micro-ROS / micro-ROS/micro_ros_arduino

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

Open
#1,791 50 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
576
Forks
146
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the posted Arduino sketch, especially subscription_callback and the compiler diagnostic on the digitalWrite line. Compare the String message handling with the existing micro_ros_subscriber example and verify that the sketch compiles and responds correctly to the key_hit_event subscription.

Written by the indexing model from the issue text.

Assessment

Tech stack
arduino, c
Domain
embedded-iot
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.