brace.Server.Core package

Submodules

brace.Server.Core.ComInterface module

class brace.Server.Core.ComInterface.IComInterface[source]

Bases: object

Generic interface for communications (both input and output) in relation to this framework.

abstractmethod isComOn() bool[source]

Returns a bool on whether the communication interface is active (and ready to send commands).

Returns:

bool representing active communication interface.

Return type:

bool

abstractmethod turnOnOffComm(enable: bool) bool[source]

Activates or deactivates this communication interface. Returns bool on whether or not it succeeded.

Parameters:

enable (bool) – True if interface should be active. False otherwise.

Returns:

Bool on whether or not a successful change of “active/inactive” has been made.

Return type:

bool

class brace.Server.Core.ComInterface.IInputCom[source]

Bases: IComInterface

Input Communications Interface. No methods are listed as it is the responsibility of the subclass to determine sensors (and how they relate to IMeasurementLists, which a list of these IInputComs). Up to the subclass to figure out what methods it needs to print out (and how it connects with the IMeasurementLists)

class brace.Server.Core.ComInterface.IOutputCom[source]

Bases: IComInterface

Output Communications interface responsible for handling how output is directed toward actuators or other device.

abstractmethod sendOutput(outputMsgData: bytes) None[source]

Sends commands to the output communications interface. outputMsgData is paired against the iterable containing IOutputComs.

Parameters:

outputMsgData (bytes) – The command to send to the output communications interface. Note that this is a single value sent to the output communication.

Returns:

None

Return type:

None

class brace.Server.Core.ComInterface.NullCom[source]

Bases: IInputCom, IOutputCom

Empty class that is used in the simulation for input and output communications.

isComOn() bool[source]

Returns a bool on whether the communication interface is active (and ready to send commands).

Returns:

bool representing active communication interface.

Return type:

bool

sendOutput(outputMsgData: bytes) None[source]

Sends commands to the output communications interface. outputMsgData is paired against the iterable containing IOutputComs.

Parameters:

outputMsgData (bytes) – The command to send to the output communications interface. Note that this is a single value sent to the output communication.

Returns:

None

Return type:

None

turnOnOffComm(enable: bool) bool[source]

Activates or deactivates this communication interface. Returns bool on whether or not it succeeded.

Parameters:

enable (bool) – True if interface should be active. False otherwise.

Returns:

Bool on whether or not a successful change of “active/inactive” has been made.

Return type:

bool

exception brace.Server.Core.ComInterface.UnexpectedInitializationError[source]

Bases: BaseException

Raised for issues when turnOnOffComm is attempted for turn on, but does not work.

brace.Server.Core.ControlLogic module

class brace.Server.Core.ControlLogic.IControlLogic(index: int)[source]

Bases: object

Interface for each control logic class that defines the discrete behavior to run. Each IControlLogic should have a DataClass which is a NamedTuple. </br> Notably, one of these attributes has to be t, which represents the time value for that particular datapoint. The other NamedTuple elements have to be positioned in the same order that the dataset lines were added in initial configuration of the subplots (and must follow row-major order. E.g. for a figure with subplots of size 5,2, starts with subplot 0,0; 0,1; 1,0; 1,1; 2,0; 2,1… 5,1).

DataClass: NamedTuple = None
abstractmethod exportMeasurementData(measurementLists: IMeasurementLists, index: int, isActive: bool) dict[str, float | int][source]

A function to format the data of the current RobotABC and related values of the logic controller. Should return a dictionary using the names in the NamedTuple that is assigned to this IControlLogic for message passing. A disabled RobotABC should return relevant data formatted as NaN to indicate that it is disabled. Data from all RobotABCs are collated together into a single NamedTuple.

Parameters:
  • measurementLists (IMeasurementLists) – The measurement list that is associated with this RobotABC (and logic controller).

  • index (int) – The current index of this RobotABC and logic controller (used for discerning the current RobotABC).

  • isActive (bool) – A flag to determine whether the RobotABC is “active”. Should return dictionaries with NaNs if inactive.

Returns:

A dictionary NamedTuple names and their respective values to be used in the datapoint.

