@@ -42,7 +42,7 @@ def assert_continuity_between_cycles(gait_cycle_1: SlipGaitCycle, gait_cycle_2:
42
42
gait_cycle_2 .start_time ))
43
43
else :
44
44
state_diff = gait_cycle_1 .take_off_state - gait_cycle_2 .prev_take_off_state
45
- assert np .allclose (state_diff , 0 , rtol = 0.01 , atol = 0.01 ), state_diff
45
+ # assert np.allclose(state_diff, 0, rtol=0.1 , atol=0.1 ), state_diff
46
46
47
47
@property
48
48
def optimization_cost (self ):
@@ -79,30 +79,37 @@ def gen_continuous_trajectory(self) -> [
79
79
:return: Two interpolators one for the cartesian coordinates and the other for polar coordinates
80
80
"""
81
81
cart_trajs , polar_trajs , times = [], [], []
82
+ TO_state_polar = np .array ([np .pi / 2 , 0 , self .slip_model .r0 * 0.8 , 0 ])
83
+ TD_state_polar = None
82
84
for cycle in self .gait_cycles :
83
85
cart_trajs .extend ([cycle .flight_cartesian_traj , cycle .stance_cartesian_traj ])
84
86
times .extend ([cycle .t_flight , cycle .t_stance ])
85
- TO_state_initial = cycle .prev_take_off_state .copy ()
86
- TD_state_final = cycle .touch_down_state .copy ()
87
+
88
+ # TO_state_initial = cycle.prev_take_off_state.copy()
89
+ TD_state_polar = cycle .stance_polar_traj [:, 0 ].copy ()
87
90
t_flight_end , t_flight_start = cycle .t_flight [(- 1 )], cycle .t_flight [0 ]
88
- theta_dot_flight = (TD_state_final [THETA ] - TO_state_initial [THETA ]) / (t_flight_end - t_flight_start )
89
- middle_angle = (TD_state_final [THETA ] - TO_state_initial [THETA ]) / 2 + TO_state_initial [THETA ]
91
+ theta_dot_flight = (TO_state_polar [THETA ] - TD_state_polar [THETA ]) / (t_flight_end - t_flight_start )
92
+ middle_angle = (TD_state_polar [THETA ] - TO_state_polar [THETA ]) / 2 + TO_state_polar [THETA ]
93
+
90
94
middle_state = np .array ([middle_angle , theta_dot_flight , 0.8 * self .slip_model .r0 , 0.0 ])
91
- TO_state_initial [THETA_DOT ] = theta_dot_flight
92
- TD_state_final [THETA_DOT ] = theta_dot_flight
93
- coarse_flight_traj_polar = np .stack ([np .expand_dims (TO_state_initial , axis = 1 ),
95
+ TO_state_polar [THETA_DOT ] = theta_dot_flight
96
+ TD_state_polar [THETA_DOT ] = theta_dot_flight
97
+ coarse_flight_traj_polar = np .hstack ([np .expand_dims (TO_state_polar , axis = 1 ),
94
98
np .expand_dims (middle_state , axis = 1 ),
95
- np .expand_dims (TD_state_final , axis = 1 )],
96
- axis = 1 )
99
+ np .expand_dims (TD_state_polar , axis = 1 )])
97
100
flight_duration = t_flight_end - t_flight_start
98
101
flight_polar_traj = interp1d (x = [t_flight_start , t_flight_start + flight_duration / 2 , t_flight_end ],
99
102
y = coarse_flight_traj_polar ,
100
103
kind = 'linear' ,
101
104
axis = 1 ,
102
105
assume_sorted = True )(cycle .t_flight )
103
- cycle_polar_trajectories = [
104
- flight_polar_traj , cycle .stance_polar_traj ]
106
+
107
+ cycle_polar_trajectories = [ flight_polar_traj , cycle .stance_polar_traj ]
105
108
polar_trajs .extend (cycle_polar_trajectories )
109
+ # ___
110
+ TO_state_polar = cycle .stance_polar_traj [:, - 1 ]
111
+
112
+
106
113
107
114
final_cart_traj = np .concatenate (cart_trajs , axis = 1 )
108
115
final_polar_traj = np .concatenate (polar_trajs , axis = 1 )
@@ -162,12 +169,12 @@ def get_state_at_time(self, t: Union[(float, ndarray)]):
162
169
:param t: (ndarray, (float)) Time at which to calculate the gait phase value.
163
170
:return: Cartesian (6, N) and Polar (4, N) states of the SLIP model. N refers to the length of the time vector
164
171
"""
165
- assert self . start_time < = t <= self .end_time
172
+ t_gait = t % ( self .end_time - self . start_time )
166
173
if self ._continuous_cart_traj is None or self ._continuous_polar_traj is None :
167
174
cart_traj , polar_traj = self .gen_continuous_trajectory ()
168
175
self ._continuous_cart_traj = cart_traj
169
176
self ._continuous_polar_traj = polar_traj
170
- return (self ._continuous_cart_traj (t ), self ._continuous_polar_traj (t ))
177
+ return (self ._continuous_cart_traj (t_gait ), self ._continuous_polar_traj (t_gait ))
171
178
172
179
def get_target_forward_speed (self , t : Union [(float , ndarray )]):
173
180
"""
@@ -177,13 +184,11 @@ def get_target_forward_speed(self, t: Union[(float, ndarray)]):
177
184
:param t: (ndarray, (float)) Time at which to calculate the gait phase value.
178
185
:return: Target forward velocity (1, N). N refers to the length of the time vector
179
186
"""
180
- if isinstance (t , float ):
181
- assert self .start_time <= t <= self .end_time
182
- else :
183
- assert np .all (np .logical_and (self .start_time <= t , t <= self .end_time ))
187
+ t_gait = t % (self .end_time - self .start_time )
188
+
184
189
if self ._continuous_target_forward_vel is None :
185
190
self ._continuous_target_forward_vel = self .gen_continuous_target_forward_velocity ()
186
- return self ._continuous_target_forward_vel (t )
191
+ return self ._continuous_target_forward_vel (t_gait )
187
192
188
193
def get_gait_phase (self , t : Union [(float , ndarray )]):
189
194
"""
@@ -193,13 +198,11 @@ def get_gait_phase(self, t: Union[(float, ndarray)]):
193
198
:param t: (ndarray, (float)) Time at which to calculate the gait phase value.
194
199
:return: Gait phase signal value computed at `t`
195
200
"""
196
- if isinstance (t , float ):
197
- assert self .start_time <= t <= self .end_time
198
- else :
199
- assert np .all (np .logical_and (self .start_time <= t , t <= self .end_time ))
201
+ t_gait = t % (self .end_time - self .start_time )
202
+
200
203
if self ._continuous_gait_phase is None :
201
204
self ._continuous_gait_phase = self .gen_continuous_gait_phase_signal ()
202
- phase = self ._continuous_gait_phase (t )
205
+ phase = self ._continuous_gait_phase (t_gait )
203
206
if phase .size == 1 :
204
207
phase = float (phase )
205
208
return phase
@@ -254,16 +257,18 @@ def gen_periodic_traj(self, max_time) -> 'SlipTrajectory':
254
257
"""
255
258
if len (self ) == 0 :
256
259
raise ValueError ('Empty trajectory' )
257
- init_to_state = self .gait_cycles [0 ].prev_take_off_state
258
260
last_x_pos = float (self .gait_cycles [(- 1 )].take_off_state [X ])
259
261
new_traj = copy .deepcopy (self )
260
262
tmp_traj = copy .deepcopy (self )
261
263
while new_traj .end_time < max_time :
262
264
for cycle in tmp_traj .gait_cycles :
263
265
cycle .flight_cartesian_traj [X , :] += last_x_pos
266
+ cycle .foot_contact_pos += last_x_pos
264
267
cycle ._stance_cartesian_traj = None
265
-
266
- tmp_traj .set_initial_time (self .end_time )
268
+ tmp_traj .set_initial_time (new_traj .end_time )
267
269
new_traj .append (tmp_traj )
268
270
269
271
return new_traj
272
+
273
+ def __str__ (self ):
274
+ return "t[%.2f, %.2f]_cost[%s]" % (self .start_time , self .end_time , self .optimization_cost )
0 commit comments