yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
RDK X5 Robot📖
01. RDK-X5-Robot Introduction
  • 1.Introduction
  • 2.Common Problem Analysis
  • 3.Battery and charger usage precautions
  • 4.TF card expand capacity
02. Assembly Tutorial
  • Assembly Tutorial
  • Assembly Video-1
  • Assembly Video-2
  • Assembly Video-3
  • Assembly Video-4
03. Remote Control Course
  • 1.Mobile APP remote control
  • 2.USB Wireless Controller Remote Control
04. ROS Driver Board Course
  • 1. Introduction of extension board
  • 2. Set up STM32 development environment
  • 3. Key control buzzer sound
  • 4. FreeRTOS application
  • 5. Serial communication
  • 6. SBUS model remote control
  • 7. CAN bus communication
  • 8. RGB color light strip
  • 9. Timer interrupt control PWM servo
  • 10. Control serial steering gear
  • 11. Nine-axis attitude sensor to obtain data
  • 12. Control motor forward and reverse
  • 13. The timer captures encoder data
  • 14. Theory of robot kinematics analysis
  • 15. PID control robot motion
05. Basic Control Course
  • 1.Update expansion board firmware
  • 2.Install Python driver library
  • 3.Set the car type
  • 4.Open and close APP program control
  • 5.Turn hotspot mode on and off
  • 6.Buzzer sound
  • 7.Control the motor to rotate forward and reverse
  • 8.Controlling robot movement
  • 9.OLED display
  • 10.Control fans and lighting effects
06. Development Environment
  • 1. Virtual machine installation and use
  • 2. Linux Basics
  • 3. Remote connection
  • 4. Multi-machine communication configuration
  • 5. Bind device ID
  • 6. Image installation and backup
07. ROS2 Basic Course
  • 1. Introduction to ROS2
  • 2. ROS2 install Humble
  • 3. ROS2 development environment
  • 4. ROS2 workspace
  • 5. ROS2 function package
  • 6. ROS2 node
  • 7. ROS2 topic communication
  • 8. ROS2 service communication
  • 9. ROS2 action communication
  • 10. ROS2 custom interface message
  • 11. ROS2 parameter service case
  • 12. ROS2 meta-function package
  • 13. ROS2 distributed communication
  • 14. ROS2 DDS
  • 15. ROS2 time related API
  • 16. ROS2 common command tools
  • 17. ROS2 rviz2 use
  • 18. ROS2 rqt toolbox
  • 19. ROS2 Launch startup file configuration
  • 20. ROS2 recording and playback tool
  • 21. ROS2 URDF model
  • 22. ROS2 Gazebo simulation platform
  • 23. ROS2 TF2 coordinate transformation
08. Robot Chassis Control Course
  • 1. PID algorithm theory
  • 2. Robot information release
  • 3. Robot control
  • 4. Robot state estimation
  • 5. Robot calibration
  • 6. Robot trajectory tracking
  • 7. URDF Model
09. LiDAR Course
  • 1. Introduction and use of lidar
  • 2. Lidar obstacle avoidance
  • 3. Lidar tracking
  • 4. Lidar guard
  • 5. Lidar patrol
  • 6. gmapping mapping algorithm
  • 7. Cartographer mapping algorithm
  • 8. Navigation and obstacle avoidance
  • 9. App Mapping and Navigation
10. OpenCV Course
  • 1. Getting started with OpenCV
  • 2. OpenCV geometric transformation
  • 3. OpenCV Image Processing
  • 4. OpenCV image beautification
  • 5. QR code creation and recognition
11. Mipi Camera Course
  • 1. Camera driver
  • 2. Adjust the color HSV value
  • 3. Color recognition
  • 4. Color Tracking
  • 5. Color Follow
  • 6. QR code instructions
  • 7. Face Detection
  • 8. Object Detection
  • 9. Visual line patrol-OpenCV
  • 10. Visual line patrol-deep learning
  • 11. Human body tracking
  • 12. Gesture control
12. Depth Camera Course
  • 1. Use of Depth Camera
  • 2. Camera intrinsic calibration
  • 3. ROS+OpenCV Basics
  • 4. AR Vision
  • 5. Color Tracking
  • 6. Object Tracking
  • 7. RTAB-Map 3D Mapping Navigation
13. Multi-robot Synchronous Control
  • Multi-vehicle synchronous control
Remote login control
  • 1. VNC and SSH remote login
  • 2. Jupyter lab login and case code running
Download
  • System_File
  • Code
  • VM_File
  • Software_Tools
  • Hardware_Info
  • Firmware
  • Instruction_Manual
  • ROS2_Basic_VM
Download ZIP

Welcome to RDK X5 Robot repository

3. Robot control

3. Robot control

3. Robot control3.1. Program function description3.2, Program code reference path3.3, Program startup3.3.1, handle control3.3.2, Keyboard control3.3.3, Node Communication3.4, Core Source Code Analysis3.4.1, Controller Control Code3.4.2, keyboard control code

3.1. Program function description

Turn on the chassis and run the handle/keyboard control program. You can control the robot movement through the handle or keyboard. The handle can also control the buzzer, light strip, etc.

3.2, Program code reference path

After SSH connects to the car, the source code of the handle control function is located at,

xxxxxxxxxx
/home/sunrise/yahboomcar_ws/src/yahboomcar_ctrl/yahboomcar_ctrl/yahboom_joy.py

After SSH connects to the car, the source code of the keyboard control function is located at,

xxxxxxxxxx
/home/sunrise/yahboomcar_ws/src/yahboomcar_ctrl/yahboomcar_ctrl/yahboom_keyboard.py

