Skip to content

Commit

Permalink
Formatting clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
patkenneally committed Aug 13, 2024
1 parent 452e9d5 commit 7faf354
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 55 deletions.
15 changes: 7 additions & 8 deletions examples/BskSim/models/BSK_Dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ def __init__(self, SimBase, dynRate):
SimBase.AddModelToTask(self.taskName, self.thrustersDynamicEffectorACS, 302)
SimBase.AddModelToTask(self.taskName, self.thrustersDynamicEffectorDV, 303)
SimBase.AddModelToTask(self.taskName, self.extForceTorqueObject, 300)

SimBase.createNewEvent("addOneTimeRWFault", self.processTasksTimeStep, True,
["self.TotalSim.getCurrentNanos()>=self.oneTimeFaultTime and self.oneTimeRWFaultFlag==1"],
["self.DynModels.AddRWFault('friction',0.05,1, self.TotalSim.getCurrentNanos())", "self.oneTimeRWFaultFlag=0"])


SimBase.createNewEvent("addRepeatedRWFault", self.processTasksTimeStep, True,
["self.repeatRWFaultFlag==1"],
["self.DynModels.PeriodicRWFault(1./3000,'friction',0.005,1, self.TotalSim.getCurrentNanos())", "self.setEventActivity('addRepeatedRWFault',True)"])
Expand Down Expand Up @@ -170,7 +170,7 @@ def SetReactionWheelDynEffector(self):
gsHat,
maxMomentum=maxRWMomentum,
rWB_B=rwPosVector[0])

gsHat = (rbk.Mi(-rwAzimuthAngle[1], 3).dot(rbk.Mi(rwElAngle[1], 2))).dot(np.array([1, 0, 0]))
self.RW2 = self.rwFactory.create('Honeywell_HR16',
gsHat,
Expand All @@ -182,7 +182,7 @@ def SetReactionWheelDynEffector(self):
gsHat,
maxMomentum=maxRWMomentum,
rWB_B=rwPosVector[2])

gsHat = (rbk.Mi(-rwAzimuthAngle[3], 3).dot(rbk.Mi(rwElAngle[3], 2))).dot(np.array([1, 0, 0]))
self.RW4 = self.rwFactory.create('Honeywell_HR16',
gsHat,
Expand Down Expand Up @@ -302,9 +302,9 @@ def PeriodicRWFault(self, probability, faultType, fault, faultRW, currentTime):
"""
if np.random.uniform() < probability:
self.AddRWFault(faultType, fault, faultRW, currentTime)



def AddRWFault(self, faultType, fault, faultRW, currentTime):
"""
Adds a static friction fault to the reaction wheel.
Expand Down Expand Up @@ -337,4 +337,3 @@ def InitAllDynObjects(self):
self.SetReactionWheelDynEffector()
self.SetACSThrusterStateEffector()
self.SetDVThrusterStateEffector()

10 changes: 5 additions & 5 deletions examples/BskSim/scenarios/scenario_AddRWFault.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
This script demonstrates how to use event handlers to add reaction wheel faults. The script is found in the folder ``basilisk/examples/BskSim/scenarios`` and executed by using::
python3 scenario_AddRWFault.py
Using event handlers
--------------------
Expand Down Expand Up @@ -112,11 +112,11 @@ def __init__(self):

self.configure_initial_conditions()
self.log_outputs()

self.oneTimeRWFaultFlag = 1
self.repeatRWFaultFlag = 1
self.oneTimeFaultTime = macros.min2nano(10.)

DynModels = self.get_DynModel()
self.DynModels.RWFaultLog = []

Expand Down Expand Up @@ -166,7 +166,7 @@ def pull_outputs(self, showPlots):

sigma_BR = np.delete(attErrRec.sigma_BR, 0, 0)
omega_BR_B = np.delete(attErrRec.omega_BR_B, 0, 0)

num_RW = 4
RW_speeds = np.delete(self.rwSpeedRec.wheelSpeeds[:, range(num_RW)], 0, 0)
RW_friction = []
Expand Down Expand Up @@ -197,7 +197,7 @@ def runScenario(scenario):

simulationTime = macros.min2nano(30.)
scenario.modeRequest = "hillPoint"

# Run the simulation
scenario.InitializeSimulation()
scenario.ConfigureStopTime(simulationTime)
Expand Down
3 changes: 0 additions & 3 deletions src/architecture/system_model/sim_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,3 @@ uint64_t SimModel::getCurrentNanos() const {
uint64_t SimModel::getNextTaskTime() const {
return this->NextTaskTime;
}



2 changes: 1 addition & 1 deletion src/architecture/system_model/sim_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class SimModel
public:
SimModel(); //!< The SimModel constructor
~SimModel(); //!< SimModel destructorS

void selfInitSimulation(); //!< Method to initialize all added Tasks
void resetInitSimulation(); //!< Method to reset all added tasks
void StepUntilStop(uint64_t SimStopTime, int64_t stopPri); //!< Step simulation until stop time uint64_t reached
Expand Down
4 changes: 2 additions & 2 deletions src/architecture/system_model/sim_model.i
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace std {
SWIG_exception(SWIG_RuntimeError, e.what());
} catch (const std::string& e) {
SWIG_exception(SWIG_RuntimeError, e.c_str());
}
}
}

