|
18 | 18 | },
|
19 | 19 | {
|
20 | 20 | "cell_type": "code",
|
21 |
| - "execution_count": 1, |
| 21 | + "execution_count": null, |
22 | 22 | "metadata": {},
|
23 | 23 | "outputs": [],
|
24 | 24 | "source": [
|
|
48 | 48 | },
|
49 | 49 | {
|
50 | 50 | "cell_type": "code",
|
51 |
| - "execution_count": 2, |
52 |
| - "metadata": {}, |
53 |
| - "outputs": [ |
54 |
| - { |
55 |
| - "name": "stdout", |
56 |
| - "output_type": "stream", |
57 |
| - "text": [ |
58 |
| - "observation space: \n", |
59 |
| - " Dict('difference_to_goal': Box(-inf, inf, (1, 3), float32), 'pos': Box(-inf, inf, (1, 3), float32), 'quat': Box(-inf, inf, (1, 4), float32), 'rpy_rates': Box(-inf, inf, (1, 3), float32), 'vel': Box(-inf, inf, (1, 3), float32))\n", |
60 |
| - "action space: \n", |
61 |
| - " Box([[ 0.11264675 -3.1415927 -3.1415927 -3.1415927 ]], [[0.5933658 3.1415927 3.1415927 3.1415927]], (1, 4), float32)\n", |
62 |
| - "time step: 0.002\n" |
63 |
| - ] |
64 |
| - } |
65 |
| - ], |
| 51 | + "execution_count": null, |
| 52 | + "metadata": {}, |
| 53 | + "outputs": [], |
66 | 54 | "source": [
|
67 | 55 | "# set config for simulation\n",
|
68 | 56 | "sim_config = config_dict.ConfigDict()\n",
|
69 | 57 | "sim_config.physics = Physics.sys_id\n",
|
70 | 58 | "sim_config.control = Control.attitude\n",
|
71 |
| - "sim_config.thrust_freq = 500\n", |
| 59 | + "sim_config.thrust_freq = 50\n", |
72 | 60 | "sim_config.device = \"cpu\"\n",
|
73 | 61 | "sim_config.n_drones = 1\n",
|
74 | 62 | "sim_config.n_worlds = 1 #20\n",
|
|
121 | 109 | },
|
122 | 110 | {
|
123 | 111 | "cell_type": "code",
|
124 |
| - "execution_count": 3, |
| 112 | + "execution_count": null, |
125 | 113 | "metadata": {},
|
126 | 114 | "outputs": [],
|
127 | 115 | "source": [
|
|
169 | 157 | },
|
170 | 158 | {
|
171 | 159 | "cell_type": "code",
|
172 |
| - "execution_count": 4, |
173 |
| - "metadata": {}, |
174 |
| - "outputs": [ |
175 |
| - { |
176 |
| - "name": "stdout", |
177 |
| - "output_type": "stream", |
178 |
| - "text": [ |
179 |
| - "A shape: (12, 12)\n", |
180 |
| - "B shape: (12, 4)\n", |
181 |
| - "A :\n", |
182 |
| - " [[ 0. 1. 0. 0. 0.\n", |
183 |
| - " 0. 0. 0. 0. 0.\n", |
184 |
| - " 0. 0. ]\n", |
185 |
| - " [ 0. 0. 0. 0. 0.\n", |
186 |
| - " 0. 0. 9.19147649 0. 0.\n", |
187 |
| - " 0. 0. ]\n", |
188 |
| - " [ 0. 0. 0. 1. 0.\n", |
189 |
| - " 0. 0. 0. 0. 0.\n", |
190 |
| - " 0. 0. ]\n", |
191 |
| - " [ 0. 0. 0. 0. 0.\n", |
192 |
| - " 0. -9.19147649 0. 0. 0.\n", |
193 |
| - " 0. 0. ]\n", |
194 |
| - " [ 0. 0. 0. 0. 0.\n", |
195 |
| - " 1. 0. 0. 0. 0.\n", |
196 |
| - " 0. 0. ]\n", |
197 |
| - " [ 0. 0. 0. 0. 0.\n", |
198 |
| - " 0. -0. -0. 0. 0.\n", |
199 |
| - " 0. 0. ]\n", |
200 |
| - " [ 0. 0. 0. 0. 0.\n", |
201 |
| - " 0. 0. 0. 0. 1.\n", |
202 |
| - " 0. 0. ]\n", |
203 |
| - " [ 0. 0. 0. 0. 0.\n", |
204 |
| - " 0. 0. 0. 0. 0.\n", |
205 |
| - " 1. 0. ]\n", |
206 |
| - " [ 0. 0. 0. 0. 0.\n", |
207 |
| - " 0. 0. 0. 0. 0.\n", |
208 |
| - " 0. 1. ]\n", |
209 |
| - " [ 0. 0. 0. 0. 0.\n", |
210 |
| - " 0. -130.3 0. 0. -16.33\n", |
211 |
| - " 0. 0. ]\n", |
212 |
| - " [ 0. 0. 0. 0. 0.\n", |
213 |
| - " 0. 0. -99.94 0. 0.\n", |
214 |
| - " -13.3 0. ]\n", |
215 |
| - " [ 0. 0. 0. 0. 0.\n", |
216 |
| - " 0. 0. 0. 0. 0.\n", |
217 |
| - " 0. 0. ]]\n", |
218 |
| - "B :\n", |
219 |
| - " [[ 0. 0. 0. 0. ]\n", |
220 |
| - " [ 0. 0. 0. 0. ]\n", |
221 |
| - " [ 0. 0. 0. 0. ]\n", |
222 |
| - " [ 0. 0. 0. 0. ]\n", |
223 |
| - " [ 0. 0. 0. 0. ]\n", |
224 |
| - " [ 20.90757426 0. 0. 0. ]\n", |
225 |
| - " [ 0. 0. 0. 0. ]\n", |
226 |
| - " [ 0. 0. 0. 0. ]\n", |
227 |
| - " [ 0. 0. 0. 0. ]\n", |
228 |
| - " [ 0. 119.3 0. 0. ]\n", |
229 |
| - " [ 0. 0. 84.73 0. ]\n", |
230 |
| - " [ 0. 0. 0. 0. ]]\n" |
231 |
| - ] |
232 |
| - } |
233 |
| - ], |
| 160 | + "execution_count": null, |
| 161 | + "metadata": {}, |
| 162 | + "outputs": [], |
234 | 163 | "source": [
|
235 | 164 | "dt = 1 / envs.sim.freq\n",
|
236 | 165 | "symbolic_model = symbolic(MASS, J, dt)\n",
|
|
343 | 272 | "outputs": [],
|
344 | 273 | "source": [
|
345 | 274 | "Ad, Bd = discretize_linear_system(A, B, dt) #, exact=True)\n",
|
346 |
| - "\n", |
| 275 | + "# print(\"A :\\n\", Ad)\n", |
| 276 | + "# print(\"B :\\n\", Bd)\n", |
347 | 277 | "P = scipy.linalg.solve_discrete_are(Ad, Bd, Q_lqr, R_lqr)\n",
|
348 | 278 | "\n",
|
349 | 279 | "btp = np.dot(Bd.T, P)\n",
|
|
353 | 283 | "\n",
|
354 | 284 | "# We can also comment out the above two lines of code \n",
|
355 | 285 | "# and use the following line instead to compute for the continuous-time case\n",
|
356 |
| - "\n", |
357 | 286 | "# P = scipy.linalg.solve_continuous_are(A, B, Q_lqr, R_lqr)\n",
|
358 |
| - "\n", |
359 | 287 | "# gain_lqr = np.dot(np.linalg.inv(R_lqr), np.dot(B.T, P))\n",
|
360 | 288 | "\n",
|
361 | 289 | "# print(\"A (discretized):\\n\", Ad)\n",
|
|
523 | 451 | "outputs": [],
|
524 | 452 | "source": [
|
525 | 453 | "x_d = np.array([0, 0, 5, 0, 1, 0, 0, 0, 0, 0, 0, 0]) # State equilibrium \n",
|
526 |
| - "u_d = np.ones(4, dtype=np.float32) * 0.25 * MASS * GRAVITY # Control equilibrium" |
| 454 | + "u_d = np.array([MASS * GRAVITY, 0.0, 0.0, 0.0], dtype=np.float32) # Control equilibrium" |
527 | 455 | ]
|
528 | 456 | },
|
529 | 457 | {
|
|
621 | 549 | " control_input = input_ff[:, step] + gains_fb[step].dot(state) \n",
|
622 | 550 | " \n",
|
623 | 551 | " # Clip the control input to the specified range\n",
|
624 |
| - " control_input = np.clip(control_input, 0.028161688, 0.14834145) \n", |
| 552 | + " control_input = np.clip(control_input, envs.action_space.low, envs.action_space.high) \n", |
625 | 553 | " \n",
|
626 | 554 | " # Convert to np.ndarray\n",
|
627 |
| - " action = np.array([control_input], dtype=np.float32) # (1, 4)\n", |
| 555 | + " action = control_input.reshape(1,4).astype(np.float32) # (1, 4)\n", |
628 | 556 | "\n",
|
629 | 557 | " # Save rollout data.\n",
|
630 | 558 | " if step == 0:\n",
|
|
0 commit comments