-
Notifications
You must be signed in to change notification settings - Fork 47
/
Test_Motor.py
77 lines (63 loc) · 1.82 KB
/
Test_Motor.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python
import PiMotor
import time
import RPi.GPIO as GPIO
#Name of Individual MOTORS
m1 = PiMotor.Motor("MOTOR1",1)
m2 = PiMotor.Motor("MOTOR2",1)
m3 = PiMotor.Motor("MOTOR3",1)
m4 = PiMotor.Motor("MOTOR4",1)
#To drive all motors together
motorAll = PiMotor.LinkedMotors(m1,m2,m3,m4)
#Names for Individual Arrows
ab = PiMotor.Arrow(1)
al = PiMotor.Arrow(2)
af = PiMotor.Arrow(3)
ar = PiMotor.Arrow(4)
##This segment drives the motors in the direction listed below:
## forward and reverse takes speed in percentage(0-100)
try:
while True:
#-----------To Drive the Motors Forward------------#
print("Robot Moving Forward ")
af.on()
motorAll.forward(100)
time.sleep(5)
#--------------------------------------------------#
#-----------To Drive the Motors backwards------------#
print("Robot Moving Backward ")
af.off()
ab.on()
motorAll.reverse(100)
time.sleep(5)
#--------------------------------------------------#
#-----------To Drive the Motors Left---------------#
print("Robot Moving Left ")
ab.off()
al.on()
m1.stop()
m2.stop()
m3.forward(100)
m4.forward(100)
time.sleep(5)
#--------------------------------------------------#
#----------To Drive the Motors Right---------------#
print("Robot Moving Right ")
ar.on()
al.off()
m1.forward(100)
m2.forward(100)
m3.stop()
m4.stop()
time.sleep(5)
#-------------------------------------------------#
#---------To Stop the Motors----------------------#
print("Robot Stop ")
al.off()
af.off()
ar.off()
motorAll.stop()
time.sleep(5)
#-------------------------------------------------#
except KeyboardInterrupt:
GPIO.cleanup()