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

5. Color Tracking

Color Tracking

Color Tracking5.1、Program function description5.2、Program code reference path5.3, Program startup5.3.1, Program startup and web page display5.3.2, Color Identification and Tracking5.3.3, Dynamic parameter adjustment5.3.4, View the node topic communication graph5.4, Core source code analysis5.4.1, color_identify.py5.4.2, color_track.py

5.1、Program function description

After the program is started, the image released by the camera is displayed on the web page. Use the mouse to select a color, the car will lock this color, and press the [Space] key to enter the tracking mode. The car will keep a distance of 1 meter from the tracked object and always ensure that the tracked object remains in the center of the screen.

In addition, the [L1] key of the handle can lock/open the motion control of the car. When the motion control is turned on, the function will be locked; when the motion control is locked, the function can be turned on.

5.2、Program code reference path

xxxxxxxxxx
#launch file
/home/sunrise/yahboomcar_ws/src/yahboomcar_colortrack/launch/colortrack_launch.xml

The node or launch file that is launched is explained as follows,

  • color_identify: mainly completes image processing and calculates the center coordinates of the tracked object. The code path is,

xxxxxxxxxx
/home/sunrise/yahboomcar_ws/src/yahboomcar_colortrack/yahboomcar_colortrack/color_identify.py
  • color_track: mainly calculates the speed based on the center coordinates and depth information of the tracked object, and publishes the speed data to the chassis. The code path is,

xxxxxxxxxx
/home/sunrise/yahboomcar_ws/src/yahboomcar_colortrack/yahboomcar_colortrack/color_track.py
  • astra.launch.xml: Start Astra camera

  • yahboomcar_bringup_launch.py: Start chassis

  • rosbridge_websocket_launch.xml: Start websocket to realize the interaction between ROS and Web

  • rosboard_node: Start ROSboard

5.3, Program startup

5.3.1, Program startup and web page display

After SSH connects to the car, enter in the terminal,

xxxxxxxxxx
ros2 launch yahboomcar_colortrack colortrack_launch.xml

Open the browser on the PC (note that the computer and the Sunrise Network must be in the same LAN), enter the URL: car IP:9999, for example, my car IP is 192.168.2.84, enter the URL in the browser on the virtual machine to open the ROSboard web page:

xxxxxxxxxx
192.168.2.84:9999

Select the three topics /camera/color/image_raw, /astra_binary, /astra_roi respectively. At this time, only the RGB image released by the camera is displayed, and no data is released in the /astra_binary and /astra_roi topics.

1684915860559

5.3.2, Color Identification and Tracking

Press the [i] or [I] key in the page to enter the Identify mode, click the mouse twice in the RGB image to select an area (the area can only have one color),

image-20230610120618675

After selecting, the following screen will appear, /astra_binary displays the binary image after color selection, /ast ra_roi displays the HSV value range of the color and the center point position of the color area.

image-20230610120642031

Press the [Space] key on the page to enter the tracking mode, and the car will move to a position 1 meter away from the target and stop; press the [q] key on the page to cancel the tracking; press the [r] key on the page to clear the color selection, and then press [i] to reselect the color.

image-20230610120724836

Move the object slowly, and the car will follow and keep a distance of 1 meter.

The interaction between this function and the keyboard is as follows:

ButtonFunctionRemarks
【r】 or 【R】Color recognitionColor selection mode, the program enters this mode by default after startup
【Space】Color trackingThe car tracks to a position 1 meter away from the target
【q】 or 【Q】Stop movementStop movement and retain the HSV range of color
【i】 or 【I】ResetStop movement and clear the HSV range of color

5.3.3, Dynamic parameter adjustment

Virtual machine terminal input,

xxxxxxxxxx
ros2 run rqt_reconfigure rqt_reconfigure

1684918964832

The adjustable parameters include the car's linear velocity, angular velocity PID and tracking distance.

