forked from AmeyaWagh/walking_model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkin_testing.py
executable file
·81 lines (68 loc) · 2.94 KB
/
kin_testing.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
# ------------------------------------------------------------------------------------------#
# This file reads angle data from test.csv and updates a subject model
# Plotter is used to draw the model using matplotlib
# Subject is a model class with all attributes of the lower exoskeleton
# Authors: Nathanial G
# Ameya Wagh - aywagh@wpi.edu
# ------------------------------------------------------------------------------------------#
from walking_model import Plotter
from walking_model import Subject
from walking_model.common import *
import numpy as np
import math
import os
import serial
PORT = '/dev/ttyACM0'
BAUDRATE = 250000
USE_SERIAL = False
plotter = Plotter.Plotter()
sub = Subject.Subject(MASS, HEIGHT)
plotter.update(sub)
if CONFIG_FILE["NEW_FORMAT"]:
joint_angle = read_csv2()
else:
joint_angle = read_csv()
steps = len(joint_angle[joint_angle.keys()[1]])
kg = KillGracefully()
if not USE_SERIAL:
while not kg.KILL_FLAG:
try:
for i in xrange(steps):
os.system('clear')
banner()
angles = np.array([-math.radians(joint_angle['Left.Knee.Angle'][i]),
math.radians(joint_angle['Left.Hip.Angle'][i]),
math.radians(joint_angle['Right.Hip.Angle'][i]),
-math.radians(joint_angle['Right.Knee.Angle'][i]),
math.radians(joint_angle['Right.Ankle.Angle'][i]),
math.radians(joint_angle['Left.Ankle.Angle'][i])], dtype=float)
sub.update(angles)
plotter.update(sub)
# time.sleep(.5)
# time.sleep(.005)
print sub.fixed
except KeyboardInterrupt:
print('KeyboardInterrupt')
close_all()
else:
print("using serial")
with serial.Serial(PORT, BAUDRATE, timeout=1) as ser:
print("reading...")
while True:
os.system('clear')
try:
line = ser.readline() # read a '\n' terminated line
data = [float(every_data) for every_data in line.split(',')[:-1]]
print(data)
banner()
angles = np.array([-math.radians(data[CALIBRATION['Left.Knee.Angle']['index']]),
math.radians(data[CALIBRATION['Left.Hip.Angle']['index']]),
math.radians(data[CALIBRATION['Right.Hip.Angle']['index']]),
-math.radians(data[CALIBRATION['Right.Knee.Angle']['index']]),
math.radians(data[CALIBRATION['Right.Ankle.Angle']['index']]),
math.radians(data[CALIBRATION['Left.Ankle.Angle']['index']])], dtype=float)
print(angles)
sub.update(angles)
plotter.update(sub)
except Exception as e:
pass