-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote_control.py
More file actions
executable file
·67 lines (57 loc) · 2.19 KB
/
Copy pathremote_control.py
File metadata and controls
executable file
·67 lines (57 loc) · 2.19 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
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
import asyncio
from kybernetes import MotionController
class App():
def __new__(cls, *args, **kwargs):
return super().__new__(cls)
def __init__(self):
self.controller = MotionController.Connection()
async def run(self):
await self.controller.start()
# send the configuration packet
await self.controller.set_configuration(\
deadzone_forward = 1525,
deadzone_backward = 1475,
deadzone_left = 1525,
deadzone_right = 1525,
Kp = 0.15,
Ki = 0.25,
Kd = 0.01
)
while True:
# Forward motion
print('arm controller to move forward')
await self.controller.wait_until_armable()
await self.controller.arm()
print('moving forward')
await self.controller.set_throttle_pid(2.0)
while True:
s = await self.controller.get_status()
print(f'status: {s}')
if not s.armed():
break
await self.controller.set_steering(-s.remote.servoSteeringInput + 1500)
print('disarmed. waiting for idle.')
await self.controller.wait_for_idle()
# Backward motion
print('arm self.controller to move backward')
await self.controller.wait_until_armable()
await self.controller.arm()
print('moving backward')
await self.controller.set_throttle_pid(-0.25)
while True:
s = await self.controller.get_status()
print(f'status: {s}')
if not s.armed():
break
await self.controller.set_steering(-s.remote.servoSteeringInput + 1500)
print('disarmed. waiting for idle.')
await self.controller.wait_for_idle()
# run asynchronous app
if __name__ == "__main__":
async def main():
await App().run()
asyncio.run(main())