Hi all!!
I am trying to go further with the basic example of Ros Serial with Arduino and a Servo. In this example, the publisher asks for an angle where to drive a servo. I am trying to do this with two servos, but the only thing I can do is to drive both to the same position. I need some tip for how to write two parameters in Ros, so each servo goes to its position. The code I have for the moment is as follows:
ros::NodeHandle nh;
Servo servo, servo2;
void servo_cb( const std_msgs::UInt16& cmd_msg){
servo.write(cmd_msg.data); //set servo angle, should be from 0-180
servo2.write(cmd_msg.data);
digitalWrite(13, HIGH-digitalRead(13)); //toggle led
}
ros::Subscriber<std_msgs::UInt16> sub("servo", servo_cb); ros::Subscriber<std_msgs::UInt16> sub2("servo2", servo_cb);
void setup(){ pinMode(13, OUTPUT);
nh.initNode(); nh.subscribe(sub);
servo.attach(9); //attach it to pin 9 servo2.attach(3); }
void loop(){ nh.spinOnce(); delay(1); }
Can anyone help me please??
Originally posted by flipmurry on ROS Answers with karma: 3 on 2013-04-21
Post score: 0