DiyServo

javadoc

The DiyServo service is a service that can be used as a normal servo, but it's built from a motor and an analog input. The idea is that you should be able to use any motor and any analog input to byild your own servo. The circuit below can be used to connect the motor and the servo to a single Arduino. But it's also possible to configure in alternate ways. 

DiyServo

 

Please note that from version 1.0.2274, the configuraion of the DiyServo is different from earlier versions. It now starts a Motor / MotorDualPwm service as a layer between the DiyServo service and the Arduino.

I made two different scripts to show some alternate configurations.


#file : /service/DiyServo.py edit raw
# This is a demo of the setup for DiyServo. 
# This setup is valid from version 1.0.2274
# The difference compared to earlier versions is that it now
# starts a MotorDualPwm service that connects to the Arduino
# Before the DiyServo connected directly to the Arduino.
#
# Config
port="COM3"
# start optional virtual arduino service, used for test
if ('virtual' in globals() and virtual):
    virtualArduino = Runtime.start("virtualArduino", "VirtualArduino")
    virtualArduino.connect(port)
# Start of script for DiyServo
# Analog input A0 is the same as digital 14 on the Arduino Uno
A0 = 14
# Start the Arduino
arduino = Runtime.start("Arduino","Arduino")
arduino.connect(port)
# Start the MotorDualPwm. You can use also use a different type of Motor
motor = Runtime.start("diyservo.motor","MotorDualPwm")
# Tell the motor to attach to the Arduino and what pins to use
motor.setPwmPins(10,11)
motor.attach(arduino)
# Start the DiyServo
servo = Runtime.start("diyservo","DiyServo")
servo.attach(arduino,A0) # Attach the analog pin 0
# Set the PID values. This example shows what DiyServo has as default.
servo.pid.setPID("diyservo", 0.020, 0.001, 0.0);
servo.moveTo(90)
# At this stage you can use the gui or a script to control the DiyServo


#file : /service/DiyServo2.py edit raw
# This is a demo of the setup for DiyServo. 
# This setup is valid from version 1.0.2274
# 
# The DiyServo service don't need to be used with an Arduino. 
# This example show a configuration to drive it from the GPIO pins on a raspberry PI using 
# the Raspi service, an Adafruit16CServoDriver and an Ads1115 AD-converter
# You can also combine the different alternatives in any fashion that you want
#
# Start of script for DiyServo
# Start the RasPi service ( Ths only works on a Raspberry PI )
raspi = Runtime.createAndStart("raspi","RasPi")
# Start and configure the Adafruit16CServoDriver connect to the raspberry on i2c address 0x40 ( default )
ada = Runtime.createAndStart("ada","Adafruit16CServoDriver")
ada.setController(raspi,"1","0x40")
# Start the Motor. You can use also use a different type of Motor
motor = Runtime.createAndStart("diyservo.motor","Motor")
# Tell the motor to attach to the Adafruit16CServoDriver and setup the power and direction pins
# How you configure the motor is depending on what type of motor board you use
motor.attach(ada)
motor.setPwrDirPins(0, 1)
# Start the Ads1115 service to get the Analog input and set the i2c address
ads1115 = Runtime.createAndStart("ads1115","Ads1115")
ads1115.setController(raspi,"1","0x48")
# Start the DiyServo
servo = Runtime.createAndStart("diyservo","DiyServo")
servo.attach(ads1115,0) # Attach the analog pin 0 
servo.moveTo(90)
# At this stage you can use the gui or a script to control the DiyServo

 

Examples:


#file : service/DiyServo.py edit raw
# This is a demo of the setup for DiyServo. 
# This setup is valid from version 1.0.2274
# The difference compared to earlier versions is that it now
# starts a MotorDualPwm service that connects to the Arduino
# Before the DiyServo connected directly to the Arduino.
#
# Config
port="COM3"
# start optional virtual arduino service, used for test
if ('virtual' in globals() and virtual):
    virtualArduino = Runtime.start("virtualArduino", "VirtualArduino")
    virtualArduino.connect(port)
# Start of script for DiyServo
# Analog input A0 is the same as digital 14 on the Arduino Uno
A0 = 14
# Start the Arduino
arduino = Runtime.start("Arduino","Arduino")
arduino.connect(port)
# Start the MotorDualPwm. You can use also use a different type of Motor
motor = Runtime.start("diyservo.motor","MotorDualPwm")
# Tell the motor to attach to the Arduino and what pins to use
motor.setPwmPins(10,11)
motor.attach(arduino)
# Start the DiyServo
servo = Runtime.start("diyservo","DiyServo")
servo.attach(arduino,A0) # Attach the analog pin 0
# Set the PID values. This example shows what DiyServo has as default.
servo.pid.setPID("diyservo", 0.020, 0.001, 0.0);
servo.moveTo(90)
# At this stage you can use the gui or a script to control the DiyServo

hairygael's picture

I just love it !!! Thanks

I just love it !!!

Thanks guys for this fantastic MRL service.

I have been dreaming of this, ever since I burned my first servo!!

SylvainJeanneton's picture

Turn left or right

Thanks your code is very usefull, thanks a lot. But it commands only the speed. How can we command the way ? In other words turn left or turn right with a middle point ? (it exists potentiometer with middle point. I 'm shure of this.) In fact we need both speed and way left or right.
Thanks
Friendly.
Sylvain.

 

Mats's picture

DiyServo

In the example I only have the motor out to show that it works.

Kwatters built the complete DiServo as you can see int his post. So it works in both directions and you can use it just like any other servo. But you have to  mount the pot, so that it turns with the joint.

http://myrobotlab.org/content/diy-servo-service

----

If you built one and only can control speed, then you need a different motor control board.

If  you for example use that board from the drill, then it will only move in one direction and only control speed.

I use a BTS7960B that I bought from here.

http://www.ebay.com/itm/191833193918?_trksid=p2057872.m2749.l2649&ssPage...

I also use a IBT-4 board from here:

http://www.ebay.com/itm/182073487693?_trksid=p2057872.m2749.l2649&ssPage...

I tested the drillmotor with a LN298N board, but it was not powerful enough.

I also tried this board, but it could only drive the motor in one direction: 

http://www.ebay.com/itm/6V-24V-10A-DC-Motor-Speed-Driver-PWM-Adjustable-...

 

hairygael's picture

Hello Mats, I'm working on

Hello Mats,

I'm working on the legs for InMoov right now. Until now I have been using the DIY Servo in a very basic way, but I would like to know if the DIY Servo is compatible with the enable and disable function?

Mats's picture

autoEnable / autoDisable

Hi Gael

Not currently. But the intention is that you should be able to replace any Servo with DiyServo.

/Mats