-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathMotorDualPwm.py
39 lines (39 loc) · 1.04 KB
/
MotorDualPwm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#########################################
# 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()