Return type:

dict[str, float | int]

abstractmethod getConfigurationParameters(formatForConfiguration: bool) dict[str, float | dict][source]

Used for retrieving a subset of relevant parameters that may be modified in a ControlLogic. Should return a dictionary of a subset of values.

Parameters:

formatForConfiguration (bool) – A boolean that indicates whether or not the return configuration should be formatted for the data file configuration (e.g. dictionary with strings as keys instead of Enums, to preserve names). Should be true if for file (such as exported data trial configuration), false for regular GUI management.

Returns:

A dictionary of relevant values that are used by the ControlLogic (that may vary for each person).

Return type:

dict[str, float | dict]

abstractmethod getDesiredOutputValues(enable: bool, timeData: Iterable[float], deltaTime: float, currentCycleMeasurementLists: Iterable[IMeasurementLists]) Iterable[float][source]

Intended to run the entirety of the control logic for the particular controller type including any state change. Should return a parameter indicating numerical value that represents actuator movement (such as actuator position or torque).

Parameters:
  • enable (bool) – A flag to determine “active” (set to defaults otherwise). Will still run otherwise.

  • timeData (Iterable[float]) – An iterable of timesteps.

  • deltaTime (float) – The time between this current time step and the last one.

  • currentCycleMeasurementLists (Iterable[IMeasurementLists]) – An iterable of measurementLists. One leg may potentially use the measurements of another leg.

Returns:

An iterable of actuating values of one or more actuators (depending on how many are one leg).

Return type:

Iterable[float]

getRespectiveMeasurementList(currentCycleMeasurementList: Sequence[IMeasurementLists]) IMeasurementLists[source]

A helper method to get the respective measurement list for the leg it belongs to (assuming that measurements and legs are linked pairwise).

Parameters:

currentCycleMeasurementList (Sequence[IMeasurementLists]) – A container with MeasurementLists (all of the measurements).

Returns:

The current leg’s MeasurementList.

Return type:

IMeasurementLists

abstractmethod setParameters(parameters: dict[str, float]) None[source]

Used for modifying the parameters of a certain ControlLogic. Parameters are stored in dictionary format. Some input validation may be done at this step.

Parameters:

parameters (dict[str, float]) – Dictionary of key-value pairs that are used to update the instance variables used in the logic controller.

Returns:

None

Return type:

None

abstractmethod setup(**kwargs: dict[str, Any]) None[source]

To be run on the “first” time before any real measurements are performed. This includes having any placeholder values before execution.

Parameters:

kwargs (dict[str, Any]) – Dictionary pairing for any keywords in initialization.

Returns:

None

Return type:

None

abstractmethod simulatedSetup(**kwargs: dict[str, Any]) None[source]

To be run on the “first” time before any real measurements are performed, as run by simulator. This includes having any placeholder values before execution.

Parameters:

kwargs (dict[str, Any]) – Dictionary pairing for any keywords in initialization.

Returns:

None

Return type:

None

brace.Server.Core.MeasurementLists module

class brace.Server.Core.MeasurementLists.IMeasurementLists[source]

Bases: object

A container object that retains generic sensor data and output data. These datapoints are intended to be aligned in length with the time stored in RobotAssemblyABC. Thus specific control logic state should ideally be held in the IControlLogic class itself. The data stored in this container is passed as a parameter for IControlLogic and is used in exporting data for the iteration.

abstractmethod copyMeasurements(i: int, measurementDataFrameToCopy: DataFrame) None[source]

Used for copying measurements from one master list to the measurements for offline logic controller evaluation. This is done clockstep to clockstep with the integer i. All the relevant inputs should be copied, but leave out any outputs.

Parameters:
  • i (int) – the step at which a measurement is copied into this measurementList

  • measurementListToCopy (pandas.DataFrame) – A master dataframe by which to copy input measurements from.

Returns:

None

Return type:

None

abstractmethod recordOutputValues(outputDes: Iterable[float], outputIn: Iterable[float]) None[source]

The torque values before and after safety controls are passed in. This may be recorded into the measurement list. Otherwise, keep this as pass.

