3. Robot control

1. Program Function Description

Turn on the chassis, run the handle/keyboard control program, you can use the handle or keyboard to control the movement of the cart, the handle also has a control buzzer, control the lights and other functions.

2. Program code reference path

After entering the docker container, the source code of the joystick control function is located in, take R2 model for example.

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

3. Program startup

It should be noted here that the joystick and keyboard cannot run at the same time, as the keyboard control, when activated, defaults to sending a message of 0 data for speed when the keyboard is not pressed.

3.1. Joystick Control

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

Remote control effect description.

HandlesEffects
Left Stick Up/DownForward/Backward Straight
Right Stick Left/RightFront Wheel Left/Right Turn
Right "1" buttonControl light effect
Right "2" buttonUnlock/Lock motion control
"START" buttonControl Buzzer/End Sleep
Left Rocker DownAdjust Line Velocity Level
Right Rocker DownAdjust Angular Velocity

3.2. Keyboard Controls

Description of the keys.

image-20230419160130920

 

3.3. Node Communication

The handle control trolley node communication diagram thatimage-20230419160537647

Keypad-controlled trolley node communication diagram that

image-20230419160740283

4. Core Code Analysis

4.1. Handle control code

Take the R2 model as an example, as we said in the previous lesson, the chassis control program, which is also known as Ackman_driver_R2.py, defines three subscribers for speed (/cmd_vel), light band effect (/RGBLight ), and buzzer (/Buzzer), so we can control the speed, light band effect (/RGBLight ), and buzzer (/Buzzer) by posting that type of topic data in the joystick control code program, yahboom_joy_R2. py can control the velocity, light band, and buzzer just by publishing that type of topic data.

In addition, we need to subscribe to the "joy" topic data, which tells us which keys (joystick and buttons) have been changed, i.e.

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

Here the function jumps all self.user_jetson, and the parameter variable passed in is the received topic, the

To analyze the example of controlling a buzzer, the

If joy_data.buttons[11] == 1 i.e. if "start" is pressed, then the value of the buzzer will be changed and published self.pub_Buzzer.publish(Buzzer_ctrl) . The others are in order, the principle is the same, they are all assigning values by detecting the change of key value. Refer to yahboom_joy_R2.py for detailed code.

4.2. Keyboard Control Code

Keyboard control can only control the motion control of the cart, it cannot control the cart's light strip and buzzer, therefore, there is only one /cmd_vel speed publisher that

The program also defines two dictionaries to detect changes in the keyboard when letters are pressed, the

Entering a while loop, the program reads the value of the keyboard press and then makes a layer upon layer of judgment that

Finally, assign to twist.linear.x, twist.linear.y, twist.angular.z based on the multi-layer judgment and post it.

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: