scenarioAttitudePointingPy

Overview

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.

This script showcases the new way of creating Python modules. For the deprecated way, refer to scenarioAttitudePointingPyDEPRECATED.

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: Basilisk.architecture.sysModel.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).

Reset(CurrentSimNanos)[source]

The Reset method is used to clear out any persistent variables that need to get changed when a task is restarted. This method is typically only called once after selfInit/crossInit, but it should be written to allow the user to call it multiple times if necessary. :param CurrentSimNanos: current simulation time in nano-seconds :return: none

UpdateState(CurrentSimNanos)[source]

The updateState method is the cyclical worker method for a given Basilisk class. It will get called periodically at the rate specified in the task that the model is attached to. It persists and anything can be done inside of it. If you have realtime requirements though, be careful about how much processing you put into a Python UpdateState method. You could easily detonate your sim’s ability to run in realtime.

Parameters

CurrentSimNanos – current simulation time in nano-seconds

Returns

none

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