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

Hi, i canot publish an array to ros from arduino ide.

asked 2017-10-29 00:56:24 -0600

ARUN T S gravatar image

updated 2017-10-31 06:01:49 -0600

enter code here

#include <ros.h>
#include <Wire.h>
    #define    LIDARLite_ADDRESS   0x62         
    #define    RegisterMeasure     0x00         
    #define    MeasureValue        0x04       
    #define    RegisterHighLowB    0x8f         
    #define USB_USBCON
    #include <LIDARLite.h>
    #include <I2C.h>
    #include <sensor_msgs/Range.h>
    #include <sensor_msgs/LaserScan.h>
     LIDARLite myLidarLite;
     ros::NodeHandle  nh;
     sensor_msgs::LaserScan scan;
     ros::Publisher pub_range( "lidar", &scan);
     float ranges[7];
      char frameid[] = "/my_frame";
     int lidarGetRange(void) 
     {
     int val = -1;
     Wire.beginTransmission((int)LIDARLite_ADDRESS); 
     Wire.write((int)RegisterMeasure); 
     Wire.write((int)MeasureValue);   
     Wire.endTransmission(); 
      delay(20); 
     Wire.beginTransmission((int)LIDARLite_ADDRESS);
     Wire.write((int)RegisterHighLowB); 
     Wire.endTransmission(); 
     delay(20); 
     Wire.requestFrom((int)LIDARLite_ADDRESS, 2);
     if(2 <= Wire.available()) 
     {
     val = Wire.read(); 
     val = val << 8; 
     val |= Wire.read();
      }
      return val;
      }
     void setup()
      {
     Serial.begin(57600);
    nh.initNode();
    nh.advertise(pub_range);
    //delay(1000);
     myLidarLite.begin(0, true);
    myLidarLite.configure(0);
    scan.header.frame_id =  frameid;
    scan.angle_min= 0; 
     scan.angle_max= 3.14;
    scan.angle_increment =1; 
    scan.range_min = 0.03;  
    scan.range_max = 4000; 
          } 
     void loop()
      {
     for(int i = 0; i < 7; i++)
         {
      Serial.println(lidarGetRange());
      scan.ranges[i] =lidarGetRange();   
       pub_range.publish(&scan);
         }
        nh.spinOnce();
      }`
edit retag flag offensive close merge delete

Comments

We're all here to help so no need for the "plz help"

jayess gravatar image jayess  ( 2017-10-29 01:11:35 -0600 )edit

Make sure you're not using the same serial port for ROS and for Serial.println(..)). That will not work.

Also: make sure you have a large enough buffer on the Arduino side (LaserScan msgs are big), and search ROS Answers for similar Q&As. There have been a few.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-29 01:52:46 -0600 )edit

make sure you are adding ros header at the top of the code.

shubham gravatar image shubham  ( 2017-10-29 02:34:15 -0600 )edit
3

So in general: @ARUN T S: in order for us to all stop guessing what migth be wrong here, please update your question to include the relevant (and required) information. See wiki/Support.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-29 02:37:40 -0600 )edit

i edited my question ,this is my full program, can u guys find out what is the error in my program? am trying to create a map of surroundings with a lidar lite v3 using hector slam

ARUN T S gravatar image ARUN T S  ( 2017-10-31 06:03:49 -0600 )edit

I see a Serial.println(lidarGetRange()); and use of ROS in the same program. Have you made sure that those two are not using the same serial port?

Also: please see the support guidelines: we cannot ..

gvdhoorn gravatar image gvdhoorn  ( 2017-10-31 07:43:00 -0600 )edit

.. help you because all you wrote was "I canot publish". Does that mean that everything appears to work, but there are no messages? Are you getting error messages printed on your console? Is rosserial complaining about desyncs? Etc.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-31 07:43:49 -0600 )edit

Getting error message when i tries to establish serial publication between arduino and ros

[ERROR] [1509616280.864411]: Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino

When i remove for loop no error

ARUN T S gravatar image ARUN T S  ( 2017-11-02 07:31:25 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-11-02 15:02:07 -0600

gvdhoorn gravatar image

Please remove the following line:

Serial.println(lidarGetRange());

You cannot use the serial port through Serial and use rosserial at the same time.

edit flag offensive delete link more

Comments

That's it, Thank you gvhoorn , and i also have to remove delay

ARUN T S gravatar image ARUN T S  ( 2017-11-03 13:00:45 -0600 )edit

Please mark the question as answered by ticking the checkmark to the left of the answer. Thanks.

gvdhoorn gravatar image gvdhoorn  ( 2017-11-04 06:20:02 -0600 )edit

I really appreciate your help But am Getting one more error when i increased loop condition to 200(i<200) it's like

wrong checksum for topic id and msg
ARUN T S gravatar image ARUN T S  ( 2017-11-04 11:17:44 -0600 )edit

That sounds like a different problem. Please use questions for single problems only.

gvdhoorn gravatar image gvdhoorn  ( 2017-11-04 14:44:35 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2017-10-29 00:56:24 -0600

Seen: 436 times

Last updated: Oct 31 '17