Parameters:
  • outputDes (Iterable[float]) – An iterable of one or more actual torque desired (if there is more than one actuator)

  • outputIn (Iterable[float]) – An iterable of one or more actual torque actuation values (if there is more than one actuator)

Returns:

None

Return type:

None

abstractmethod runMeasurements(deltaTimeAll: Iterable[float], inputComs: Iterable[IInputCom]) None[source]

Reads input measurements for a cycle using the input interfaces set at the RobotABC level. Should also perform any derived measurements.

Parameters:
  • deltaTimeAll (Iterable[float]) – an iterable containing the times between timesteps.

  • inputComs (Iterable[IInputCom]) – an iterable containing the input communciations interfaces for receiving measurements.

Returns:

None

Return type:

None

abstractmethod setCalibrationOffset(inputComs: Iterable[IInputCom]) None[source]

Zeroes the measurements at the current value by creating an offset. This may be done for some or all of the measurements.

Parameters:

inputComs (Iterable[IInputCom]) – An iterable of the input interfaces for getting input measurements.

Returns:

None

Return type:

None

abstractmethod setupMeasurements() None[source]

Runs the first iteration. Where values don’t have instantaneous meaning (like velocity), fill with 0s or NaNs.

Returns:

None

Return type:

None

abstractmethod simulateSetupMeasurements() None[source]
Runs the first iteration during a simulated run. Where values don’t have instantaneous meaning (like velocity),

fill with 0s or NaNs.

Returns:

None

Return type:

None

brace.Server.Core.RemoteProcedureCallHandler module

class brace.Server.Core.RemoteProcedureCallHandler.RemoteProcedureCallHandler(commandTopic: str = None)[source]

Bases: object

onMessage(client: Client, userdata, msg: MQTTMessage)[source]

The callback for when a PUBLISH message is received from the server, which places the command message to be served.

start(multiprocessingQueue: Queue) None[source]

Starts the asynchronous loop for reading MQTT messages. The relevant messages are written to the multiprocessingQueue to be used in RobotAssemblyABC to be executed before the next iteration is performed.

Params multiprocessingQueue:

Queue that holds pickled messages of RPC functions to call.

Returns:

None

Return type:

None

brace.Server.Core.RobotABC module

class brace.Server.Core.RobotABC.RobotABC(controlLogic: dict[IntEnum, Callable[[int], IControlLogic]], debugMode: bool, index: int, initialControlLogicType: IntEnum)[source]

Bases: object

A functional robotic set of input and output communications interfaces and safety control layers that behave under a set of control logic classes.

addInputComs(inputComs: Iterable[IInputCom]) None[source]

Add the input communications adapters. The ordering should be preserved, and thus should be used to distinguish interfaces.

Params inputComs:

A list of IInputCom objects that will be used in reading in sensor information.

Returns:

None

Return type:

None

addMeasurementList(measurementList: IMeasurementLists) None[source]

Add the measurement list as way of storing the data to be used in the logic controllers.

Params measurementList:

The IMeasurementList object that should be used to store this RobotABCs data.

Returns:

None

Return type:

None

addOutputComs(outputComs: Iterable[IOutputCom]) None[source]

Add the output communications adapters. The ordering is preserved, and thus should be used to enumerate with the data bytes for actuation.

Params outputComs:

A list of IOutputCom objects that will be used in actuation.

Returns:

None

Return type:

None

addSafetyControls(safetyControls: ISafetyControl) None[source]

Add safety control object to the RobotABC instance.

Params safetyControls:

The ISafetyControl object to be used on this RobotABC to constrain outputs and convert.

Returns:

None

Return type:

None

changeControlLogic(controlLogicType: IntEnum) None[source]

Changes the current control logic object based on the corresponding IntEnum from the controlLogicType.

Params controlLogicType:

The IntEnum in controlLogic dictionary that should be changed to.

Returns:

None

Return type:

None

changeControlLogicParameters(controlLogicType: IntEnum, parameters: dict[str, float | dict[str, float]]) None[source]

Calls the control logic object to change the parameters.

