Customized transmission method

1. Experimental purpose

Learn the ESP32-microROS component and use a custom transmission method (serial port transmission) to connect to the agent.

 

2. Hardware connection

As shown in the figure below, the microROS control board integrates the ESP32-S3-WROOM core module, which has its own wireless WiFi function. The ESP32-S3 core module needs to be connected to an antenna, and a type-C data cable needs to be connected to the computer and the microROS control board as The functions of burning firmware and serial communication.

image-20240112174901940

 

3. Core code analysis

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

Since the custom transmission method needs to be recompiled to generate the libmicroros.a static library, this project does not import extra_components as the external component library. You need to reinstall the micro_ros_espidf_component component to the custom_components directory, and then import custom_components as the external component library.

The factory virtual machine system has already installed custom_components components.

The operation process of compiling and generating the custom version libmicroros.a static library is similar to the operation process of compiling the libmicroros.a static library in the extra_components directory. You just need to modify the "rmw_microxrcedds" parameter in the colcon.meta file and pay attention to replacing the compilation path.

Obtain relevant configuration parameters from the IDF configuration tool. By default, serial port 2 is used, the baud rate is 921600, the TX pin is GPIO43, the RX pin is GPIO44, the namespace is empty, and the domain ID is 20.

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.

Set the microROS custom transmission mode to serial port transmission mode.

set_microros_serial_transports_with_options function as long as the function is to specify the transmission method

Open serial port

Close serial port

Write data to serial port

Read data from serial port

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 "custom_transport", in which ROS_NAMESPACE is empty by default and can be modified in the IDF configuration tool according to actual conditions.

Create the publisher "custom_publisher" and specify the ROS topic information as std_msgs/msg/Int32 type.

 

4. Compile and download the burning 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 example-app settings and keep the default configuration if there are no special requirements.

image-20240118163657010

If there are any changes, please press S to save, and then press Q to exit the configuration tool.

Compile, burn, and open the serial port simulator.

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

5. Experimental results

After starting up, the serial port simulator will print a string of garbled characters. The reason is that the connection request sent by Microros using the serial port is not all characters, and the default baud rate is not suitable, so it looks like garbled characters.

image-20240118163933247

At this time, press Ctrl+] to exit the simulator, and then enter the following content to open the serial port proxy.

image-20240118164843379

If the connection is successful, information about the relevant nodes and topics will be printed.

image-20240118164930334

At this time, open another terminal to view the current node signal.

image-20240118165148930

Subscribe to the data content of the /custom_transport topic

Press Ctrl+C to exit the topic content.

image-20240118165508504

Note: Since the microros serial port agent will occupy the serial port and cannot be burned, you need to press Ctrl+C to close the serial port agent before burning the program next time, and then burn the program.