After modifying the parameters, press the Enter key or click the blank space in the GUI to write the parameter value.

5.3.4, View the node topic communication graph

Open the virtual machine terminal and use the following command to view the topic communication between nodes,

xxxxxxxxxx
ros2 run rqt_graph rqt_graph

1684923124179

5.4, Core source code analysis

5.4.1, color_identify.py

This program has the following functions:

  • Open the camera and get the RGB image; in order to ensure the speed, the opencv method of reading the camera is adopted (note that the device number is video8), instead of receiving data through the topic. However, after reading, the image data will be published through the topic for visualization on the web page.

  • Receive keyboard and mouse topic data for switching modes and picking colors.

  • Process the image to calculate the center coordinates of the tracking target and publish it.

Some core codes are as follows,

xxxxxxxxxx
#Create a publisher to publish the center coordinates of the tracked object
self.pub_position = self.create_publisher(Position,"/Current_point", 10)
#Create a publisher to publish image data
self.pub_binary = self.create_publisher(Image, '/astra_binary', 10)
self.pub_roi = self.create_publisher(Image, '/astra_roi', 10)
self.pub_image = self.create_publisher(Image, '/camera/color/image_raw', 10)
#Create a subscriber to receive mouse and keyboard data
self.sub_mouse = self.create_subscription(Polygon, '/mouse_pos', self.MouseCallback, 1)
self.sub_keyboard = self.create_subscription(Char, '/key_value', self.KeyCallback, 1)
#Mouse event callback function, determine the selection position
def MouseCallback(self, msg):
start_cols = min(int(msg.points[0].x), int(msg.points[1].x))
start_rows = min(int(msg.points[0].y), int(msg.points[1].y))
end_cols = max(int(msg.points[0].x), int(msg.points[1].x))
end_rows = max(int(msg.points[0].y), int(msg.points[1].y))
self.Roi_init = (start_cols, start_rows, end_cols, end_rows)
#Keyboard event callback function, switch mode
def KeyCallback(self, key):
data = key.data
if data == 32: self.Track_state = 'tracking'
elif data == ord('i') or data == ord('I'): self.Track_state = 'identify'
elif data == ord('r') or data == ord('R'): self.Track_state = 'reset'
elif data == ord('q') or data == ord('Q'): self.Track_state = 'cancle'
#Calculate the value of the center coordinates, self.circle stores the xy values
rgbFrame, binary, self.circle = self.color.object_follow(rgbFrame, self.hsv_range)
#Publish the message of the center coordinates
def execute(self, x, y, z):
position = Position()
position.anglex = x * 1.0
position.angley = y * 1.0
position.distance = z * 1.0
self.pub_position.publish(position)

5.4.2, color_track.py

This program has the following functions: receiving /Current_point and depth image topic data, calculating speed, and then publishing speed data.

Some codes are as follows,

xxxxxxxxxx
#Define subscribers to receive required topic data
self.sub_depth = self.create_subscription(Image,"/camera/depth/image_raw",self.depth_img_Callback, 1)
self.sub_position = self.create_subscription(Position,"/Current_point",self.positionCallback,1)
#Define velocity publisher
self.pub_cmdVel = self.create_publisher(Twist,'/cmd_vel',10)
#Two important callback functions, get point_x value and dist value
def PositionCallback(self, msg):
def DepthCallback(self, msg):
#Calculate linear velocity and angular velocity according to point_x and dist and publish
linear_x = self.linear_pid.compute(dist, self.minDist) / 1000.0
angular_z = self.angular_pid.compute(320, point_x) / 1000.0 if abs(dist - self.minDist) < 30: linear_x = 0 if abs(point_x - 320.0) < 30: angular_z = 0 twist = Twist() twist.linear.x = linear_x * 1.0 twist.angular.z = angular_z * 1.0 self.pub_cmdVel.publish(twist) ```
AR Vision
Object Tracking

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/中文