@@ -90,8 +90,41 @@ def calc_f_x(self, xs, us, dt):
9090
9191 f_x = np .zeros ((pred_len , state_size , state_size ))
9292
93- f_x [:, 0 , 2 ] = - np .sin (xs [:, 2 ]) * us [:, 0 ]
94- f_x [:, 1 , 2 ] = np .cos (xs [:, 2 ]) * us [:, 0 ]
93+ # f_x_dot
94+ f_x [:, 0 , 1 ] = np .ones (pred_len )
95+ 96+ # f_theta
97+ tmp = ((self .mc + self .mp * np .sin (xs [:, 2 ])** 2 )** (- 2 )) \
98+ * self .mp * 2. * np .sin (xs [:, 2 ]) * np .cos (xs [:, 2 ])
99+ tmp2 = 1. / (self .mc + self .mp * (np .sin (xs [:, 2 ])** 2 ))
100+ 101+ f_x [:, 1 , 2 ] = - us [:, 0 ] * tmp \
102+ - tmp * (self .mp * np .sin (xs [:, 2 ]) \
103+ * (self .l * xs [:, 3 ]** 2 \
104+ + self .g * np .cos (xs [:, 2 ]))) \
105+ + tmp2 * (self .mp * np .cos (xs [:, 2 ]) * self .l \
106+ * xs [:, 3 ]** 2 \
107+ + self .mp * self .g * (np .cos (xs [:, 2 ])** 2 \
108+ - np .sin (xs [:, 2 ])** 2 ))
109+ f_x [:, 3 , 2 ] = - 1. / self .l * tmp \
110+ * (- us [:, 0 ] * np .cos (xs [:, 2 ]) \
111+ - self .mp * self .l * (xs [:, 3 ]** 2 ) \
112+ * np .cos (xs [:, 2 ]) * np .sin (xs [:, 2 ]) \
113+ - (self .mc + self .mp ) * self .g * np .sin (xs [:, 2 ])) \
114+ + 1. / self .l * tmp2 \
115+ * (us [:, 0 ] * np .sin (xs [:, 2 ]) \
116+ - self .mp * self .l * xs [:, 3 ]** 2 \
117+ * (np .cos (xs [:, 2 ])** 2 - np .sin (xs [:, 2 ])** 2 ) \
118+ - (self .mc + self .mp ) \
119+ * self .g * np .cos (xs [:, 2 ]))
120+ 121+ # f_theta_dot
122+ f_x [:, 1 , 3 ] = tmp2 * (self .mp * np .sin (xs [:, 2 ]) \
123+ * self .l * 2 * xs [:, 3 ])
124+ f_x [:, 2 , 3 ] = np .ones (pred_len )
125+ f_x [:, 3 , 3 ] = 1. / self .l * tmp2 \
126+ * (- 2. * self .mp * self .l * xs [:, 3 ] \
127+ * np .cos (xs [:, 2 ]) * np .sin (xs [:, 2 ]))
95128
96129 return f_x * dt + np .eye (state_size ) # to discrete form
97130
@@ -139,10 +172,7 @@ def calc_f_xx(self, xs, us, dt):
139172
140173 f_xx = np .zeros ((pred_len , state_size , state_size , state_size ))
141174
142- f_xx [:, 0 , 2 , 2 ] = - np .cos (xs [:, 2 ]) * us [:, 0 ]
143- f_xx [:, 1 , 2 , 2 ] = - np .sin (xs [:, 2 ]) * us [:, 0 ]
144- 145- return f_xx * dt
175+ raise NotImplementedError
146176
147177 def calc_f_ux (self , xs , us , dt ):
148178 """ hessian of model with respect to state and input in batch form
@@ -161,11 +191,8 @@ def calc_f_ux(self, xs, us, dt):
161191
162192 f_ux = np .zeros ((pred_len , state_size , input_size , state_size ))
163193
164- f_ux [:, 0 , 0 , 2 ] = - np .sin (xs [:, 2 ])
165- f_ux [:, 1 , 0 , 2 ] = np .cos (xs [:, 2 ])
194+ raise NotImplementedError
166195
167- return f_ux * dt
168- 169196 def calc_f_uu (self , xs , us , dt ):
170197 """ hessian of model with respect to input in batch form
171198
@@ -183,4 +210,4 @@ def calc_f_uu(self, xs, us, dt):
183210
184211 f_uu = np .zeros ((pred_len , state_size , input_size , input_size ))
185212
186- return f_uu * dt
213+ raise NotImplementedError
0 commit comments