Arduino code facing problems with rosserial

asked 2018-04-15 05:27:47 -0600

Prof. xavier gravatar image

updated 2018-04-15 13:30:26 -0600

jayess gravatar image

Hello, I am a beginner. I will try to be as specific as possible, So I am trying to run a single servo with arduino using rosserial lib. I am using the example code for servo control :

#if (ARDUINO >= 100)
 #include <Arduino.h>
 #include <WProgram.h>

#include <Servo.h> 
#include <ros.h>
#include <std_msgs/UInt16.h>

ros::NodeHandle  nh;

Servo servo;

void servo_cb( const std_msgs::UInt16& cmd_msg){
  servo.write(; //set servo angle, should be from 0-180  
  digitalWrite(13, HIGH-digitalRead(13));  //toggle led  

ros::Subscriber<std_msgs::UInt16> sub("servo", servo_cb);

void setup(){
  pinMode(13, OUTPUT);


  servo.attach(9); //attach it to pin 9

void loop()



there is always an error on every upload I do --- > avrdude: stk500_recv(): programmer is not responding I have to always change the permission for /dev/ttyACM0 with "sudo chmod a+rw /dev/ttyACM0", after this I uploaded the code and it was successful.

I uploaded the code, uploading was successful but when I connected the servo, it did not give any output(it did not run) when I published an angle msg on servo topic, when I echoed the servo topic, the msgs topic was talking all the msgs but there was not movement in the servo at all.

Then I tried to run a non-ros code to run a simple servo on my computer and with the simple code too the servo did not respond at all, just to make sure that all the hardware was fine and I took another windows-computer and tried to upload the simple code and the servo worked great with the same code.

I am using ros-kineitc and rosserial for this project, what could be the problem here ? please help me and ask any further questions as required to solve this. Thanks for any help.

edit retag flag offensive close merge delete


If the non-ROS code didn't work using your computer, then the problem is not with ROS. I suggest you ask in an Arduino forum for help with that problem, because there are more likely to be lots of people who can help you fix the real problem in that sort of place.

Geoff gravatar image Geoff  ( 2018-04-15 21:55:29 -0600 )edit

@Prof. xavier may You post the Error, that occur while publishing angle ?

lagankapoor gravatar image lagankapoor  ( 2018-04-16 03:04:14 -0600 )edit