55
66class BipedalPlanner (object ):
77 def __init__ (self ):
8- self .footsteps = None
8+ self .ref_footsteps = None
99 self .g = 9.8
1010
11- def set_ref_footsteps (self , footsteps ):
12- self .ref_footsteps = footsteps
11+ def set_ref_footsteps (self , ref_footsteps ):
12+ self .ref_footsteps = ref_footsteps
1313
1414 def inverted_pendulum (self , x , x_dot , px_star , y , y_dot , py_star , z_c , time_width ):
1515 time_split = 100
@@ -35,13 +35,12 @@ def walk(self, T_sup=0.8, z_c=0.8, a=10, b=1, plot=False):
3535 return
3636
3737 self .com_trajectory = []
38- self .footsteps = []
3938 self .ref_p = []
4039 self .act_p = []
4140
4241 px , py = 0. , 0.
4342 px_star , py_star = px , py
44- xi , xi_dot , yi , yi_dot = 0. , 0. , 0.01 , 0. # TODO yi should be set as +epsilon
43+ xi , xi_dot , yi , yi_dot = 0. , 0. , 0.01 , 0. # TODO yi should be set as +epsilon, set xi, yi as COM
4544 time = 0.
4645 n = 0
4746 self .ref_p .append ([px , py , 0 ])
@@ -87,26 +86,29 @@ def walk(self, T_sup=0.8, z_c=0.8, a=10, b=1, plot=False):
8786 py_star = - a * (C - 1 ) / D * (yd - C * yi - T_c * S * yi_dot ) - b * S / (T_c * D ) * (yd_dot - S / T_c * yi - C * yi_dot )
8887 self .act_p .append ([px_star , py_star , f_theta ])
8988
90- self .footsteps .append ([px_star , py_star ])
91-
9289 if plot :
9390 fig = plt .figure ()
9491 ax = fig .subplots ()
9592 ax .set_xlim (0 , 1 )
9693 ax .set_ylim (- 0.1 , 0.2 + 0.1 )
9794 ax .set_aspect ('equal' , 'datalim' )
9895
99- ax .plot ([i [0 ] for i in self .footsteps ], [i [1 ] for i in self .footsteps ])
10096 ax .plot ([i [0 ] for i in self .com_trajectory ], [i [1 ] for i in self .com_trajectory ])
101-
97+
98+ foot_width = 0.06
99+ foot_height = 0.04
102100 for i in range (len (self .ref_p )):
103- rec = pat .Rectangle (xy = (self .ref_p [i ][0 ], self .ref_p [i ][1 ]), width = 0.06 , height = 0.04 , angle = self .ref_p [i ][2 ] * 180 / math .pi , color = "green" , fill = False , ls = ":" )
101+ angle = self .ref_p [i ][2 ] + math .atan2 (foot_height , foot_width ) - math .pi
102+ r = math .sqrt (math .pow (foot_width / 3. , 2 ) + math .pow (foot_height / 2. , 2 ))
103+ rec = pat .Rectangle (xy = (self .ref_p [i ][0 ] + r * math .cos (angle ), self .ref_p [i ][1 ] + r * math .sin (angle )),
104+ width = foot_width , height = foot_height , angle = self .ref_p [i ][2 ] * 180 / math .pi , color = "green" , fill = False , ls = ":" )
104105 ax .add_patch (rec )
105-
106106 for i in range (len (self .act_p )):
107- rec = pat .Rectangle (xy = (self .act_p [i ][0 ], self .act_p [i ][1 ]), width = 0.06 , height = 0.04 , angle = self .act_p [i ][2 ] * 180 / math .pi , color = "blue" , fill = False )
107+ angle = self .act_p [i ][2 ] + math .atan2 (foot_height , foot_width ) - math .pi
108+ r = math .sqrt (math .pow (foot_width / 3. , 2 ) + math .pow (foot_height / 2. , 2 ))
109+ rec = pat .Rectangle (xy = (self .act_p [i ][0 ] + r * math .cos (angle ), self .act_p [i ][1 ] + r * math .sin (angle )),
110+ width = foot_width , height = foot_height , angle = self .act_p [i ][2 ] * 180 / math .pi , color = "blue" , fill = False )
108111 ax .add_patch (rec )
109- print (len (self .ref_p ), len (self .act_p ))
110112
111113 plt .show ()
112114
0 commit comments