Xicro Package¶
Xicro is ROS2 package for microcontroller interface originally made for replacing micro-ROS. Xicro allows the developers to use the generated libraries for the microcontrollers as well as auto-generated node that intrepreter information from/to the microcontrollers via UART. In this documentation, Xicro is used for transmit navigation message from microcontroller to ROS2 including Odometry and Imu measurement. Also from ROS2 to microcontroller including Twist for robot velocity command.
Create custom message for microcontroller interface¶
In the xicro_interfaces/msg directory, create 3 new files for navigation message including Odometry.msg, Imu.msg and
DiffDriveTwist.msg then write below codes to each file to create custom message.
Type: xicro_interfaces/msg/Odometry
xicro_interfaces/Pose pose
xicro_interfaces/Twist twist
Type: xicro_interfaces/msg/Imu
xicro_interfaces/Quaternion orientation
xicro_interfaces/Vector3 angular_velocity
xicro_interfaces/Vector3 linear_acceleration
Type: xicro_interfaces/msg/DiffDriveTwist
float32 linear
float32 angular
Setup parameter in setup_xicro.yaml¶
In xicro yaml file, Set Baudrate to 576000 for a highest transmission rate of Xicro, then declare topics for all navigation
messages in Setup_Publisher and Setup_Subscriber. Microcontroller port is set to /dev/ttyACM0 from Hardware setup.
Idmcu: 3
Namespace: "sub_N_pub"
Port: "/dev/ttyACM0"
generate_library_Path: "xicro/libraries"
Baudrate: 576000
Setup_Publisher: [ [1,"nav_stm32","xicro_interfaces/Odometry.msg"], [2,"imu_stm32","xicro_interfaces/Imu.msg"] ]
Setup_Subscriber: [ [1,"cmd_vel_stm32","xicro_interfaces/DiffDriveTwist.msg"] ]
Setup_Srv_client: []
Create xicro library for microcontroller¶
After yaml config, The stm32 library will be generated based on setup_xicro.yaml when run the following command:
ros2 run xicro_pkg generate_library.py stm32 stm32h7xx_hal.h
Stm32 library will be generated in ~/xicro/libraries. So you need to bring this .h and .cpp to your stm32 project.
Create xicro node¶
The node will be generated based on setup_xicro.yaml when run the following command:
ros2 run xicro_pkg generate_xicro_node.py stm32
Caution
After running the command, VScode will display the node that was created.
Delete line 11 !Delete this line to verify the code. and save it The entry point is add auto by command.