MotorDualPwm

javadoc

A general DC continous Motor which is controlled by 2 inputs.
A motor controller (such as Arduino or AdafruitMotorShield) is needed for the MotorDualPwm service to attach.
One of the most useful methods is the motor's move(powerLevel).  The powerLevel needs to be a float value between -1.0 and 1.0   
0.0 is stop.  1.0 is full power in a clockwise direction, and -1.0 is full power is a counter clockwise direction. And fractional value will resolve to a fractional amount of power which the motor controller can supply.  e.g. 0.5 would be clockwise at 1/2 power.

Interfacing a motor and motor controller in Python

Be aware that this service use AnalogWrite so it can not be used on all pins.

On the Arduino Uno pins 3,5,6,9,10 and 11 can be used.

On the Arduino Mega pins 2-13 and 44-46 can be used.

MotorDualPwm - 2 PWM,  one for each direction

The board that has been tested is the IBT-4 module. It can drive motors from 5V-15V and up to 50A.

Control voltage 3V3 - 5V so it can be used with most controllerers.

Examples:


#file : service/MotorDualPwm.py edit raw
#########################################
# MotorDualPwm.py
# description: Motor service which support 2 pwr pwm pins clockwise and counterclockwise
# categories: motor
# more info @: http://myrobotlab.org/service/MotorDualPwm
#########################################
# 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)
arduino = runtime.start("arduino","Arduino")
motor = runtime.start("motor","MotorDualPwm")
arduino.connect(port)
motor.setPwmPins(10,11)
motor.attach(arduino)
# At this point you should be able to control the motor thru the Gui
# move both motors forward
# at 50% power
# for 2 seconds
motor.move(0.5)
sleep(2) 
# move both motors backward
# at 50% power
# for 2 seconds
motor.move(-0.5)
sleep(2)
# stop and lock
motor.stopAndLock()
# after locking
# motor should not move
motor.move(0.5)
sleep(2)
# unlock motor and move it
motor.unlock()
motor.move(0.5)
sleep(2)
motor.stop()