%include "sys_model_task.h"
Expand Down Expand Up @@ -129,4 +129,4 @@ namespace std {
)
return self.getPrevRouteTime()
%}
}
}
6 changes: 3 additions & 3 deletions src/architecture/system_model/sys_model_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void SysModelTask::SelfInitTaskList()
{
std::vector<ModelPriorityPair>::iterator ModelPair;
SysModel* NonIt;

//! - Loop over all models and do the self init for each
for(ModelPair = this->TaskModels.begin(); ModelPair != this->TaskModels.end();
ModelPair++)
Expand Down Expand Up @@ -95,7 +95,7 @@ void SysModelTask::ExecuteTaskList(uint64_t CurrentSimNanos)
{
std::vector<ModelPriorityPair>::iterator ModelPair;
SysModel* NonIt;

//! - Loop over all of the models in the simulation and call their UpdateState
for(ModelPair = this->TaskModels.begin(); (ModelPair != this->TaskModels.end() && this->taskActive);
ModelPair++)
Expand All @@ -118,7 +118,7 @@ void SysModelTask::AddNewObject(SysModel *NewModel, int32_t Priority)
{
std::vector<ModelPriorityPair>::iterator ModelPair;
ModelPriorityPair LocalPair;

//! - Set the local pair with the requested priority and mode
LocalPair.CurrentModelPriority = Priority;
LocalPair.ModelPtr = NewModel;
Expand Down
2 changes: 1 addition & 1 deletion src/architecture/system_model/sys_model_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ typedef struct {
//! Class used to group a set of models into one "Task" of execution
class SysModelTask
{

public:
SysModelTask();
SysModelTask(uint64_t InputPeriod, uint64_t FirstStartTime=0); //!< class method
Expand Down
2 changes: 1 addition & 1 deletion src/architecture/system_model/sys_model_task.i
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ namespace std {
)
self.setFirstTaskTime(value)
%}
}
}
9 changes: 4 additions & 5 deletions src/architecture/system_model/sys_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void SysProcess::singleStepNextTask(uint64_t currentNanos)
SysModelTask *localTask = fireIt->TaskPtr;
localTask->ExecuteTaskList(currentNanos);
fireIt->NextTaskStart = localTask->getNextStartTime();

//! - Figure out when we are going to be called next for scheduling purposes
fireIt=this->processTasks.begin();
//! - If the requested time does not meet our next start time, just return
Expand Down Expand Up @@ -207,7 +207,7 @@ void SysProcess::scheduleTask(ModelScheduleEntry & taskCall)
this->processTasks.push_back(taskCall);
}

/*! The name kind of says it all right? It is a shotgun used to disable all of
/*! The name kind of says it all right? It is a shotgun used to disable all of
a process' tasks. It is handy for a FSW scheme where you have tons of tasks
and you are really only turning one on at a time.
@return void
Expand All @@ -222,7 +222,7 @@ void SysProcess::disableAllTasks()
}
}
/*! The name kind of says it all right? It is a shotgun used to enable all of
a processes tasks. It is handy for a process that starts out almost entirely
a processes tasks. It is handy for a process that starts out almost entirely
inhibited but you want to turn it all on at once.
@return void
*/
Expand All @@ -236,7 +236,7 @@ void SysProcess::enableAllTasks()
}
}

