-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw_traj.py
115 lines (81 loc) · 2.88 KB
/
draw_traj.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
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
108
109
110
111
112
113
114
115
import numpy as np
import matplotlib.pyplot as plt
from BezierCurve import BezierCurveMaker
from StanceCurve import StanceCurveMaker
class TrajMaker(object):
def __init__(self, swing_len, points, stance_len, delta, L, z_offset):
super().__init__()
self.swing_len = swing_len
self.points = points
self.stance_len = stance_len
self.delta = delta
self.L = L
self.z_offset = z_offset
# Bezier Curve Maker
self.bc_maker = BezierCurveMaker(len(points) - 1, points)
# Stance Curve Maker
self.sc_maker = StanceCurveMaker(delta=self.delta, L=self.L)
def calcBezierCurve(self, z_offset=0):
sample_points = np.linspace(0, 1, self.swing_len)
traj_points = []
for t in sample_points:
my_point = self.bc_maker.getBezierPoint(t)
my_point[1] += self.z_offset
traj_points.append(my_point)
return traj_points
def calcStanceCurve(self, z_offset=0):
sample_points = np.linspace(0, 1, self.stance_len)
traj_points = []
for t in sample_points:
my_point = self.sc_maker.stanceCurve(t)
my_point[1] += self.z_offset
traj_points.append(my_point)
return traj_points
def getTrajPoints(self, z_offset=0):
traj_points = []
traj_points += self.calcBezierCurve(z_offset)
traj_points += self.calcStanceCurve(z_offset)
return traj_points
def get3DTrajPoints(self, y_offset=0, z_offset=0, phase=1):
traj_points = []
bezier_traj_3d = []
stance_traj_3d = []
for bezier_point in self.calcBezierCurve(z_offset):
bezier_traj_3d.append([bezier_point[0], y_offset, bezier_point[1]])
for stance_point in self.calcStanceCurve(z_offset):
stance_traj_3d.append([stance_point[0], y_offset, stance_point[1]])
if phase == 1:
traj_points += bezier_traj_3d
traj_points += stance_traj_3d
elif phase ==2:
traj_points += stance_traj_3d
traj_points += bezier_traj_3d
return traj_points
if __name__=="__main__":
points = [
[-0.1, 0],
[-0.1, 0.05],
[-0.1, 0.1],
[0.1, 0.1],
[0.1, 0.05],
[0.1, 0],
]
num_sample = 25
sample_points = np.linspace(0, 1, num_sample)
# Attaching 3D axis to the figure
# referenced from https://wikidocs.net/14604
fig = plt.figure()
ax = fig.subplots()
traj_maker = TrajMaker(
swing_len=25, points=points,
stance_len=25, delta=0.02, L=0.2,
z_offset=-0
)
traj_points = traj_maker.getTrajPoints()
for p in traj_points:
ax.plot(p[0], p[1],'r-*',lw=1)
# # X and Y swap
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.axis([-0.2, 0.2, -0.1, 0.2])
plt.show()