Control the car using RT-Thread
RT-Thread connects to ROS to control the car
This document will introduce how to use RT-Thread and ROS to connect to realize a remote control car with a camera.

But in fact, the RT-Thread part of the code has been introduced in this document: RT-Thread connects to ROS to control the car . On this basis, we only need to modify the ROS code.
Here is a diagram of the entire system, so that if you want to make a car like this yourself, you can try it out:

This is what the actual picture looks like:

The following codes are all operated on a computer with ROS installed
The installation of ROS has been introduced before, so I won’t repeat it here. Let’s create a new workspace first:
Let's create a new ROS package:
Now we can start ROS development, in the telebot_ws directory:
We first create a node to monitor keyboard keys and publish the received keys to the topic /keys (communication between ROS nodes is achieved by publishing and subscribing to topics). We create a new file key_publisher.py in the telebot_ws/src/telebot/src directory
The code above is less than 20 lines long. I have also added some comments, so I won’t go into detail. Let’s add executable permissions to this file:
You can start the node:
In this way, we can see that there is a /keys topic that continuously outputs keyboard keys:
Now there is a node publishing our key messages. The next step is to convert the key messages into motion instructions for the robot, that is, publish them to /cmd_vel. We create a new file keys_to_twist_with_ramps.py in the telebot_ws/src/telebot/src directory:
Similarly, we add executable permissions to this file:
You can start the node:
The parameters passed in above are the ratio of the speed and acceleration of the car we want, so we can see that there is a /cmd_vel topic that will output the expected car speed:
Now the car can start, stop and turn slowly according to our instructions. The next step is to add a remote camera to it.
Before connecting to the camera of the car, there is one very important point. The previous operations were all performed on the computer. Next, we want to use our ARM development board as the ROS master node, so we need to set the environment variables and replace the following IP address with the actual IP address of the ARM board on the car :
The following codes are all operated on the ARM development board on the car with ROS installed
Let’s create a new workspace:
Let's create a new ROS package:
Now we can start ROS development, in the telebot_ws directory:
In fact, the code for publishing camera messages is only about 30 lines. We create a new my_publisher.cpp in the telebot_ws/src/telebot_image/src directory.
Before compiling, you need to install the OpenCV development environment first , because we use the OpenCV library function to obtain the camera data, and then publish it using the ROS library function. This is the CMakeLists.txt in the telebot_ws/src/telebot_image directory
We compile the project in the telebot_ws directory:
In this way, the camera message can be published. The image message is published in camera/image:
The following codes are all operated on a computer with ROS installed
Subscribing and seeing camera messages is actually very simple:
You can then see the pictures from the car's camera on your computer.

If you already have a car that can be controlled by ROS, you only need to write about 30 lines of code in Part 3 for image publishing. You can use the OpenCV library to obtain camera information and then publish it using the ROS library.
Of course, if you just want to see the car's camera on your computer, there are actually many other ways that don't even require writing code. The advantage of using ROS to publish image data is that we can process the acquired images, such as target detection, which will be further introduced in subsequent documents.
Last updated
Was this helpful?