Robot handle control

Note: The ROS_DOMAIN_ID of the Raspberry Pi and the microROS control board need to be consistent. You can check [MicroROS Control Board Parameter Configuration] to set the microROS control board ROS_DOMAIN_ID. Check the tutorial [Connect MicroROS Agent] to determine whether the IDs are consistent.

1. Program function description

The car is connected to the agent, the receiver of the handle is connected to the Raspberry Pi 5 port, and the program is run, and the car movement, buzzer and gimbal servo can be controlled by remote control.

2. Start and connect to the agent

After successfully starting the Raspberry Pi, enter the following command to start the agent.

image-20240123103719295

Then, turn on the car switch and wait for the car to connect to the agent. The connection is successful, as shown in the figure below.

image-20240123103750736

3. Enter the car docker

Open another terminal and enter the following command to enter docker.

When the following interface appears, you have successfully entered docker. Now you can control the car through commands.

image-20240201101454224

Enter the following command in the terminal to check whether the controller is mounted normally.

When this interface appears, it means it was successfully mounted.

image-20240123112809498

4. Start the handle control program

Because the handle control function has been automatically activated at boot, if we need to manually enable handle control, we need to turn off the auto-start process at boot.

Terminal input command:

image-20240123113715913

You can see that the processes of the handle control node and the handle node are 171 and 173. Turn off these two processes to manually start the handle control.

Manually open the handle control program.

image-20240123113950850

The remote control button description is as follows:

5、Node communication diagram

Enter the following command in the terminal.

image-20240123115953926

If it is not displayed at first, select [Nodes/Topics(all)], and then click the refresh button in the upper left corner.

6、Code analysis

Source code reference path.

yahboom_joy_ launch.py

Two nodes are running, namely, the yahboom_ctrl handle control node and the joy_node handle key value reading node.

Two node source code reference paths.

yahboom_joy.py

7. Variables corresponding to remote control key values

Based on the default mode [Controller], the key values corresponding to the remote control are as follows.

remote control eventCorresponding variable
Left joystick upaxes[1]=1
Left joystick downaxes[1]=-1
Right joystick to leftaxes[2]=1
Right joystick to the rightaxes[2]=-1
Button X pressedbutton[3]=1
ButtonB pressedbutton[1]=1
Button Y pressedbutton[4]=1
Button R1 pressedbutton[7]=1
Button start pressedbutton[11]=1
Left joystick pressedbutton[13]=1
Right joystick pressedbutton[14]=1

Combined with the above source code for easy understanding, when these values change, it means that the remote control is pressed and the corresponding program can be executed. To view other buttons, you can subscribe to the /joy topic. Enter the following command in the terminal.

image-20240123120728855