micro-ROS / micro_ros_arduino

micro-ROS library for Arduino
Apache License 2.0
446 stars 116 forks source link

Want to rewrite the micro_ros_subscriber for example_interfaces/msg/String. #1791

Open drinkBr opened 4 months ago

drinkBr commented 4 months ago

Hi, I want to rewrite the micro_ros_subscriber for example_interfaces/msg/String. However, when I tried to modify it myself, I encountered an error and couldn't proceed any further. I would like to know how to resolve this issue.

The operating environment ・ArduinoIDE2.1.1 ・Arduino Due

program

< ``` #include #include #include #include #include #include #include rcl_subscription_t subscriber; example_interfaces__msg__String 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) { const example_interfaces__msg__String * msg = (const example_interfaces__msg__String *)msgin; digitalWrite(LED_PIN, (msg->data = "0") ? LOW : HIGH); } 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(example_interfaces, msg, String), "key_hit_event")); // 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))); } ``` Error message ``` rror: no match for 'operator=' (operand types are 'const rosidl_runtime_c__String' and 'const char [2]') digitalWrite(LED_PIN, (msg->data = "0") ? LOW : HIGH); ^ ``` Thank you.