Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Micro ros image subscriber issue #1850

Open
ZaGabriel opened this issue Oct 10, 2024 · 1 comment
Open

Micro ros image subscriber issue #1850

ZaGabriel opened this issue Oct 10, 2024 · 1 comment

Comments

@ZaGabriel
Copy link

ZaGabriel commented Oct 10, 2024

Issue template

  • Hardware description: ESP32
  • RTOS:
  • Installation type: arduino ide
  • Version or commit hash: humble

Steps to reproduce the issue

Expected behavior

I want a subscriber listen to a image topic.

Actual behavior

rclc_executor_spin_some returns RMW_RET_ERROR.

Additional information

I've working on it for hours, have no idea how to subscribe to a image topic, but I've successes on publish an image topic on micro ros. Even if I let subscription_callback() do nothing the rclc_executor_spin_some will still returns RMW_RET_ERROR.

here is my code on subscribe an image topic :

#include <micro_ros_arduino.h>

#include <stdio.h>
#include <rcl/rcl.h>
#include <rcl/error_handling.h>
#include <rclc/rclc.h>
#include <rclc/executor.h>

#include <std_msgs/msg/int32.h>
#include <sensor_msgs/msg/image.h>

rcl_subscription_t subscriber;
sensor_msgs__msg__Image msg;
rclc_executor_t executor;
rclc_support_t support;
rcl_allocator_t allocator;
rcl_node_t node;
rcl_timer_t timer;

#define LED_PIN 13

#define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){error_loop();}}
#define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){}}


void error_loop(){
  while(1){
    digitalWrite(LED_PIN, !digitalRead(LED_PIN));
    delay(100);
  }
}

void subscription_callback(const void * msgin){  
  
}

void setup() {
  set_microros_transports();
  
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH);  
  
  delay(2000);

  allocator = rcl_get_default_allocator();

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

  // create node
  RCCHECK(rclc_node_init_default(&node, "micro_ros_arduino_node", "", &support));

  // create subscriber
  RCCHECK(rclc_subscription_init_default(
    &subscriber,
    &node,
    ROSIDL_GET_MSG_TYPE_SUPPORT(sensor_msgs, msg, Image),
    "micro_ros_subscriber"));

  // create executor
  RCCHECK(rclc_executor_init(&executor, &support.context, 1, &allocator));
  RCCHECK(rclc_executor_add_subscription(&executor, &subscriber, &msg, &subscription_callback, ON_NEW_DATA));
}

void loop() {
  delay(100);
  RCCHECK(rclc_executor_spin_some(&executor, RCL_MS_TO_NS(100)));
}
@ZaGabriel ZaGabriel changed the title Micro ros subscriber and publisher cant work together. Micro ros image subscriber issue Oct 10, 2024
@hippo5329
Copy link

You will need to handle message memory allocation.

https://micro.ros.org/docs/tutorials/advanced/handling_type_memory/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants