micro-ROS / micro-ROS-demos

Sample code using rclc and rclcpp implementations.
Apache License 2.0
84 stars 24 forks source link

Unable to isolate micro_ros topics #82

Closed Muthukumar4796 closed 8 months ago

Muthukumar4796 commented 8 months ago

Issue template

Steps to reproduce the issue

I am having difficulty isolating Micro-ROS topics without affecting the ROS domain ID specified in the bashrc file. Even after configuring the ROS domain ID within the Micro-ROS code, the topics do not appearing.

Additionally, when I try to check your Micro-ROS code, the Micro-ROS agent is also not running. https://github.com/micro-ROS/micro-ROS-demos/blob/70f3cbf27ce12dc9e57e5095b4233553e207d866/rclc/configuration_example/configured_publisher/main.c

I shared the link to your code and sent a screenshot of the Micro ROS agent not functioning.

Screenshot from 2024-01-09 16-36-19

pablogs9 commented 8 months ago

Your micro-ROS client is not connected to the micro-ROS Agent, have you reset the board after connecting?

Muthukumar4796 commented 8 months ago

Yes.I reset the board. but still not connect micro_ros agent.

pablogs9 commented 8 months ago

Could you check if your board is sending any data via the serial port? Maybe using minicom or miniterm instead of the agent?

Muthukumar4796 commented 8 months ago

No, the board is not sending any data via serial.I'm not sure about using miniterm or minicom. I have only used Agent for my entire project. I am stuck while isolating the micro ROS topics.I have been facing this issue for the past three weeks.

Muthukumar4796 commented 8 months ago

I have found a solution to the problem of isolating the topic. In the code provided, the necessary lines were not included. I have added the following lines to the code to fix the issue:

// Initialize rclc support object with custom options

rclc_support_t support;

rclc_support_init_with_options(&support, 0, NULL, &init_options, &allocator);

Please take a look at this updated code.

include

include

include <rcl/rcl.h>

include <rcl/error_handling.h>

include <rclc/rclc.h>

include <rclc/executor.h>

include <std_msgs/msg/int32.h>

rcl_publisher_t publisher; std_msgsmsgInt32 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 timer_callback(rcl_timer_t * timer, int64_t last_call_time) {
RCLC_UNUSED(last_call_time); if (timer != NULL) { RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL)); msg.data++; } }

void setup() { set_microros_transports();

pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, HIGH);

delay(2000);

allocator = rcl_get_default_allocator();

// Initialize micro-ROS allocator rcl_allocator_t allocator = rcl_get_default_allocator();

// Initialize and modify options (Set DOMAIN ID to 7) rcl_init_options_t init_options = rcl_get_zero_initialized_init_options(); rcl_init_options_init(&init_options, allocator); rcl_init_options_set_domain_id(&init_options, 7);

// Initialize rclc support object with custom options rclc_support_t support; rclc_support_init_with_options(&support, 0, NULL, &init_options, &allocator);

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

// create publisher RCCHECK(rclc_publisher_init_default( &publisher, &node, ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32), "micro_ros_arduino_node_publisher"));

// create timer, const unsigned int timer_timeout = 1000; RCCHECK(rclc_timer_init_default( &timer, &support, RCL_MS_TO_NS(timer_timeout), timer_callback));

// create executor RCCHECK(rclc_executor_init(&executor, &support.context, 1, &allocator)); RCCHECK(rclc_executor_add_timer(&executor, &timer));

msg.data = 0; }

void loop() { delay(100); RCSOFTCHECK(rclc_executor_spin_some(&executor, RCL_MS_TO_NS(100))); }

--here is the updated micro ros publisher code for isolating topics using Domain_ID.Thanks for the support