Release IMU data topic

1. Experimental purpose

Learn ESP32-microROS components, access the ROS2 environment, and publish IMU data topics.

 

2. Hardware connection

As shown in the figure below, the microROS control board integrates the IMU six-axis attitude sensor and the ESP32-S3-WROOM core module. It has its own wireless WiFi function. The ESP32-S3 core module needs to be connected to the antenna and the type-C data cable. The computer and microROS control board function as firmware burning.

image-20240118115029925

 

3. Core code analysis

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

Since the IMU six-axis attitude sensor ICM42670P is used this time, and the components of ICM42670P have been made in the previous routine, the components of ICM42670P need to be copied to the components directory of the project. Call Icm42670p_Init at the beginning of the program to initialize ICM42670P.

image-20240118115651183

Initialize the release of IMU information, set frame_id to "imu_frame", and then decide whether to add the ROS_NAMESPACE prefix based on whether ROS_NAMESPACE is empty.

Create a new IMU data update task to update the IMU data every 10 milliseconds.

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

To create publisher "imu", you need to specify the publisher information as sensor_msgs/msg/Imu 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 IMU's timer callback function is to send Imu data.

Call rclc_executor_spin_some in the loop to make microros work normally.

 

4. Compile and download 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 and a publisher are created.

image-20240117113138240

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

image-20240118120913760

Subscribe to the data of the /odom_raw topic,

Press Ctrl+C to end the command

image-20240118121024379

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

Press Ctrl+C to end the command

image-20240118121205192