/*! This method updates a specified task's period once it locates that task
/*! This method updates a specified task's period once it locates that task
in the list. It will warn the user if a task is not found.
@return void
@param taskName The name of the task you want to change period of
Expand All @@ -262,4 +262,3 @@ void SysProcess::changeTaskPeriod(std::string taskName, uint64_t newPeriod)
uint64_t SysProcess::getPrevRouteTime() const {
return this->prevRouteTime;
}

2 changes: 1 addition & 1 deletion src/architecture/system_model/sys_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef struct {
//! Class used to group a set of tasks into one process (task group) of execution
class SysProcess
{

public:
SysProcess();
SysProcess(std::string messageContainer); //!< class method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,4 +873,4 @@ def faultScenarios(show_plots):
# stateUpdateRWInertialAttitude(True)
# statePropRateInertialAttitude(True)
# faultScenarios(True)
all_inertial_kfTest(True)
all_inertial_kfTest(True)
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#
#
# ISC License
#
#
# Copyright (c) 2021, Autonomous Vehicle Systems Lab, University of Colorado Boulder
#
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
#
#
import copy
import itertools
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#
#
# ISC License
#
#
# Copyright (c) 2023, Autonomous Vehicle Systems Lab, University of Colorado Boulder
#
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
#
#

import copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,3 @@ def run(show_plots, offCount):
test_module(False, # show_plots
3 # offCount
)

Original file line number Diff line number Diff line change
Expand Up @@ -587,4 +587,4 @@ def unitSimIMU(show_plots, testCase, stopTime, procRate, gyroLSBIn
# stand-along python script
if __name__ == "__main__":
# unitSimIMU(True, 'noise', 1.0, 0.01, 0.0, 0.0, 1000., 1000., 0.0, 0.0, 0.0, 0.0, 0., 0., 1e-8)
unitSimIMU(False, 'noise', 1.0, 0.001, 0.0, 0.0, 1000., 1000., .1, .1, 0.1, 0.1, 0.0, 0.0, 1e-1)
unitSimIMU(False, 'noise', 1.0, 0.001, 0.0, 0.0, 1000., 1000., .1, .1, 0.1, 0.1, 0.0, 0.0, 1e-1)
24 changes: 12 additions & 12 deletions src/utilities/SimulationBaseClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def CreateNewTask(self, TaskName, TaskRate, InputDelay=None, FirstStart=0):

# When this method is removed, remember to delete the 'oldSyntaxVariableLog' and
# 'allModels' attributes (as well as any mention of them) as they are no longer needed
@deprecated.deprecated("2024/09/06",
@deprecated.deprecated("2024/09/06",
"Use the 'logger' function or 'PythonVariableLogger' instead of 'AddVariableForLogging'."
" See 'http://hanspeterschaub.info/basilisk/Learn/bskPrinciples/bskPrinciples-6.html'"
)
Expand All @@ -362,18 +362,18 @@ def AddVariableForLogging(self, VarName: str, LogPeriod: int = 0, *_, **__):
Args:
VarName (str): The variable to log in the format "<ModelTag>.<variable_name>"
LogPeriod (int, optional): The minimum time between logs. Defaults to 0.
"""
"""
if "." not in VarName:
raise ValueError('The variable to log must be given in the format '
'"<ModelTag>.<variable_name>"')

modelTag = VarName.split('.')[0]

# Calling eval on a pre-compiled string is faster than
# eval-ing the string (by a large factor)
compiledExpr = compile(VarName, "<logged-variable>", "eval")

# Find the model object that corresponds to the given tag, as well as the
# Find the model object that corresponds to the given tag, as well as the
# task where this model was added
modelOrConfig = task = None
for model, modelData, task in self.allModels:
Expand All @@ -388,7 +388,7 @@ def AddVariableForLogging(self, VarName: str, LogPeriod: int = 0, *_, **__):
# expression. We pass a dictionary '{modelTag: modelOrConfig}'
# that allows the expression to substitute the modelTag by the
# actual model object
def fun(_):
def fun(_):
val = eval(compiledExpr, globals(), {modelTag: modelOrConfig})
val = np.array(val).squeeze()
return val
Expand Down Expand Up @@ -423,7 +423,7 @@ def ConfigureStopTime(self, TimeStop):
"""
self.StopTime = TimeStop

@deprecated.deprecated("2024/09/06",
@deprecated.deprecated("2024/09/06",
"Calling 'RecordLogVars' is deprecated and unnecessary."
)
def RecordLogVars(self):
Expand Down Expand Up @@ -456,18 +456,18 @@ def ExecuteSimulation(self):
progressBar.markComplete()
progressBar.close()

@deprecated.deprecated("2024/09/06",
@deprecated.deprecated("2024/09/06",
"Deprecated way to access logged variables."
" See 'http://hanspeterschaub.info/basilisk/Learn/bskPrinciples/bskPrinciples-6.html'"
)
def GetLogVariableData(self, LogName):
"""
Pull the recorded module recorded variable. The first column is the variable recording time in
nano-seconds, the additional column(s) are the message data columns.
"""
"""
if LogName not in self.oldSyntaxVariableLog:
raise ValueError(f'"{LogName}" is not being logged. Check the spelling.')

logger = self.oldSyntaxVariableLog[LogName]
return np.column_stack([logger.times(), logger.variable])

Expand Down Expand Up @@ -581,10 +581,10 @@ def setModelDataWrap(self, modelData):
"\tscSim.AddModelToTask(simTaskName, inertial3D, 10)\n"
)
return modelData.createWrapper()

deprecated.deprecationWarn(
deprecationId,
removalDate,
deprecationId,
removalDate,
"This C module has not been converted yet to the new way of defining C "
"modules, which makes using them more intuitive. Take the time to see how "
"the new C module '.i' file looks by checking out a default Basilisk module"
Expand Down

0 comments on commit 7faf354

Please sign in to comment.