Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 59

Error while publishing encoder ticks in Arduino

$
0
0
I am using Arduino Uno to publish Rotary Encoder ticks. I have used the following code to publish the encoder values to ROS and ended up in the error #include #include #include #include #include int val; int encoder0PinA = 2; int encoder0PinB = 3; int encoder0PinZ = 4; int lwheel = 0; int encoder0PinALast = LOW; int n = LOW; ros::NodeHandle nh; std_msgs::Int16 lwheelMsg; ros::Publisher lwheelPub("lwheel", &lwheelMsg); //self._Right_Encoder = rospy.Publisher('rwheel',Int64,queue_size = 10) void setup() { Serial.begin(57600); pinMode (encoder0PinA,INPUT); pinMode (encoder0PinB,INPUT); nh.initNode(); nh.advertise(lwheelPub); } void loop() { n = digitalRead(encoder0PinA); if ((encoder0PinALast == LOW) && (n == HIGH)) { if (digitalRead(encoder0PinB) == LOW) { lwheel--; } else { lwheel++; } Serial.print (lwheel*0.97); Serial.print ("mm/"); lwheelPub.publish(&lwheelMsg); } encoder0PinALast = n; nh.spinOnce(); } ERROR [WARN] [WallTime: 1473618880.299270] Serial Port read returned short (expected 2 bytes, received 1 instead). [WARN] [WallTime: 1473618880.300057] Serial Port read failure: I found some fixes which told to change the baud rate, i tried them but didn't help. Someone please help me to fix the issue and direct me to correct ROS Arduino node to publish encoder ticks to ROS with interupt.

Viewing all articles
Browse latest Browse all 59

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>