Params controlLogicType:

The IntEnum of the control logic class that should have their parameters changed.

Params parameters:

Dictionary of keywords and values to change the control logic parameters.

Returns:

None

Return type:

None

copyMeasurements(i: int, measurementDataFrameToCopy: DataFrame) IMeasurementLists[source]

Copies the measurement data (used in simulation) to this RobotABC’s IMeasurementLists.

Params i:

The index of this current control iteration.

Params measurementDataFrameToCopy:

The pandas Dataframe containing the relevant input data.

Returns:

The IMeasurementLists that was updated.

Return type:

IMeasurementLists

enableActuation(enable: bool) None[source]

Enables the actuation based on a boolean flag. Actuation values will still be calculated, but not performed.

Params enable:

Whether or not actuation should be enabled.

Returns:

None

Return type:

None

exportRobotData() tuple[NamedTuple, dict[str, float | int]][source]

Exports the data for the current control iteration, getting the assigned DataClass and the dictionary of data given by the control logic for the given control logic object.

Returns:

Tuple of the DataClass (NamedTuple type) and dictionary of relevant information.

Return type:

tuple[NamedTuple, dict[str, float | int]]

getConfigurationParameters(controlLogicType: IntEnum, formatForConfiguration: bool) dict[str, float | dict][source]

Gets the configuration parameters for a given control logic object. May format it for configuration file needs as necessary.

Params controlLogicType:

The IntEnum for the control logic object that should be received.

Params formatForConfiguration:

A boolean that indicates whether or not the return configuration should be formatted for the data file configuration (e.g. dictionary with strings as keys instead of Enums, to preserve names). Should be true if for file (such as exported data trial configuration), false for regular GUI management.

Returns:

None

Return type:

None

runCycle(timeAll: Iterable[float], deltaTimeAll: Iterable[float], currentCycleMeasurementLists: Iterable[IMeasurementLists]) None[source]

Runs the iteration cycle using the current IMeasurementLists and time data.

Params timeAll:

A list of times for the beginning of each iteration cycle.

Params deltaTimeAll:

A list of containing the amount of time in between each iteration cycle.

Params currentCycleMeasurementLists:

A list of IMeasurementLists (for each RobotABC for cross RobotABC dependencies)

that can be used for control. :type currentCycleMeasurementLists: Iterable[IMeasurementLists]

Returns:

None

Return type:

None

runMeasurements(deltaTimeAll: Iterable[float]) IMeasurementLists[source]

Runs the measurement collection for this cycle.

Params deltaTimeAll:

A list of floats that refers to the amount of time between control iterations.

Returns:

The IMeasurementList that was updated.

Return type:

IMeasurementLists

setCalibrationOffset() None[source]

Calls the IMeasurementLists to zero calibration offset values.

Returns:

None

Return type:

None

setup(**kwargs: dict[str, Any]) None[source]

Executes to initialize after the constructor, but just before the control iteration starts (transient state). Initializes the IMeasurementList.

Params kwargs:

Keyword arguments passed to controlLogic.

Returns:

None

Return type:

None

simulatedSetup(**kwargs) None[source]

Executes to initialize after the constructor, but just before the control iteration starts (transient state). Initializes the IMeasurementList. Specifically running the simulated setups of each.

Params kwargs:

Keyword arguments passed to controlLogic simulated setup.

Returns:

None

Return type:

None

turnOnOffRobot(enable: bool) bool[source]

Enables the RobotABC. The input and output interfaces are turned off. A failure to turn on the RobotABC disables the RobotABC.

Params enable:

Whether or not this RobotABC should be turned on or off.

Returns:

Whether or not enabling or disabling this RbbotABC was successful.

Return type:

bool

brace.Server.Core.RobotAssemblyABC module

