Release speed topic

1. Experimental purpose

Learn ESP32-microROS components, access the ROS2 environment, and publish the topic of odom speed of robot cars.

 

2. Hardware connection

As shown in the figure below, the microROS control board integrates the ESP32-S3-WROOM core module with its own wireless WiFi function. The ESP32-S3 core module needs to be connected to the antenna, and then the four-way motors are connected to the motor interface. The type -C data cable connects the computer and microROS control board for firmware burning function.

image-20240117174957846

The corresponding names of the four motor interfaces are: left front wheel->Motor1, left rear wheel->Motor2, right front wheel->Motor3, right rear wheel->Motor4.

image-20240111155522592

Motor interface line sequence, there is a detailed line sequence silk screen on the back of the microROS control board. Here we take Motor1 as an example. M1+ and M1- are the interfaces for controlling the rotation of the motor. GND and VCC are the power supply circuits of the encoder. H1A and H1B are the encoder pulses. detection pin.

image-20240111160116671

Note: If you are using the 310 motor and motor cable provided by Yabo Intelligence, connect the white wire shell end to the interface on the microROS control board, and the black wire shell end to the 310 motor interface.

 

3. Core code analysis

The virtual machine path corresponding to the program source code is as follows

Based on twist_subscriber's subscription speed function, the function of publishing odom speed topics is added.

image-20240117181909132

Initialize the odom information of the publishing speed, set the frame_id to "odom_frame", set the child_frame_id to "base_footprint", and then decide whether to add the ROS_NAMESPACE prefix based on whether ROS_NAMESPACE is empty.

Get the WiFi name and password to connect from the IDF configuration tool.

The uros_network_interface_initialize function will connect to WiFi hotspots based on the WiFi configuration in IDF.

Then obtain ROS_NAMESPACE, ROS_DOMAIN_ID, ROS_AGENT_IP and ROS_AGENT_PORT from the IDF configuration tool.

Initialize the configuration of microROS, in which ROS_DOMAIN_ID, ROS_AGENT_IP and ROS_AGENT_PORT are modified in the IDF configuration tool according to actual needs.

Try to connect to the proxy. If the connection is successful, go to the next step. If the connection to the proxy is unsuccessful, you will always be in the connected state.

Create the node "odom_publisher", in which ROS_NAMESPACE is empty by default and can be modified in the IDF configuration tool according to actual conditions.

To create the publisher "odom_raw", you need to specify the publisher information as nav_msgs/msg/Odometry type.

Create a timer for the publisher with a publishing frequency of 20HZ.

Create an executor, where the three parameters are the numbers controlled by the executor, which should be greater than or equal to the number of subscribers and publishers added to the executor. and add the publisher's timer to the executor.

The main function of odom's timer callback function is to update odom data and send the data.

The speed read from the robot car, and the odom information is updated based on the car speed.

Call rclc_executor_spin_some in the loop to make microros work normally.

 

4. Compile, download and flash firmware

Use a Type-C data cable to connect the virtual machine/computer and the microROS control board. If the system pops up, choose to connect to the virtual machine.

Activate the ESP-IDF development environment. Note that every time you open a new terminal, you need to activate the ESP-IDF development environment before compiling the firmware.

Enter the project directory

Open the ESP-IDF configuration tool.

Open micro-ROS Settings, fill in the IP address of the agent host in micro-ROS Agent IP, and fill in the port number of the agent host in micro-ROS Agent Port.

image-20240116194035834

Open micro-ROS Settings->WiFi Configuration in sequence, and fill in your own WiFi name and password in the WiFi SSID and WiFi Password fields.

image-20240116193354397

Open the micro-ROS example-app settings. The Ros domain id of the micro-ROS defaults to 20. If multiple users are using it at the same time in the LAN, the parameters can be modified to avoid conflicts. Ros namespace of the micro-ROS is empty by default and does not need to be modified under normal circumstances. If non-empty characters (within 10 characters) are modified, the namespace parameter will be added before the node and topic.

image-20240116195328563

After modification, press S to save, and then press Q to exit the configuration tool.

Compile, flash, and open the serial port simulator.

If you need to exit the serial port simulator, press Ctrl+].

 

5. Experimental results

After powering on, ESP32 tries to connect to the WiFi hotspot, and then tries to connect to the proxy IP and port.

If the agent is not turned on in the virtual machine/computer terminal, please enter the following command to turn on the agent. If the agent is already started, there is no need to start the agent again.

image-20240117151035412

After the connection is successful, a node, a publisher and a subscriber are created.

image-20240117113138240

At this time, you can open another terminal in the virtual machine/computer and view the /odom_publisher node.

image-20240118111650355

Publish data to the /cmd_vel topic and control the robot car to walk forward at 0.5m/s.

Subscribe to the data of the /odom_raw topic,

Press Ctrl+C to end the command

image-20240118112009255

image-20240118113344508

Check the frequency of the /odom_raw topic. It is normal if it is about 20hz.

Press Ctrl+C to end the command

image-20240118112158523

Publish data to the /cmd_vel topic and control the robot car to stop.