Skip to content

Commit 32bf679

Browse files
committed
Update active control example with new actuator class
1 parent f13f92a commit 32bf679

1 file changed

Lines changed: 25 additions & 42 deletions

File tree

docs/examples/halcyon_flight_sim_roll_throttle.ipynb renamed to docs/examples/halcyon_flight_sim_active_control.ipynb

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,11 @@
4444
" Accelerometer,\n",
4545
" Environment,\n",
4646
" Flight,\n",
47-
" Function,\n",
48-
" GnssReceiver,\n",
4947
" Gyroscope,\n",
5048
" Rocket,\n",
5149
")\n",
5250
"from rocketpy.motors import CylindricalTank, Fluid, HybridMotor\n",
5351
"from rocketpy.motors.tank import MassFlowRateBasedTank\n",
54-
"from rocketpy.tools import quaternions_to_spin\n",
5552
"\n",
5653
"plt.style.use(\"seaborn-v0_8-colorblind\")"
5754
]
@@ -284,30 +281,36 @@
284281
"outputs": [],
285282
"source": [
286283
"def tvc_controller_function(\n",
287-
" time, sampling_rate, state, state_history, observed_variables, tvc, sensors\n",
284+
" time,\n",
285+
" sampling_rate,\n",
286+
" state,\n",
287+
" state_history,\n",
288+
" observed_variables,\n",
289+
" thrust_vector_control,\n",
290+
" sensors,\n",
288291
"):\n",
289292
" # state = [x, y, z, vx, vy, vz, e0, e1, e2, e3, wx, wy, wz]\n",
290293
"\n",
291294
" # print(time)\n",
292295
"\n",
293-
" tvc.gimbal_angle_x = 0\n",
294-
" tvc.gimbal_angle_y = 0\n",
296+
" thrust_vector_control.gimbal_angle_x = 0\n",
297+
" thrust_vector_control.gimbal_angle_y = 0\n",
295298
" # Return variables of interest to be saved in the observed_variables list\n",
296299
" return (\n",
297300
" time,\n",
298-
" tvc.gimbal_angle_x,\n",
299-
" tvc.gimbal_angle_y,\n",
301+
" thrust_vector_control.gimbal_angle_x,\n",
302+
" thrust_vector_control.gimbal_angle_y,\n",
300303
" )\n",
301304
"\n",
302305
"\n",
303-
"tvc, tvc_controller = HALCYON.add_tvc(\n",
304-
" gimbal_range=10,\n",
306+
"thrust_vector_control, tvc_controller = HALCYON.add_thrust_vector_control(\n",
307+
" controller_function=tvc_controller_function,\n",
305308
" sampling_rate=100,\n",
309+
" max_gimbal_angle=10,\n",
306310
" gimbal_rate_limit=100,\n",
307-
" controller_function=tvc_controller_function,\n",
308311
" return_controller=True,\n",
309312
")\n",
310-
"tvc.info()\n",
313+
"thrust_vector_control.x.info()\n",
311314
"tvc_controller.info()"
312315
]
313316
},
@@ -380,10 +383,10 @@
380383
"\n",
381384
"\n",
382385
"roll_control, roll_controller = HALCYON.add_roll_control(\n",
383-
" max_roll_torque=10,\n",
384-
" sampling_rate=100,\n",
385-
" torque_rate_limit=100,\n",
386386
" controller_function=roll_controller_function,\n",
387+
" sampling_rate=100,\n",
388+
" max_roll_torque=10,\n",
389+
" torque_rate_limit=1000,\n",
387390
" return_controller=True,\n",
388391
")\n",
389392
"roll_control.info()\n",
@@ -417,28 +420,17 @@
417420
" time,\n",
418421
" throttle_command,\n",
419422
" throttle_actual,\n",
420-
" )"
421-
]
422-
},
423-
{
424-
"cell_type": "code",
425-
"execution_count": null,
426-
"metadata": {},
427-
"outputs": [],
428-
"source": [
423+
" )\n",
424+
"\n",
425+
"\n",
429426
"throttle_obj, throttle_controller = HALCYON.add_throttle_control(\n",
430427
" controller_function=throttle_controller_function,\n",
431428
" sampling_rate=100,\n",
432429
" throttle_range=(0.0, 1.0),\n",
433430
" throttle_rate_limit=100,\n",
434-
" actuator_tau=0.2,\n",
435-
" throttle=1.0,\n",
431+
" throttle_time_constant=0.5,\n",
436432
" return_controller=True,\n",
437-
" clamp=True,\n",
438-
")\n",
439-
"print(\"has add_throttle_control:\", hasattr(HALCYON, \"add_throttle_control\"))\n",
440-
"print(\"has throttle_control:\", hasattr(HALCYON, \"throttle_control\"))\n",
441-
"print(\"throttle_control:\", getattr(HALCYON, \"throttle_control\", None))"
433+
")"
442434
]
443435
},
444436
{
@@ -497,15 +489,6 @@
497489
"time1, ax, ay, az = zip(*accelerometer_clean.measured_data)\n",
498490
"time2, gx, gy, gz = zip(*gyro_clean.measured_data)\n",
499491
"\n",
500-
"# plt.plot(time1, ax, label=\"Accelerometer X\")\n",
501-
"# plt.plot(time1, ay, label=\"Accelerometer Y\")\n",
502-
"# plt.plot(time1, az, label=\"Accelerometer Z\")\n",
503-
"# plt.xlabel(\"Time (s)\")\n",
504-
"# plt.ylabel(\"Acceleration (m/s^2)\")\n",
505-
"# plt.legend()\n",
506-
"# plt.grid()\n",
507-
"# plt.show()\n",
508-
"\n",
509492
"plt.plot(time2, gx, label=\"Gyroscope X\")\n",
510493
"plt.plot(time2, gy, label=\"Gyroscope Y\")\n",
511494
"plt.plot(time2, gz, label=\"Gyroscope Z\")\n",
@@ -538,7 +521,7 @@
538521
],
539522
"metadata": {
540523
"kernelspec": {
541-
"display_name": ".venv (3.12.10)",
524+
"display_name": ".venv (3.14.3)",
542525
"language": "python",
543526
"name": "python3"
544527
},
@@ -552,7 +535,7 @@
552535
"name": "python",
553536
"nbconvert_exporter": "python",
554537
"pygments_lexer": "ipython3",
555-
"version": "3.12.10"
538+
"version": "3.14.3"
556539
}
557540
},
558541
"nbformat": 4,

0 commit comments

Comments
 (0)