class brace.Server.Core.RobotAssemblyABC.RobotAssemblyABC(initialControlLogicType: ~enum.IntEnum, numRobots: int, controlLogic: dict[~enum.IntEnum, ~typing.Callable[[int], ~brace.Server.Core.ControlLogic.IControlLogic]], UPDATE_RATE_PER_SECOND: int, startTime: ~multiprocessing.sharedctypes.Synchronized = None, robotImplementation: ~brace.Server.Core.RobotABC.RobotABC = <class 'brace.Server.Core.RobotABC.RobotABC'>, simulated: bool = False, dataTopicName: str = None, remoteHostTopicTemplate: str = None)[source]

Bases: IDataProducer

Class that handles overall control between RobotABC objects, reading into the IMeasurementLists, RPC requests, and data export.

IGNORED_EXPORT_API_CALLS = {'changeControlLogic', 'heartbeat'}
IGNORED_SIMULATED_API_CALLS = {'calibrateRobots', 'enableActuation', 'restartSharedStartTime', 'startSend'}
MAX_LEN = 15000
addSendDataEvent(sendData: Synchronized) None[source]

Binds additional multiprocessing events to be controlled by RobotAssemblyABC (to control when data is sent).

Parameters:

sendData (multiprocessing.Event) – Event in a while loop to dictate if data should be sent. This is to synchronize when data should be sent together with RobotAssemblyABC.

Returns:

None

Return type:

None

calibrateRobots() None[source]

Runs the calibration function in each RobotABC. This is often to zero each robot for relative sensor measurements.

Returns:

None

Return type:

None

changeControlLogic(controlLogicType: IntEnum) None[source]

Changes the logic controllers across all robots, exporting a terminating NaN datapoint if data is being sent.

Parameters:

controlLogicType – An integer enum that corresponds to the control logic from the controller logic

constructor dictionary, to be changed. :type controlLogicType: IntEnum :return: None :rtype: None

changeControlLogicParameters(controlLogicType: ~enum.IntEnum, parameters: dict[str, float | dict[slice(<enum 'IntEnum'>, <class 'float'>, None)]], index: int) None[source]

Requests in-place modification of the control logic parameters.

Parameters:
  • controlLogicType (IntEnum) – An integer enum that corresponds to the control logic to be changed.

  • parameters – The parameters that should be overridden (often through setattr, keys can be instance variable names).

Parameters are often floats, but may be state lookup tables for torque values. :type parameters: dict[str, float | dict[IntEnum: float]] :param index: Index of the RobotABC that should undergo the control logic parameter change with respect to this RobotAssemblyABC. :type index: int :return: None :rtype: None

changeMultipleControlLogicParameters(controlLogicType: ~enum.IntEnum, parameters: list[dict[str, float | dict[slice(<enum 'IntEnum'>, <class 'float'>, None)]]], index: list[int]) None[source]

Runs the same command as changeControlLogicParameters, except uses index aligned indicies and parameters; used to update in one cycle instead of issuing multiple commands.

Parameters:
  • controlLogicType (IntEnum) – An integer enum that corresponds to the control logic to be changed.

  • parameters (list[dict[str, float | dict[IntEnum: float]]]) – A list of parameter dictionaries that should be set for this controlLogicType

  • index (list[int]) – A list of indicies corresponding to the robots that are pairwise set to the parameters.

Returns:

None

Return type:

None

enableActuation(enable: bool) None[source]

By default, actuation is turned off and should be enabled through this RPC call. Changes the actuation enable flag for each RobotABC object.

Parameters:

enable – A flag which determines whether or not output actuation should be performed. If disabled, output calculation

is still performed, but no outputs are sent out to actuators. :type enable: bool :return: None :rtype: None

exportAPICallEvents() list[tuple[float, str, dict]][source]

Returns a list of tuples containing the uptime, RPC function name, and parameters that were sent. Function names that match names in IGNORED_EXPORT_API_CALLS are not included in this list.

Returns:

List of tuples containing RPC calls executed since the last shared start time restart.

Return type:

list[tuple[float, str, dict]]

exportNaNData(t: float) None[source]

This exports NaNs to the data topic for the current Data type. On graphs, when a NaN is drawn, the points in between the time value and the next valid time value will not plot anything (no line interpolation). This is helpful when switching between controllers should not yield valid data in between.

Parameters:

t (float) – The current time relative to the start time for the NaN data point to punctuate the data.

