micro-ROS / micro-ROS/micro_ros_stm32cubemx_utils
How to increase a published topic frame rate faster than best effort publisher
- Dominant language
- C
- Stars
- 275
- Forks
- 100
- PR merge metrics
- No merged PRs in 30d
Description
- Hardware description: STM32F427 on RoboMaster Development Board Type A
- RTOS: FreeRTOS
- Installation type: micro_ros_stm32cubemx_utils
- Version or commit hash: Galactic
#### Steps to reproduce the issue
1. Creat a odometry best effort publisher
```c
// create odometry_publisher
RCCHECK(rclc_publisher_init_best_effort(
&odometry_publisher,
&node,
ROSIDL_GET_MSG_TYPE_SUPPORT(nav_msgs, msg, Odometry),
"odometry")
);
```
2. Creat a 100 Hz timer
```c
rcl_timer_t publish_100hz_timer;
RCCHECK(rclc_timer_init_default(&publish_100hz_timer, &support, RCL_MS_TO_NS(1), publish_100hz_timer_callback));
RCCHECK(rclc_executor_add_timer(&executor, &publish_100hz_timer));
```
And the timer callback:
```c
void publish_100hz_timer_callback(rcl_timer_t * timer, int64_t last_call_time)
{
if(timer != NULL) {
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
nav_msgs__msg__Odometry odometry_msg = {};
odometry_msg->header.stamp.sec = ts.tv_sec;
odometry_msg->header.stamp.nanosec = ts.tv_nsec;
static char odometry_frame_id[] = "odom";
static char odometry_child_frame_id[] = "base_link";
odometry_msg->header.frame_id.data = odometry_frame_id;
odometry_msg->header.frame_id.size = strlen(odometry_msg->header.frame_id.data);
odometry_msg->header.frame_id.capacity = sizeof(odometry_frame_id);
odometry_msg->child_frame_id.data = odometry_child_frame_id;
odometry_msg->child_frame_id.size = strlen(odometry_child_frame_id);
odometry_msg->child_frame_id.capacity = sizeof(odometry_child_frame_id);
RCSOFTCHECK(rcl_publish(&odometry_publisher, &odometry_msg, NULL));
}
}
```
3. ros spin
```c
while (true) {
rclc_executor_spin_some(&executor, RCL_MS_TO_NS(1));
osDelay(1);
}
```
4.Start Microros agent with 1500000 baud rate on serial:
```sh
ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/serial/by-id/usb-FTDI_USB__-__Serial-if00-port0 -b 1500000
```
5.Use `topic hz` to watch
```sh
ros2 topic hz /odometry
```
#### Expected behavior
Expect receive the odometry msg in 100 Hz
#### Actual behavior
Actually only 50 Hz:
```sh
➜ interfaces_ws ros2 topic hz /odometry
WARNING: topic [/odometry] does not appear to be published yet
average rate: 49.933
min: 0.014s max: 0.026s std dev: 0.00571s window: 51
average rate: 49.947
min: 0.014s max: 0.026s std dev: 0.00577s window: 102
average rate: 49.964
min: 0.013s max: 0.026s std dev: 0.00579s window: 153
average rate: 49.974
min: 0.013s max: 0.027s std dev: 0.00581s window: 204
average rate: 49.978
min: 0.013s max: 0.027s std dev: 0.00582s window: 255
average rate: 49.982
min: 0.013s max: 0.027s std dev: 0.00583s window: 306
average rate: 49.983
min: 0.013s max: 0.027s std dev: 0.00583s window: 357
average rate: 49.987
min: 0.013s max: 0.027s std dev: 0.00583s window: 408
average rate: 49.988
min: 0.013s max: 0.027s std dev: 0.00583s window: 459
average rate: 49.989
min: 0.013s max: 0.027s std dev: 0.00583s window: 510
average rate: 49.995
```
Is 50 Hz the fatest rate? If not, how to increase the publish frame rate to reach the serial line's potential?
#### Additional information
When I used reliable publisher, it`s only 27 Hz:
```C
// create odometry_publisher
RCCHECK(rclc_publisher_init_default(
&odometry_publisher,
&node,
ROSIDL_GET_MSG_TYPE_SUPPORT(nav_msgs, msg, Odometry),
"odometry")
);
```
And the output:
```sh
➜ interfaces_ws ros2 topic hz /odometry
average rate: 26.999
min: 0.037s max: 0.038s std dev: 0.00023s window: 29
average rate: 27.006
min: 0.037s max: 0.038s std dev: 0.00020s window: 57
average rate: 27.015
min: 0.037s max: 0.038s std dev: 0.00018s window: 85
average rate: 27.123
min: 0.036s max: 0.038s std dev: 0.00038s window: 113
average rate: 27.105
min: 0.036s max: 0.038s std dev: 0.00035s window: 141
average rate: 27.085
min: 0.036s max: 0.038s std dev: 0.00035s window: 168
average rate: 27.077
min: 0.036s max: 0.038s std dev: 0.00033s window: 196
```
I'm not a native English speaker, and new to the ros. Hope my behavior not so bad.
Contributor guide
Research direction
Start with the reported STM32 C entry points: rclc_timer_init_default, rclc_executor_spin_some, and rcl_publish, then reproduce the measurements with the serial micro-ROS agent and ros2 topic hz. Compare best-effort and reliable publishers at the stated timer and baud-rate settings; done means identifying the limiting behavior and documenting or correcting it so the observed rate matches the supported expectation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot, performance, robotics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100