3、Robot control

1、Program function description

Open the chassis, run the handle/keyboard control program, you can control the trolley movement through the handle or keyboard, and the handle also controls the buzzer, controls the light strip and other functions.

2、Program code reference path

After entering the docker container, the location of the source code of the controller control function is located, taking the X3 model as an example

After entering the docker container, the location of the source code of the keyboard control function is located at,

3、The program starts

It should be noted here that the controller and the keyboard cannot run at the same time, because after the keyboard control is started, when the keyboard is not pressed, the default is to send a message with 0 data of speed.

3.1、Controller control

After turning on, press the "START" button, hear the buzzer sound, and you can start the remote control. The remote control will enter sleep mode after being turned on for a period of time, and you need to press the "START" button to end sleep. If you want to control the trolley running, you also need to press the R2 key and release the motion control lock before you can use the joystick to control the trolley movement.

Remote control effect description,

handleeffect
Left stick up/downGo straight forward/backward
Left stick left/rightGo straight left/right
Right stick left/rightRotate left/rotate right
The right "1" keyControl the strip light effect
The right "2" keyUnlock/lock motion control
"START" buttonControl the buzzer/end hibernation
The left stick is pressedAdjust the speed of the X/Y axis
The right stick is pressedAdjust the angular velocity magnitude

3.2、keyboard control

Key description,

【i】or【I】【linear,0】【u】or【U】【linear,angular】
【,】【-linear,0】【o】or【O】【linear,-angular】
【j】or【J】【0,angular】【m】or【M】【-linear,-angular】
【l】or【L】【0,-angular】【.】【-linear,angular】
KeySpeed changesKeySpeed changes
【q】10% increase in both linear and angular velocities【z】10% reduction in both linear and angular velocities
【w】Only 10% increase in line speed【x】Only 10% reduction in line speed
【e】Only 10% increase in angular velocity【c】Only 10% reduction in angular velocity
【t】Linear speed X/Y direction switching【s】Stop keyboard control

3.3、node communication

Handle control trolley node communication diagram,

image-20230419160537647

Keyboard control trolley node communication diagram,

image-20230419160740283

4、core code parsing

4.1、Controller control code

Taking the X3 model as an example, we said in the previous lesson that the chassis control program is the Mcnamu_driver_X3.py, defining three subscribers: speed (/cmd_vel), light strip effect (/RGBLight), and buzzer (/buzzer), so we can control speed, light strip and buzzer as long as we publish this type of topic data yahboom_joy_X3.py the controller control code program.

In addition, we need to subscribe to the "joy" topic data, which tells us that the keys (joysticks and keys) have changed, that is,

The main look is the callback function of this joy topic, which parses the received value, then assigns the value to the publisher's variable, and finally publishes it.

The function jumps here are self.user_jetson, and the parameter variable passed in is the topic received,

Take the control buzzer as an example for analysis,

It is judged here that if it is joy_data.buttons[11] == 1, that is, if "start" is pressed, then the value of the buzzer will change, and then publish self.pub_Buzzer.publish(Buzzer_ctrl). In other cases, the principle is the same, they are all assigned by detecting the change of the key value. Refer to yahboom_joy_X3.py for detailed code.

4.2、keyboard control code

The keyboard control can only control the movement control of the trolley, not the light strip and buzzer of the trolley, therefore, there is only one / cmd_vel speed publisher,

The program also defines two dictionaries to detect the change of the letters of the keyboard when pressed,

Entering the while loop, the program will read the value pressed by the keyboard, and then make judgments layer by layer.

Finally, according to the judgment of multiple layers, assign values to twist.linear.x, twist.linear.y, twist.angular.z and then publish.

Refer to yahboom_keyboard.py for detailed code.

 

Precautions for Handle Use

 

 

Raspberry Pi series support mode: X-BOX mode. In X-BOX mode, the default POWER MODE indicator light is green. You can connect the handle receiver to the usb port of the computer to connect to the wireless handle. Enter the URL in the browser: https://gamepad-tester.com/. Pressing the button URL will display the change of the button value, as shown in the following figure: