Skip to main content
Visitor II
July 8, 2024
Question

microROS: Messages being published at only one hertz

  • July 8, 2024
  • 2 replies
  • 1282 views

I have implemented microros on an stm32 nucleo f446re and wrote a publisher in it, while using default qos the messages published can't exceed the frequency more than one hertz even after removing the delay function.....Is there any way to increase the speed of the message publishing

 this is the code of the thread

void StartDefaultTask(void *argument)
{
/* USER CODE BEGIN 5 */

// micro-ROS configuration

rmw_uros_set_custom_transport(
true,
(void *) &huart2,
cubemx_transport_open,
cubemx_transport_close,
cubemx_transport_write,
cubemx_transport_read);

rcl_allocator_t freeRTOS_allocator = rcutils_get_zero_initialized_allocator();
freeRTOS_allocator.allocate = microros_allocate;
freeRTOS_allocator.deallocate = microros_deallocate;
freeRTOS_allocator.reallocate = microros_reallocate;
freeRTOS_allocator.zero_allocate = microros_zero_allocate;

if (!rcutils_set_default_allocator(&freeRTOS_allocator)) {
printf("Error on default allocators (line %d)\n", __LINE__);
}

// micro-ROS app

rcl_publisher_t publisher;
std_msgs__msg__Int32 msg;
rclc_support_t support;
rcl_allocator_t allocator;
rcl_node_t node;

allocator = rcl_get_default_allocator();

//create init_options
rclc_support_init(&support, 0, NULL, &allocator);

// create node
rclc_node_init_default(&node, "cubemx_node", "", &support);

// create publisher
rclc_publisher_init_best_effort(
&publisher,
&node,
ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32),
"cubemx_publisher");

msg.data = 0;

rcl_subscription_t subscription;
std_msgs__msg__Int32 sub_msg;


for(;;)
{
rcl_ret_t ret = rcl_publish(&publisher, &msg, NULL);
if (ret != RCL_RET_OK)
{
printf("Error publishing (line %d)\n", __LINE__);
}

msg.data++;
osDelay(10);
}
/* USER CODE END 5 */
}
    This topic has been closed for replies.

    2 replies

    Visitor II
    October 30, 2024

    Hi, I'm new to working with Micro-ROS on STM32 microcontrollers. I've been experimenting with two Nucleo boards, the F446 and H723, as well as a custom F407 board. My development environment is Ubuntu 22.04 with ROS2 Humble, and the boards communicate via UART.

    When I use OSDelay(10); I get the following communication rates by running ros2 topic hz /:

    F446: 40 Hz , H723: 1 Hz

    After adjusting to OSDelay(1); and generating the .c/.h files FreeRTOS.h, the rates changed to:

    F446: 120 Hz , H723: 1 Hz

    I'm not entirely sure why the H723 remains at 1 Hz, but 120 Hz on the F446 works well enough for my purposes. Hopefully, this may help.

    Visitor II
    August 11, 2025

    Hi,

    I am having the same issue. Can you help if you have solved it?

    Thanks.