ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
/* * rosserial Servo Control Example * * This sketch demonstrates the control of hobby R/C servos * using ROS and the arduiono * * For the full tutorial write up, visit * www.ros.org/wiki/rosserial_arduino_demos * * For more information on the Arduino Servo Library * Checkout : * http://www.arduino.cc/en/Reference/Servo */
#include "Arduino.h"
#include <wprogram.h>
ros::NodeHandle nh;
Servo servo1; Servo servo2; Servo servo3; Servo servo4; Servo servo5; Servo servo6;
void servo_cb1( const std_msgs::UInt16& cmd_msg){ servo1.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb2( const std_msgs::UInt16& cmd_msg){ servo2.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb3( const std_msgs::UInt16& cmd_msg){ servo3.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb4( const std_msgs::UInt16& cmd_msg){ servo4.write(cmd_msg.data); //set servo angle, should be from 0-180
} void servo_cb5( const std_msgs::UInt16& cmd_msg){ servo5.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb6( const std_msgs::UInt16& cmd_msg){ servo6.write(cmd_msg.data); //set servo angle, should be from 0-180
}
ros::Subscriber<std_msgs::uint16> sub("servo1", servo_cb); ros::Subscriber<std_msgs::uint16> sub("servo2", servo_cb); ros::Subscriber<std_msgs::uint16> sub("servo3", servo_cb); ros::Subscriber<std_msgs::uint16> sub("servo4", servo_cb); ros::Subscriber<std_msgs::uint16> sub("servo5", servo_cb); ros::Subscriber<std_msgs::uint16> sub("servo6", servo_cb);
void setup(){ pinMode(13, OUTPUT); pinMode(12, OUTPUT); pinMode(11, OUTPUT); pinMode(10, OUTPUT); pinMode(9, OUTPUT); pinMode(8, OUTPUT);
nh.initNode(); nh.subscribe(sub);
servo1.attach(13); //attach it to pin 13 servo2.attach(12); servo3.attach(11); //attach it to pin 11 servo4.attach(10); servo1.attach(9); //attach it to pin 9 servo2.attach(8);
}
void loop(){ nh.spinOnce(); delay(1); }
2 | No.2 Revision |
/* * rosserial Servo Control Example * * This sketch demonstrates the control of hobby R/C servos * using ROS and the arduiono * * For the full tutorial write up, visit * www.ros.org/wiki/rosserial_arduino_demos * * For more information on the Arduino Servo Library * Checkout : * http://www.arduino.cc/en/Reference/Servo */
#include }
}
}
}
}
}
ros::Subscriber<std_msgs::uint16> sub("servo1", servo_cb); ros::Subscriber<std_msgs::uint16> sub("servo2", servo_cb); ros::Subscriber<std_msgs::uint16> sub("servo3", servo_cb); ros::Subscriber<std_msgs::uint16> sub("servo4", servo_cb); ros::Subscriber<std_msgs::uint16> sub("servo5", servo_cb); ros::Subscriber<std_msgs::uint16> sub("servo6", servo_cb);
}
3 | No.3 Revision |
#include "Arduino.h"
#else
#include <WProgram.h>
#endif
#include <Servo.h>
#include <ros.h>
#include <std_msgs/UInt16.h>
ros::NodeHandle nh;
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;
void servo_cb1( const std_msgs::UInt16& cmd_msg){
servo1.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb2( const std_msgs::UInt16& cmd_msg){
servo2.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb3( const std_msgs::UInt16& cmd_msg){
servo3.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb4( const std_msgs::UInt16& cmd_msg){
servo4.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb5( const std_msgs::UInt16& cmd_msg){
servo5.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb6( const std_msgs::UInt16& cmd_msg){
servo6.write(cmd_msg.data); //set servo angle, should be from 0-180
}
ros::Subscriber<std_msgs::UInt16> sub1("servo1", servo_cb1);
ros::Subscriber<std_msgs::UInt16> sub2("servo2", servo_cb2);
ros::Subscriber<std_msgs::UInt16> sub3("servo3", servo_cb3);
ros::Subscriber<std_msgs::UInt16> sub4("servo4", servo_cb4);
ros::Subscriber<std_msgs::UInt16> sub5("servo5", servo_cb5);
ros::Subscriber<std_msgs::UInt16> sub6("servo6", servo_cb6);
void setup(){
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
nh.initNode();
nh.subscribe(sub1);
nh.subscribe(sub2);
nh.subscribe(sub3);
nh.subscribe(sub4);
nh.subscribe(sub5);
nh.subscribe(sub6);
servo1.attach(13); //attach it to pin 13
servo2.attach(12);
servo3.attach(11); //attach it to pin 11
servo4.attach(10);
servo1.attach(9); //attach it to pin 9
servo2.attach(8);
}
void loop(){
nh.spinOnce();
delay(1);
}
4 | No.4 Revision |
#include "Arduino.h"
#else
#include <WProgram.h>
#endif
#include <Servo.h>
#include <ros.h>
#include <std_msgs/UInt16.h>
ros::NodeHandle nh;
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;
void servo_cb1( const std_msgs::UInt16& cmd_msg){
servo1.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb2( const std_msgs::UInt16& cmd_msg){
servo2.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb3( const std_msgs::UInt16& cmd_msg){
servo3.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb4( const std_msgs::UInt16& cmd_msg){
servo4.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb5( const std_msgs::UInt16& cmd_msg){
servo5.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb6( const std_msgs::UInt16& cmd_msg){
servo6.write(cmd_msg.data); //set servo angle, should be from 0-180
}
ros::Subscriber<std_msgs::UInt16> sub1("servo1", servo_cb1);
ros::Subscriber<std_msgs::UInt16> sub2("servo2", servo_cb2);
ros::Subscriber<std_msgs::UInt16> sub3("servo3", servo_cb3);
ros::Subscriber<std_msgs::UInt16> sub4("servo4", servo_cb4);
ros::Subscriber<std_msgs::UInt16> sub5("servo5", servo_cb5);
ros::Subscriber<std_msgs::UInt16> sub6("servo6", servo_cb6);
void setup(){
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
nh.initNode();
nh.subscribe(sub1);
nh.subscribe(sub2);
nh.subscribe(sub3);
nh.subscribe(sub4);
nh.subscribe(sub5);
nh.subscribe(sub6);
servo1.attach(13); //attach it to pin 13
servo2.attach(12);
servo3.attach(11); //attach it to pin 11
servo4.attach(10);
servo1.attach(9); //attach it to pin 9
servo2.attach(8);
}
void loop(){
nh.spinOnce();
delay(1);
}
5 | No.5 Revision |
#include "Arduino.h"
#else
#include <WProgram.h>
#endif
#include <Servo.h>
#include <ros.h>
#include <std_msgs/UInt16.h>
ros::NodeHandle nh;
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;
void servo_cb1( const std_msgs::UInt16& cmd_msg){
servo1.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb2( const std_msgs::UInt16& cmd_msg){
servo2.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb3( const std_msgs::UInt16& cmd_msg){
servo3.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb4( const std_msgs::UInt16& cmd_msg){
servo4.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb5( const std_msgs::UInt16& cmd_msg){
servo5.write(cmd_msg.data); //set servo angle, should be from 0-180
}
void servo_cb6( const std_msgs::UInt16& cmd_msg){
servo6.write(cmd_msg.data); //set servo angle, should be from 0-180
}
ros::Subscriber<std_msgs::UInt16> sub1("servo1", servo_cb1);
ros::Subscriber<std_msgs::UInt16> sub2("servo2", servo_cb2);
ros::Subscriber<std_msgs::UInt16> sub3("servo3", servo_cb3);
ros::Subscriber<std_msgs::UInt16> sub4("servo4", servo_cb4);
ros::Subscriber<std_msgs::UInt16> sub5("servo5", servo_cb5);
ros::Subscriber<std_msgs::UInt16> sub6("servo6", servo_cb6);
void setup(){
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
nh.initNode();
nh.subscribe(sub1);
nh.subscribe(sub2);
nh.subscribe(sub3);
nh.subscribe(sub4);
nh.subscribe(sub5);
nh.subscribe(sub6);
servo1.attach(13); //attach it to pin 13
servo2.attach(12);
servo3.attach(11); //attach it to pin 11
servo4.attach(10);
servo1.attach(9); //attach it to pin 9
servo2.attach(8);
}
void loop(){
nh.spinOnce();
delay(1);
}