scenarioAttitudePointingPy

Overview

This script showcases how to create a Python Basilisk module.

Demonstrates how to stabilize the attitude tumble without translational motion. This script sets up a 6-DOF spacecraft, but without specifying any orbital motion. Thus, this scenario simulates the spacecraft translating in deep space. The scenario is a version of scenarioAttitudePointing where the Module: mrpPD feedback control module is replaced with an equivalent python based BSK MRP PD control module.

The script is found in the folder basilisk/examples and executed by using:

python3 scenarioAttitudePointingPy.py

As with scenarioAttitudePointing, when the simulation completes 3 plots are shown for the MRP attitude history, the rate tracking errors, as well as the control torque vector.

The MRP PD control module in this script is a class called PythonMRPPD. Note that it has the same setup and update routines as are found with a C/C++ Basilisk module. These Python modules behave exactly as other C++/C modules: they respect their given priority and can run before C++/C modules.

Similarly to C++ modules, creating an instance of the Python module is done with the code:

pyMRPPD = PythonMRPPD()
pyMRPPD.ModelTag = "pyMRP_PD"
pyMRPPD.K = 3.5
pyMRPPD.P = 30.0
scSim.AddModelToTask(simTaskName, pyMRPPD)

Illustration of Simulation Results

show_plots = True

Here a small initial tumble is simulated. The resulting attitude and control torque histories are shown below. The spacecraft quickly regains a stable orientation without tumbling past 180 degrees.

../_images/scenarioAttitudePointingPy1.svg ../_images/scenarioAttitudePointingPy2.svg
class scenarioAttitudePointingPy.PythonMRPPD(*a, **kw)[source]

Bases: SysModel

This class inherits from the SysModel available in the Basilisk.architecture.sysModel module. The SysModel is the parent class which your Python BSK modules must inherit. The class uses the following virtual functions:

  1. Reset: The method that will initialize any persistent data in your model to a common “ready to run” state (e.g. filter states, integral control sums, etc).

  2. UpdateState: The method that will be called at the rate specified in the PythonTask that was created in the input file.

Additionally, your class should ensure that in the __init__ method, your call the super __init__ method for the class so that the base class’ constructor also gets called:

super(PythonMRPPD, self).__init__()

You class must implement the above four functions. Beyond these four functions you class can complete any other computations you need (Numpy, matplotlib, vision processing AI, whatever).

scenarioAttitudePointingPy.run(show_plots)[source]

The scenarios can be run with the followings setups parameters:

Parameters:

show_plots (bool) – Determines if the script should display plots