-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsingle.py
49 lines (40 loc) · 1.67 KB
/
single.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
#!/usr/bin/env python3
import odrive
from odrive.enums import *
from UDPComms import Subscriber, timeout, Publisher
import time
import os
if os.geteuid() != 0:
exit("You need to have root privileges to run this script.\nPlease try again, this time using 'sudo'. Exiting.")
a = Subscriber(8830, timeout = 0.3)
odom = Publisher(8820)
print("finding any odrives...")
odrive = odrive.find_any()
print("found an odrive (random)")
odrive.axis0.requested_state = AXIS_STATE_IDLE
odrive.axis1.requested_state = AXIS_STATE_IDLE
while True:
try:
msg = a.get()
print(msg)
odom.send([odrive.axis0.encoder.pos_estimate / odrive.axis0.encoder.config.cpr,
- odrive.axis1.encoder.pos_estimate / odrive.axis1.encoder.config.cpr])
if (msg['t'] == 0 and msg['f'] == 0):
odrive.axis0.requested_state = AXIS_STATE_IDLE
odrive.axis1.requested_state = AXIS_STATE_IDLE
else:
odrive.axis0.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
odrive.axis1.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
odrive.axis0.controller.vel_setpoint = (msg['f'] + msg['t'])
odrive.axis1.controller.vel_setpoint = -(msg['f'] - msg['t'])
except timeout:
odrive.axis0.requested_state = AXIS_STATE_IDLE
odrive.axis1.requested_state = AXIS_STATE_IDLE
odrive.axis0.controller.vel_setpoint = 0
odrive.axis1.controller.vel_setpoint = 0
except:
odrive.axis0.requested_state = AXIS_STATE_IDLE
odrive.axis1.requested_state = AXIS_STATE_IDLE
odrive.axis0.controller.vel_setpoint = 0
odrive.axis1.controller.vel_setpoint = 0
raise