-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenPythonApi.py
More file actions
107 lines (91 loc) · 3.43 KB
/
Copy pathopenPythonApi.py
File metadata and controls
107 lines (91 loc) · 3.43 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
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
# Lab of Biomechatronics Open Source Exoskeleton controller program.
# This program can connect to an Arduino Nano BLE 33 and
# controll the exoskeleton by sending commands that the
# exoskeleon firmware interprets.
# Author: Payton Cox
# Date Created: Jan 2024
# Last updated: May 2024
import asyncio
import os
import time
import exoDeviceManager
import exoTrial
def cls():
os.system('cls' if os.name=='nt' else 'clear')
# Menu to calibrate the exo before begining trial.
# The current system does not rely on a user weight
# or a predefined torque. If you would like to futher
# modify this program to do so this is where it should
# be added in order to pass the data to the trial
# class.
def calibrationMenu():
isKilograms = True
weight = 1
isAssist = True
cls()
return isKilograms, weight, isAssist
#-----------------------------------------------------------------------------
# Menu for actions to take upon connection
def connectedMenu():
while True:
print("""-------------------------
|1. Start Trial |
-------------------------""")
option = int(input())
if option == 1:
return option
print("Choose a valid option")
# Display menu and return what is entered
def displayMenu():
while True:
print("""-------------------------
|1. Start Scan |
|2. End program |
-------------------------""")
option = int(input())
if option == 1 or option == 2:
return option
print("Choose a valid option")
#-----------------------------------------------------------------------------
# Start up menu for UI purposes (Has no affect on the program)
async def startUpMenu():
cls()
print("Starting Exoskeleton Controller Program...\n")
await asyncio.sleep(1)
#-----------------------------------------------------------------------------
async def main():
sleep_between_messages = 0.1
try:
# Initial display
await startUpMenu()
# Set up Menu
menuSelection = displayMenu()
await asyncio.sleep(sleep_between_messages)
# Run loop until end program is selected
while menuSelection != 2:
# Scan and connect to an Exo
deviceManager = exoDeviceManager.ExoDeviceManager()
await deviceManager.scanAndConnect()
# If connection is successful
if deviceManager.client.is_connected:
print("Connected!\n")
connectedMenuSelection = connectedMenu()
if connectedMenuSelection == 1:
cls()
isKilograms, weight, isAssistance = calibrationMenu()
trial = exoTrial.ExoTrial(isKilograms, weight, isAssistance)
await trial.calibrate(deviceManager) # Calibrate exo
await trial.beginTrial(deviceManager) # Start trial
await trial.systemUpdate(deviceManager) # Update exo system after trial begins
menuSelection = displayMenu() # show display menu once trial has ended
print("Shutting down...") # Shutdown
await asyncio.sleep(2)
cls()
except asyncio.CancelledError:
print("Main task was cancelled")
finally:
# Cleanup resources if needed
pass
#-----------------------------------------------------------------------------
if __name__ == "__main__":
asyncio.run(main())