-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjoystick_mode.py
More file actions
56 lines (49 loc) · 1.65 KB
/
joystick_mode.py
File metadata and controls
56 lines (49 loc) · 1.65 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
import web_interface_core
import threading
import argparse
import inputs # https://inputs.readthedocs.io/en/latest/user/intro.html
steer = 0
drive = 0
done = False
def event_loop():
"""
This function is called in a loop, and will get the events from the
controller and send them to the functions we specify in the `event_lut`
dictionary
"""
global done, drive, steer
while not done:
events = inputs.get_gamepad()
for event in events:
if event.code == "ABS_RZ":
drive = event.state / -256.0
# print('\t', event.ev_type, event.code, event.state)
if event.code == "ABS_X":
steer = (event.state - 128) / 128.0
if event.code == "ABS_RZ":
drive = event.state / -256.0
elif event.code == "ABS_Z":
drive = event.state / 256.0
if event.code == "BTN_NORTH":
done = True
def main():
"""Process all events forever."""
parser = argparse.ArgumentParser()
parser.add_argument("ip")
parser.add_argument("password")
args = parser.parse_args()
print("Logging onto " + args.ip + " with password: " + args.password)
client = web_interface_core.DRInterface(args.password, args.ip)
client.log_on()
client.set_manual_mode()
client.start_car()
t1 = threading.Thread(target=event_loop, name='t1')
t1.start()
global done, drive, steer
while not done:
client.send_drive_command(steer, drive)
print("Steering command: " + str(steer) + " Throttle command: " + str(drive))
client.stop_car()
t1.join()
if __name__ == "__main__":
main()