Submitted by admin on Tue, 02/14/2012 - 13:53
The Servo service is used to control servos through a micro-controller such as an Arduino or a Raspberry pi (ServoController).
The service will allow to control attaching or detaching the device, control his position and the speed at wich it move to that position, and turn off/on the servo.
servo.attach(controller, pin, pos, velocity): Initial servo device attachement to the microcontroller
servo.detach(controller): detach the servo from the microcontroller
servo.attach(): Name as arduino servo library, will turn the servo motor on
servo.detach(): will turn the servo motor off
servo.moveTo(pos): ask the servo to move to a position
servo.map(inputMin, inputMax, outputMin, outputMax): default to (0,180, 0, 180). Allow to map a range to a valid output range that can be understand by the servo. The outputMin and outputMax must have value between 0 and 180.
setvo.setInverted(true/false): Reverse the direction of rotation of the servo.
Connect the signal wire to a pin on the controller
Connect the (+) wire to the (+) of a power source (battery or power supply)
Connect the (-) wire to the ground of a power source AND the ground of the controller
Servo needs a lot of current and require to be connect to a power source that can provide enough current. The controllers (Arduino or Raspberry pi) are not strong enough to make the servo work properly and you should avoid connecting the 5V of the controller to the servo.
arduino = Runtime.createAndStart("arduino","Arduino")
servo = Runtime.createAndStart("servo","Servo")
servo.attach(arduino,26,90,-1) #attach the servo to pin 26 at an initial position of 90 and without speed control)
#servo.attach(arduino,26,180,20) #attach the servo to pin 26 at an initial position of 180 and will make the servo rotate at the speed of 20 degrees/s)
servo.moveTo(0) # move the servo position to 0
Speed control (working only when connected to an Arduino)
servo.setVelocity(degree/s): Will force the servo to rotate at the specify velocity. If the speed specify is faster than the servo capability, the servo will turn at a lower speed than expected. The value -1 will bypass the speed control and have the servo rotate normally.
This is a common Servo service. All simple Servos need to attach to a ServoController. Currently, the list of ServoControllers are :
The Servo needs a controller in order to operate. You should be able to select one in the drop down. Select the correct signal pin the servo is attached to. Then select "attach" and the servo should be controllable with the slider bar. Limits can be set in order to protect the servo from going beyon a certain minimum and maximum value.
Now there is an additional method Servo.setSpeed(0.5). At the moment this is only accessable through Python. This will set the speed of a servo. The servo will remember it's last speed until it is changed again. Valid values for speed are between 0.0 and 1.0
#file : service/Servo.py edit raw
from org.myrobotlab.service import Arduino
from org.myrobotlab.service import Servo
from org.myrobotlab.service import Runtime
from time import sleep
servoPin = 4
# comPort = "/dev/ttyUSB0"
comPort = "COM15"
# create the services
arduino = Runtime.start("arduino","Arduino")
servo01 = Runtime.start("servo01","Servo")
# initialize arduino
# TODO - set limits
# attach servo
# fast sweep
# speed changes
servo01.setSpeed(0.99) # set speed to 99% of full speed
servo01.setSpeed(0.50) # set speed to 50% of full speed
servo01.setSpeed(1.0) # set speed to 100% of full speed
# moving to rest position
# detaching servo
Modular Block Diagram showing the differences of sweeping a Servo from MyRobotLab versus sweeping it from the microcontroller (Arduino)