forked from UIC-RMC/Final-Testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrolCommMainv4-steeringonly.py
139 lines (112 loc) · 4.21 KB
/
controlCommMainv4-steeringonly.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import serdes
import tcpModule
import time
from mobilityMovementCommandv4 import moveRover
import os
import RPi.GPIO as GPIO
while True:
try:
#monitor pi with GPIO
# LED_PIN = 17
# GPIO.setmode(GPIO.BCM)
# GPIO.setup(LED_PIN, GPIO.OUT)
# GPIO.output(LED_PIN, GPIO.HIGH)
# time.sleep(2)
port, pack = moveRover.servoSetup()
rc1, rc2 = moveRover.init_RoboClaw()
HOST = '192.168.1.162'
PORT = 2356
#create serializer and reciever objects
ser = serdes.deserializer()
print('waiting to connect')
recv = tcpModule.reciever(HOST, PORT)
print('connection confirmed')
angle1 = 1150 #850 note 850 all thw way left, 1450 all the way right
angle2 = 1150 #2400, note same as above for turning
angle3 = 1600 #1850, note 2000 for turnng left, 1200 for right
angle4 = 3600 #3200, note 3900 for left, 3300 for right
flang = angle1
frang = angle2
blang = angle3
brang = angle4
'''
moveRover.moveServos(port, pack, angle1, angle2, angle3, angle4)
moveRover.moveServos(port, pack, angle1, angle2, angle3, angle4)
moveRover.moveServos(port, pack, angle1, angle2, angle3, angle4)
time.sleep(2)
#turn left:
angle = 350
flang = angle + angle1
frang = angle + angle2
blang = -1*angle + angle3
brang = -1*angle + angle4
moveRover.moveServos(port, pack, flang, frang, blang, brang)
moveRover.moveServos(port, pack, flang, frang, blang, brang)
moveRover.moveServos(port, pack, flang, frang, blang, brang)
time.sleep(2)
moveRover.moveServos(port, pack, angle1, angle2, angle3, angle4)
moveRover.moveServos(port, pack, angle1, angle2, angle3, angle4)
moveRover.moveServos(port, pack, angle1, angle2, angle3, angle4)
'''
'''
rc2.BackwardM1(0x80, 40)
print('extend')
time.sleep(2)
temp = rc1.ReadCurrents(0x80)
print(repr(temp[1]))
rc2.ForwardM1(0x80, 0)
print('stop')
'''
#recieve messages
print('will now recieve messages!')
while True:
msg = recv.recieve_msg()
data = ser.decode(msg) #note that data is a python list that contains the different values
print(data[0]) #contains the message type
#do the stuff based on the data
if data[0] == 'move':
wheelVel = data[1]
angle = data[2]
#print(str(angle) +' '+str(wheelVel))
print(str(angle))
#print(type(angle))
#print(type(wheelVel))
#Move Wheels
print(wheelVel)
amps = moveRover.wheelMotors(rc1, wheelVel)
#Move Servos
flang = angle + angle1
#print(flang)
frang = angle + angle2
#print(frang)
blang = -1*angle + angle3
#print(blang)
brang = -1*angle + angle4
#print(brang)
moveRover.moveServos(port, pack, flang, frang, blang, brang)
elif data[0] == 'mine':
speed = 300
digVel = data[4]
print(digVel)
#moveRover.digMotor(rc1, digVel)
# if data[2]:
# curr = moveRover.digActuator(rc2, speed)
# elif data[3]:
# curr = moveRover.digActuator(rc2, -speed)
# else:
# curr = moveRover.digActuator(rc2, 0)
elif data[0] == 'dump':
speed = 300
# if data[1]:
# curr = moveRover.dumpActuator(rc2, speed)
# elif data[2]:
# curr = moveRover.dumpActuator(rc2, -speed)
# else:
# curr = moveRover.dumpActuator(rc2, 0)
# pass
moveRover.moveServos(port, pack, flang, frang, blang, brang)
except:
pass
#timer to reset
#look up how to shut down
#os.system('controlCommMainv3.py')