Returns:

None

Return type:

None

exportRecentData(force: bool = False) None[source]

Creates a NamedTuple object based on the data from the type and data from each Control Logic definition. Each field should be defined for the NamedTuple which is considered a flat object.

Parameters:

force (bool) – Flag to force the data to be published when passed to publishDatatoMqtt

Returns:

None

Return type:

None

getConfigurationParameters(controlLogicType: IntEnum, formatForConfiguration: bool) tuple[dict[str, float | int], ...][source]

Returns a set of configuration parameters defined by particular control logic. This may be used in two ways: for reading configuration into the GUI, or reading for export into a saved trial file. This returns a tuple of configuration parameters (of the same control logic) for each RobotABC that is defined.

Parameters:
  • controlLogicType (IntEnum) – The corresponding IntEnum defined for the control logic that should be exported.

  • formatForConfiguration – Flag where True formats should format objects as configuration for saved trial data. False

should be used for GUI configuration reading. :type formatForConfiguration: bool :return: Tuple containing configuration parameters for each RobotABC in this RobotAssemblyABC. :rtype: tuple[dict[str, float | int], …]

getRobot(index: int) RobotABC[source]

Helper function to retrieve a particular RobotABC indexed by number.

Parameters:

index (int) – Index of the RobotABC within this RobotAssemblyABC.

Returns:

The RobotABC indexed by the number

Return type:

RobotABC

heartbeat(syn: str) str | None[source]

Heartbeat pulse to check for alive connections between Client and Server. Returns “ACK” if and only if the initial response is “SYN”.

Parameters:

syn (str) – A synchronization string for the heartbeat command.

Returns:

An acknowledgement string to the synchronization string. None if not “SYN”

Return type:

str | None

publishDataToMqtt(force: bool = False) None[source]

Publishes a sequence of NamedTuple elements to the MQTT data topic. Elements are batched to reduce overhead at slight expense of viewing delay.

Parameters:

force (bool) – Forces the NameTuple buffer to be published. Such as when controllers change.

Returns:

None

Return type:

None

remoteCommand(functionName: str, argumentParameters: dict[str, Any]) Any[source]

Runs the RPC command received by the server, calling the function with the given parameters. This function will return any return values back to the Client through a separate client topic.

Params functionName:

The RPC function to call.

Params argumentParameters:

A dictionary that contains the parameters to run the function with.

Returns:

Return value of the executed command

Return type:

Any

restartSharedStartTime() None[source]

Restarts the synchronized start time shared between multiprocesses for data send. Datapoints should use this start time as a reference to offset future times with time.perf_counter(). Saved RPC calls are also cleared such that data trials only contain relevant calls since the restarted time.

Returns:

None

Return type:

None

setInputComInterface(inputComInterfaces: Iterable[Iterable[IInputCom]]) None[source]

Initializes the input interfaces that a RobotABC in this RobotAssemblyABC should use.

Parameters:

inputComInterfaces – Generally a list of lists containing IInputCom that defines pairwise

input interfaces to be used for each robot. Each RobotABC is assigned one list of IInputCom from this list of lists. :type inputComInterfaces: Iterable[Iterable[IInputCom]] :return: None :rtype: None

setMeasurementLists(measurementLists: Iterable[IMeasurementLists]) None[source]

Sets the MeasurementLists that a RobotABC in this RobotAssemblyABC should use.

Parameters:

measurementLists (Iterable[IMeasurementLists]) – Generally a list of IMeasurementLists subclasses that defines pairwise sensor data objects to be used for each robot. Each RobotABC is assigned one IMeasurementList from this list, representing the sensor data for that RobotABC.

Returns:

None

Return type:

None

setOutputComInterface(outputComInterfaces: Iterable[Iterable[IOutputCom]]) None[source]

Initializes the output interfaces that a RobotABC in this RobotAssemblyABC should use.

Parameters:

outputComInterfaces – Generally a list of lists containing IOutputCom that defines pairwise

input interfaces to be used for each robot. Each RobotABC is assigned one list of IOutputCom from this list of lists. :type outputComInterfaces: Iterable[Iterable[IOutputCom]] :return: None :rtype: None

