Some basic help
Hi, I'm using Ubuntu 14.04, Indigo.
I'm trying to get used to using ROS and robot programing. I have a code in python which will turn a servo, but I'm unsure how to "ROSatize" it. When I look online for codes written for ROS I usually see node handles, and values saved as geometry_msgs.msg Twist, publishers and subscribers. I think using the right variable (I think that's what they are) I hope to be able to do something like rosbag Twist
to get the time history of the servo angle. Getting this right now will save me headache when I make a full blown robot. By writing this code for a servo, I hope to learn the basics of how these components function. I didn't find any tutorials that really explain these things.
Here's my code now:
# Servo Control
import time
def set(property, value):
try:
f = open("/sys/class/rpi-pwm/pwm0/" + property, 'w')
f.write(value)
f.close()
except:
print("Error writing to: " + property + " value: " + value)
def setServo(angle):
set("servo", str(angle))
set("delayed", "0")
set("mode", "servo")
set("servo_max", "180")
set("active", "1")
delay_period = 0.01
while True:
angle = input('Enter Angle: ')
setServo(angle)
This code uses some things like delayed, mode, and stuff. I just want to be able to run this using rosrun, send angles using something like rostopic pub servo std_msgs/UInt16 <angle>
, and use rosbag on it.
Thanks