micro-ROS / micro-ROS/micro_ros_stm32cubemx_utils
MicroRos subscriber callback stops getting called after receiving a couple messages
- Dominant language
- C
- Stars
- 275
- Forks
- 100
- PR merge metrics
- No merged PRs in 30d
Description
I am using microRos on an STM32 device which is connected to a host agent over serial. I am attempting to do a simple function first. Basically, I have the STM32 subscribing to a "heartbeat" topic. The message type (.msg file) is simply "uint8 heartbeat" The host agent publishes a "1" on this topic.
The STM32 has a callback function which I have setup. Ideally, everytime it sees a "1", an LED will toggle.
What is currently happening though, is that the LED toggles a couple times (about 11 times) before it stops toggling, even though the host agent is still publishing. The details of my STM32 implementation are below:
```
void mros_init(void *argument) {
HAL_GPIO_TogglePin(GPIOC, LED_DEBUG_Pin);
if (rmw_uros_set_custom_transport(
true, (void*) &huart1, cubemx_transport_open, cubemx_transport_close,
cubemx_transport_write, cubemx_transport_read) != RMW_RET_OK){
NVIC_SystemReset();
}
//allocate freeRtos
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__);
NVIC_SystemReset();
}
// micro-ROS app
rcl_allocator_t allocator = rcl_get_default_allocator();
//create init_options
rcl_ret_t ret3 = rclc_support_init(&support, 0, NULL, &allocator);
if (ret3 != RCL_RET_OK) {
NVIC_SystemReset();
}
// create node
rcl_ret_t ret0 = rclc_node_init_default(&node, "ccb", "", &support);
```
Above I have shown the initialization function for micro ros. You can see that I am creating the subscriber and then attaching the callback function. The callback function is simple, shown below:
```
void heartbeat_sub_callback(const void *msgin) {
HAL_GPIO_TogglePin(GPIOC, LED_DEBUG_Pin);}
```
As you can see, I am just toggling an LED. The host agent publishes data on this topic every 5ms, so I expect that this callback should be invoked continuously. Instead, it gets invoked about 11 times and then stops. Does anyone have any clues as to what could be the problem?
Contributor guide
Research direction
Start by reviewing the mros_init setup and heartbeat_sub_callback shown in the issue, then reproduce the behavior with the host agent publishing every 5ms. Trace where subscriber callbacks stop being delivered and compare the complete subscriber, executor, transport, and timing configuration; done means identifying a reproducible cause and confirming continuous callbacks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100