nh.spinOnce();
}
"
I have an ultrasonic connected to the arduino using Serial 2 Hardware Serial Port where the ultrasonic sends the distance data in ASCII coded format over the Serial comunication line. However ROS node fails to communicate and give an error (unable to sync, version mismatch etc) But when i remove the line :- "dist_msg.data = sensor.getDistance(); " it does connect.
Could someone help me solve this. Thank you in advance.
"
include
include <std_msgs/Float32.h>
include
ros::NodeHandle nh; Ultrasonicn sensor(&Serial2);
std_msgs::Float32 dist_msg; ros::Publisher pub_dist("Dist", &dist_msg);
void setup() { Serial.begin(9600); Serial2.begin(9600); nh.initNode(); nh.advertise(pub_dist);
}
void loop() {
dist_msg.data = sensor.getDistance(); pub_dist.publish(&dist_msg);
nh.spinOnce(); } " I have an ultrasonic connected to the arduino using Serial 2 Hardware Serial Port where the ultrasonic sends the distance data in ASCII coded format over the Serial comunication line. However ROS node fails to communicate and give an error (unable to sync, version mismatch etc) But when i remove the line :- "dist_msg.data = sensor.getDistance(); " it does connect.
Could someone help me solve this. Thank you in advance.