3.3, Program startup

xxxxxxxxxx
#Start chassis
ros2 run yahboomcar_bringup Mcnamu_driver

#Handle control
#Start launch file
ros2 launch yahboomcar_ctrl yahboomcar_joy_launch.py
#Or start two nodes separately
ros2 run yahboomcar_ctrl yahboom_joy
ros2 run joy joy_node

#Keyboard control
ros2 run yahboomcar_ctrl yahboom_keyboard

Note that the handle and 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 of 0 data of speed.

3.3.1, handle control

After turning it on, press the [START] button, and when you hear the buzzer sound, you can start remote control. The remote control will enter sleep mode after being turned on for a period of time. You need to press the [START] button to end the sleep mode. If you want to control the car to run, you also need to press the [L1] key to release the motion control lock before you can use the joystick to control the car to move.

Remote control effect description,

HandleEffect
Left joystick up/downGo forward/backward
Left joystick left/rightGo left/right
Right joystick left/rightRotate left/turn right
【L1】 keyRelease/lock motion control
【R1】 keyControl lighting effects
【START】 keyControl buzzer/end sleep
Press left joystickAdjust X/Y axis speed
Press right joystickAdjust angular velocity

3.3.2, Keyboard control

Button description,

  • Direction control

【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】
  • Speed control

KeySpeed changeKeySpeed change
【q】Increase both linear and angular speeds by 10%【z】Decrease both linear and angular speeds by 10%
【w】Increase only linear speed by 10%【x】Decrease only linear speed by 10%
【e】Increase only angular speed by 10%【c】Decrease only angular speed by 10%
【t】Switch between linear speed X-axis and Y-axis【s】Stop keyboard control

3.3.3, Node Communication

Controller Control Car Node Communication Diagram,

image-20230419160537647

Keyboard Control Car Node Communication Diagram,

image-20230419160740283

3.4, Core Source Code Analysis

3.4.1, Controller Control Code

As we said in the last lesson, the chassis control program, that is, Mcnamu_driver.py, defines speed (/cmd_vel), lighting effects (/RGBLight ), buzzer (/Buzzer), so we can control the speed, lighting effect and buzzer by publishing this type of topic data in the handle control code program yahboom_joy.py.

xxxxxxxxxx
#create pub
self.pub_cmdVel = self.create_publisher(Twist,"cmd_vel", 10)
self.pub_Buzzer = self.create_publisher(Bool,"Buzzer", 1)
self.pub_RGBLight = self.create_publisher(Int32,"RGBLight" , 1)
self.pub_JoyState = self.create_publisher(Bool,"JoyState", 10)

In addition, we need to subscribe to the "joy" topic data, which can tell us which key values (joystick and buttons) have changed, that is,

xxxxxxxxxx
#create sub
self.sub_Joy = self.create_subscription(Joy,'joy', self.buttonCallback,1)

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

xxxxxxxxxx
def buttonCallback(self,joy_data):
if not isinstance(joy_data, Joy): return
if self.user_name == "root": self.user_sunrise(joy_data)
else: self.user_pc(joy_data)

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

xxxxxxxxxx
def user_sunrise(self, joy_data):

Take the control of the buzzer as an example for analysis,

xxxxxxxxxx
if joy_data.buttons[7] == 1:
Buzzer_ctrl = Bool()
self.Buzzer_active = not self.Buzzer_active
Buzzer_ctrl.data = self.Buzzer_active
for i in range(3): self.pub_Buzzer.publish(Buzzer_ctrl)

Here, if joy_data.buttons[7] == 1 That is, if the [START] key is pressed, the value of the buzzer will change and then be published self.pub_Buzzer.publish(Buzzer_ctrl). The others are similar, and the principle is the same, all of which are assigned by detecting the change of key value. For detailed code, refer to yahboom_joy.py.

3.4.2, keyboard control code

Keyboard control can only control the movement of the car, not the lights and buzzer, so there is only one /cmd_vel speed publisher,

xxxxxxxxxx
self.pub = self.create_publisher(Twist,'cmd_vel',1)

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

xxxxxxxxxx
moveBindings = {
'i': (1, 0),
'o': (1, -1),
'j': (0, 1),
'l': (0, -1),
'u': (1, 1),
',': (-1, 0),
'.': (-1, 1),
'm': (-1, -1),
'I': (1, 0),
'O': (1, -1),
'J': (0, 1), 'L': (0, -1), 'U': (1, 1), 'M': (-1, -1), } speedBindings = { 'Q': (1.1, 1.1), 'Z': (.9, .9), 'W': (1.1, 1), 'X': (.9, 1), 'E': (1, 1.1), 'C': (1, .9), 'q': (1.1, 1.1), 'z': (.9, .9), 'w': (1.1, 1), 'x': (.9, 1), 'e': (1, 1.1), 'c': (1, .9),
}

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

xxxxxxxxxx
key = yahboom_keyboard.getKey()
if key=="t" or key == "T": xspeed_switch = not xspeed_switch
elif key == "s" or key == "S":
...
if key in moveBindings.keys():
...
elif key in speedBindings.keys():
...

Finally, according to the multi-layer judgment, assign values to twist.linear.x, twist.linear.y, twist.angular.z and then publish them.

python if xspeed_switch: twist.linear.x = speed * x else: twist.linear.y = speed * x twist.angular.z = turn * th if not stop: yahboom_keyboard.pub.publish(twist) if stop:yahboom_keyboard.pub.publish(Twist()) For detailed code, refer to yahboom_keyboard.py.

Robot information release
Robot state estimation

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文