This article shows you how to drive a hobby servo using Odroid U3.
Upload this to your Arduino board:
/*
* 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
*/
#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#include <Servo.h>
#include <ros.h>
#include <std_msgs/Float32.h>
ros::NodeHandle nh;
Servo servo;
void servo_cb( const std_msgs::Float32& cmd_msg){
servo.write(cmd_msg.data/3.14*180); //set servo angle, should be from 0-180
digitalWrite(13, HIGH-digitalRead(13)); //toggle led
}
ros::Subscriber<std_msgs::Float32> sub("servo", servo_cb);
void setup(){
pinMode(13, OUTPUT);
nh.initNode();
nh.subscribe(sub);
servo.attach(3); //attach it to pin 9
}
void loop(){
nh.spinOnce();
delay(1);
}
In the terminal of Odroid U3:
Open another terminal:
Open another terminal:
<angle>
here can be any float number from 0 to 180.
code
more code
~~~~