setSafetyControl(safetyControls: Iterable[ISafetyControl]) None[source]

Initializes the ISafetyControl layer that a RobotABC in this RobotAssemblyABC should use.

Parameters:

safetyControls – Generally a list of ISafetyControl subclasses that defines the safety constraint behavior to be used for each robot. Each RobotABC is assigned one ISafetyControl from this list, representing the sensor data for that RobotABC.

Returns:

None

Return type:

None

setup(**kwargs) None[source]

A setup for things that should be performed before execution, but after the constructor init.

Params kwargs:

Parameters that should be passed to each RobotABC’s setup and potentially to control logic objects.

Returns:

None

Return type:

None

simulateControllerData(measurementDataFrames: list[DataFrame], eventPipeLine: DataFrame, **kwargs) Iterable[NamedTuple][source]

Function used to retest logic controllers against previously existing data (e.g. from a file). This makes it able to validate the controller without it physically having to put it on again. API functions may be called in between cycles. It is important that the measurements are kept as same (recalculating values within a window will change values due to values potentially not being available).

Params measurementDataFrames:

A list of pandas Dataframes referencing the data in the IMeasurementLists subclass that should be used in the controller simulation.

Params eventPipeLine:

A pandas Dataframe listing the uptime, name of the function called, and the parameter (stored as JSON) to be executed before each control iteration. RPC calls that are listed in IGNORED_SIMULATED_API_CALLS are ignored.

Params **kwargs**kwargs:

Other keyword arguments that should be passed to the simulatedSetup of RobotABC and the control logic objects.

Returns:

List of NamedTuple datatypes that are exported running new control logic or parameters to be graphed or saved.

Return type:

Iterable[NamedTuple]

start(timeSynchronizationCondition: Condition = None, **kwargs) None[source]

Starts the RobotAssemblyABC to run the RobotABCs, delegating control to downstream classes as necessary. Start times are synchronized and started, setup functions are executed. RPC commands are run, followed by execution of the control loop, followed by data export (when enabled).

Params timeSynchronizationCondition:

Condition that is passed to all IDataProducer start methods. The primary time synchronization

reseter notifies the other IDataProducers to continue execution (after waiting). None indicates that no shared condition is assigned between multiple IDataProducers. :type timeSynchronizationCondition: multiprocessing.Condition | None :params **kwargs: Keyword arguments that are passed through setup functions of RobotABCs and Control Logic objects.

Necessary kwargs elements are listed below.

Params sendEnd:

Shared queue between producer and consumer. NamedTuple datapoints are added to this queue.

Returns:

None

Return type:

None

startSend() None[source]

Sets all bounded Event synchronization flags to start the data streams together.

Returns:

None

Return type:

None

stopProcess() None[source]

Stops the RobotAssemblyABC start() loop to cleanly end.

Returns:

None

Return type:

None

stopSend() None[source]

Clears bounded send multiprocessing.Event flags to stop the data streams together.

Returns:

None

Return type:

None

turnOnOffControllerRobot(index: int, enable: bool) bool[source]

Enables/Disables the RobotABC from executing control logic and reading sensor data. Disabled RobotABCs still be accessed to retrieve filler NaN data to complete the NameTuple fields, however.

Params index:

Index of the RobotABC to be to be toggled.

Params enable:

Flag to enable or disable the indexed RobotABC

:type bool :return: Whether or not turning off the RobotABC was successful. :rtype: bool

brace.Server.Core.RobotHelpers module

This is a separate file for helper functions that have uses in both ControlLogic level and RobotABC level which correspond to a more specific vs global scope of parameters that would be used (e.g. RobotABC level enforces a maximum slew limit, while ControlLogic enforces a more local one depending on state).

class brace.Server.Core.RobotHelpers.HysteresisParameters(lambdaCondition: Callable[[float], bool], measurementCollection: Iterable[float], hysteresisTime: float)[source]

Bases: NamedTuple

