ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

part of sting sent from arduino to ros is missed [closed]

asked 2016-05-25 08:07:13 -0600

crazymumu gravatar image

part of arduino code:

void loop(){
  String ang = String(angle);//angle is global value 
  String dis = String(myLidarLite.distance()); //myLidarLite.distance() is API function to get distance data
  String total = ang+'a'+ dis;

  int len = total.length();
  char toROS[len-1];
  total.toCharArray(toROS, len); 
  scan.data = toROS;  //std_msgs::String scan;
  LIDAR.publish (&scan); //ros::Publisher LIDAR("Lidar_raw", &scan);
  nh.spinOnce();   //ros::NodeHandle nh;
  delay(5);
}

I observed the output of this rostopic:

... data: 76b66
--- data: 103b48
--- data: 134b50
--- data: 163b61
--- data: 193b34
--- data: 227b9
--- data: 248b8
--- data: 271b69
--- data: 296b
--- data: 325b54
...

The dis is missing in some data, I try to output this format string in Serial Monitor and it's right. It just random missed.. Any suggestions will be appreciate.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by crazymumu
close date 2016-05-26 00:45:46.235455

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-05-26 00:44:56 -0600

crazymumu gravatar image

updated 2016-05-26 00:45:11 -0600

define a fixed size of char array like :char toROS[8] solved this problem

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-05-25 08:07:13 -0600

Seen: 243 times

Last updated: May 26 '16