-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathinteractiveRover.py
More file actions
77 lines (68 loc) · 2.22 KB
/
interactiveRover.py
File metadata and controls
77 lines (68 loc) · 2.22 KB
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
from __future__ import division
import time
from PCA9685ROBOT import PCA9685ROBOT
from PCA9685ROBOT import ROVER
from PCA9685ROBOT import MOTOR
# Uncomment to enable debug output.
#import logging
#logging.basicConfig(level=logging.DEBUG)
# Initialise the PCA9685 using the default address (0x40).
pwm = PCA9685ROBOT()
# Alternatively specify a different address and/or bus:
#pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)
# Configure min and max servo pulse lengths
servo_min = 150 # Min pulse length out of 4096
servo_med = 600 # Max pulse length out of 4096
servo_max = 2000
# Set frequency to 60hz, good for servos.
pwm.set_pwm_freq(60)
fwd_rht = MOTOR(6, 5, 4)
bwd_rht = MOTOR(7, 8, 9)
bwd_lft = MOTOR(12, 11, 10)
fwd_lft = MOTOR(13, 14, 15)
rover = ROVER()
print('Moving servo on channel 0, press Ctrl-C to quit...')
print('Press F: Forward')
print('Press B: Backward')
print('Press L: Turn LEFT')
print('Press R: Turn RIGHT')
print('Press I: Increase Speed')
print('Press D: Decrease Speed')
print('Press S: Stop')
print('Press one of the above options')
try:
while True:
cmd = input()
if(cmd == 'F' or cmd == 'f'):
#rover.stop_rover()
rover.start_rover()
time.sleep(1)
rover.forward_rover()
rover.set_rover_speed(40)
time.sleep(5)
elif(cmd == 'B' or cmd == 'b'):
#rover.stop_rover()
rover.reverse_rover()
time.sleep(1)
rover.set_rover_speed(40)
time.sleep(10)
elif(cmd == 'L' or cmd == 'l'):
#rover.stop_rover()
rover.left_rover()
time.sleep(5)
elif(cmd == 'R' or cmd == 'r'):
#rover.stop_rover()
rover.right_rover()
time.sleep(5)
elif(cmd == 'I' or cmd == 'i'):
rover.set_rover_speed(99.5)
time.sleep(5)
elif(cmd == 'D' or cmd == 'd'):
rover.set_rover_speed(30.5)
time.sleep(5)
elif(cmd == 'S' or cmd == 's'):
rover.stop_rover()
except KeyboardInterrupt:
print('Attempt Program interrupt')
rover.stop_rover()
print('Program interrupted')