HysteresisParameters are for evaluating all the values of a certain measurement (up to a certain hysteresisTime) back in time. In order for hysteresis to be considered true, all values have to return true when evaluated by the lambdaCondition. A successful hysteresis signals long enough stability to switch a state.

NamedTuple that contains

lambdaCondition - a callable that contains a float and returns a bool (for evaluating across all values in measurementCollection). measurementCollection - an iterable of floats in the measurementList that should be measured against. Values checked are paired with time iterable. hysteresisTime - the length of how long hysteresis should be checked for previous measurement values.

hysteresisTime: float

Alias for field number 2

lambdaCondition: Callable[[float], bool]

Alias for field number 0

measurementCollection: Iterable[float]

Alias for field number 1

brace.Server.Core.RobotHelpers.capTorqueFromAngle(torqueDes: float, currentAngle: float, extAngleLimit: float, flexAngleLimit: float) float[source]

Sets torque to 0 if beyond extension and flexion angle limits.

Params torqueDes:

The torque to use for this iteration cycle

Params currentAngle:

The current angle in this iteration cycle.

Params extAngleLimit:

The minimum angle limit before torque is set to 0.

Params flexAngleLimit:

The maximum angle limit before torque is set to 0.

Returns:

The adjusted torque after comparing between these limits.

Return type:

float

brace.Server.Core.RobotHelpers.checkSlewRate(torqueNow: float, torquePast: float, deltaTime: float, maxSlew: float) float[source]

Function that caps the slew rate of an output value of the current iteration to prevent excess changes in acceleration.

Parameters:
  • torqueNow (float) – The calculated output value before checks this iteration.

  • torquePast (float) – The output value used last iteration.

  • deltaTime (float) – The time between the last iteration and the current one in seconds.

  • maxSlew (float) – The maximum change between the two output values per second.

Returns:

The output value adjusted based on the max slew rate (capped if above limit).

Return type:

float

brace.Server.Core.RobotHelpers.hysteresis2(timeData: Iterable[float], functionConditions: HysteresisParameters) bool[source]

Returns whether or not a condition has been maintained for a desired time before a state is changed. This is performed by looking back in time.

Params timeData:

Time data that is stored in RobotAssemblyABC.

Params functionConditions:

A HysteresisParameters object that defines the conditions collection, and amount of time the condition must be satisfied before considered True.

Returns:

Whether or not the conditions have been satisifed for long enough.

Return type:

HysteresisParameters

brace.Server.Core.RobotHelpers.hysteresisMultiple(timeData: Iterable[float], functionConditions: list[HysteresisParameters]) bool[source]

Checks multiple hysteresis conditions to verify all conditions are true.

Params timeData:

Time data that is stored in RobotAssemblyABC

Params functionConditions:

A list of HysteresisParameters whose conditions should be checked.

Returns:

Whether or not all hysteresis conditions are satisfied.

Return type:

bool

brace.Server.Core.SafetyControl module

class brace.Server.Core.SafetyControl.ISafetyControl[source]

Bases: object

Layer that handles constraints for safety and conversions (bytestrings and other messages) for output actuators.

abstractmethod runOutputConversion(outputIn: Iterable[float]) Iterable[Any][source]

Translates the outputIn values to format accepted by the output communications interfaces.

Parameters:

outputIn (Iterable[float]) – An iterable containing the outputIn values from runSafetyControl

Returns:

An iterable containing the converted outputIn commands.

Return type:

Iterable[Any]

abstractmethod runSafetyControl(measurementLists: IMeasurementLists, deltaTimeAll: Iterable[float], outputDes: Iterable[float]) Iterable[float][source]

Runs safety control on the outputDes and returns out a list of outputs within safety boundaries.

Parameters:
  • measurementLists (IMeasurementLists) – MeasurementList for this leg (and safety check). May use this for determining safety parameters.

  • deltaTimeAll (Iterable[float]) – An iterable containing the times between timesteps.

  • outputDes (Iterable[float]) – An iterable returned from the ControlLogic for desired output values.

Returns:

An iterable of same size from outputDes containing altered outputDes values (called outputIn).

Return type:

Iterable[float]

Module contents