brace.example.exoskeleton package

Submodules

brace.example.exoskeleton.CANInterface2 module

class brace.example.exoskeleton.CANInterface2.CANInterface2(channel: int, canReaderQueue: Queue, kneeAngle: Synchronized, fsr: Synchronized, canEnable: Event)[source]

Bases: IInputCom, IOutputCom

The CAN input and output interface written for the Bionic Power Agilik actuators. This is used as both input and output, hence the multiple inheritance. This interface reads in the shared memory variables to get the measurements that are constantly read asynchronously on a separate CAN reading process for parallelization. It additionally writes any output CAN messages out to a queue that is read by the same CAN reading process to write actuator commands.

isComOn() bool[source]

Returns whether this interface is enabled (active).

Returns:

Whether or not the interface is on.

Return type:

bool

printEncoder() float[source]

Gets the knee angle value at this point in time, locking as necessary.

Returns:

Sampled knee angle value

Return type:

float

printFSR() float[source]

Gets the FSR value at this point in time, locking as necessary.

Returns:

Sampled FSR value

Return type:

float

sendOutput(outputMsgData: bytes) None[source]

Writes the output messages to the CAN processing queue for output actuation. Only written if the interface is active.

Parameters:

outputMsgData (bytes) – The CAN message to write to the actuator.

Returns:

None

Return type:

None

turnOnOffComm(enable: bool) bool[source]

Turns the communications interface as necessary for the communications. The flags for the process are also set and reset such that the CAN process does not asynchronously run.

Parameters:

enable (bool) – Whether the communications should be enabled or disabled.

Returns:

True (supposed to be successful or not)

Return type:

bool

brace.example.exoskeleton.ControlLogicLookup module

class brace.example.exoskeleton.ControlLogicLookup.ControlLogicEnum(*values)[source]

Bases: IntEnum

This IntEnum handles indexing for the control logic. Clients should reference these enums when sending RPC commands.

FSM5 = 0
PROPORTIONAL = 1
STANDING = 2

brace.example.exoskeleton.ExoController module

class brace.example.exoskeleton.ExoController.ExoController(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: RobotAssemblyABC

This class is a subclass of the stock defined RobotAssemblyABC. Custom RPC functions can be written to execute changes during runtime.

setControllerLegExtensionPositive(index: int, isExtensionPositive: bool) None[source]
Parameters:
  • index (int) – The index of the robot in the ExoController that should be changed.

  • isExtensionPositive (bool) – Whether extension should be considered positive, else flexion is positive.

Returns:

None

Return type:

None

brace.example.exoskeleton.ExoLeg module

class brace.example.exoskeleton.ExoLeg.ExoLeg(controlLogic: dict[IntEnum, Callable[[int], IControlLogic]], debugMode: bool, index: int, initialControlLogicType: IntEnum)[source]

Bases: RobotABC

This class is a subclass of the stock defined RobotABC. Custom RPC functions should be designed to forward function calls that may be received from the RobotAssemblyABC subclass.

setExtActuationConvention(extTorquePositive: bool) None[source]

RPC function that sets the torque convention of the actuator in the ISafetyControl layer.

Parameters:

extTorquePositive (bool) – Whether extension should defined as positive torque.

Returns:

None

Return type:

None

brace.example.exoskeleton.ExoMeasurementList module

class brace.example.exoskeleton.ExoMeasurementList.MeasurementLists[source]

Bases: IMeasurementLists

MeasurementLists for the exoskeleton. There are lists for knee angle, force, desired torque, corrected torque, the angular velocity, the window angular velocity. Data is recorded in these lists.

MAX_LEN = 15000
calculateWindowedAngularVelocity(inputComs: list[IInputCom], deltaTime: float) tuple[float, float][source]

Calculates the windowed angular velocity. Only runs if the input communication is available. Otherwise it is measured as 0 in the lists.

Parameters:
  • inputComs – List of input communications interfaces for gathering sensor information.

  • deltaTime (float) – The amount of time between control iterations.

Type:

inputComs: list[IInputCom]

Returns:

The tuple containing the angular and window angular velocity.

Return type:

tuple[float, float]

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

Copies the measurements from the pandas DataFrame to this MeasurementList This is particularly used in simulation, by simply placing the input values.

Consider the cases:
  • Normal data (non-NaN) -> means active exo leg replaying.

  • None object -> means data is not available, the exo leg was never on during the entire session.

  • NaN data -> means either exo leg was off at this time or we use this to denote that it switched controllers.
    • Currently you can’t switch exo legs on/off during a session (may change in the future).

    • Thus exo leg data being off would be represented by None object. NaN represents only switched controllers then.

Parameters:
  • i (int) – The iteration number that should be placed into the MeasurementList

  • measurementDataFrameToCopy (pandas.DataFrame) – The pandas DataFrame where data should be copied from.

Returns:

None

Return type:

None

getAngleMeasurements() deque[float][source]

Returns the deque of knee angle measurements. :return: Knee angle measurements :rtype: deque[float]

getAngularVelocityMeasurements() deque[float][source]

Returns the deque of angular velocity measurements. :return: Angular velocity measurements :rtype: deque[float]

getForceMeasurements() deque[float][source]

Returns the deque of FSR measurements. :return: FSR measurements :rtype: deque[float]

getTorqueDesiredMeasurements() deque[float][source]

Returns the deque of torque (pre-safety check) outputs. :return: Torque outputs (pre-safety check) :rtype: deque[float]

getTorqueInMeasurements() deque[float][source]

Returns the deque of torque (post-safety check) outputs. :return: Torque outputs (post-safety check) :rtype: deque[float]

getWindowedAngularVelocityMeasurements() deque[float][source]

Returns the windowed angular velocity measurements. :return: Windowed angular velocity measurements :rtype: deque[float]

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

Records the output values before and after safety checks to the MeasurementLists.

Parameters:
  • outputDes (list[float]) – The list of outputs before safety checks.

  • outputIn (list[float]) – The list of outputs after safety checks.

Returns:

None

Return type:

None

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

This evaluates the measurements from the angle encoder and FSR and copies it to the MeasurementList. Returns these values back so that they can be used in the other leg’s checks.

Parameters:
  • deltaTimeAll (list[float]) – The list of times in between control loop iterations.

  • inputComs (list[IInputComs]) – The list of input communications interfaces.

Returns:

None

Return type:

None

setCalibrationOffset(inputComs: list[IInputCom]) None[source]

Samples the calibration offset from the angle measurement. Future measurements are subtracted from this calibration offset. Calibration could also be sampled from previous n samples.

Parameters:

inputComs – The list of input communications interfaces that should be used

for gathering sensor information. :type inputComs: list[IInputCom] :return: None :rtype: None

setupMeasurements(inputComs: list[IInputCom]) None[source]

The initial setup for the measurements which creates the first set of measurements.

Parameters:

inputComs – The list of input communications interfaces that should be used

for gathering sensor information. :type inputComs: list[IInputCom] :return: None :rtype: None

simulateSetupMeasurements() None[source]

Separate function that initializes the measurements for the first set of measurements. These are just set to 0 to prevent off-by-one-errors.

Returns:

None

Return type:

None

brace.example.exoskeleton.ExoMeasurementList.calculateVelocity(angleMesAll: deque[float], deltaTime: float, deque: deque[float]) tuple[float, float][source]

Calculates the velocity for the knee angle measurements. Both angular velocity and the windowed angular velocity are determined.

Parameters:
  • angleMesAll (deque[float]) – The deque containing the knee angle measurements.

  • deltaTime (float) – The amount of time between the control iterations.

  • deque (deque[float]) – The deque containing the previous knee angle measurements in a window.

Returns:

The tuple containing the angular velocity and the windowed angular velocity.

Return type:

tuple[float, float]

brace.example.exoskeleton.ExoMeasurementList.windowedMovingAverage(deque: deque[float], angularVelocity: float) float[source]

” Calculates the angular velocity from the values of a deque. The values are cycled out automatically. This creates a low pass filter for the angular velocity.

Parameters:
  • deque (deque[float]) – A window that contains a few previous values.

  • angularVelocity (float) – The angular velocity for the current iteration.

Returns:

The windowed angular velocity for this current iteration.

Return type:

float

brace.example.exoskeleton.ServerSide module

brace.example.exoskeleton.ServerSide.handleException(excType, excValue, excTraceback)[source]
brace.example.exoskeleton.ServerSide.main()[source]

brace.example.exoskeleton.SlewSafetyChecks module

class brace.example.exoskeleton.SlewSafetyChecks.SlewSafetyChecks(extTorquePositive: bool, MAX_SLEW_RATE: float, MAX_FLEX_TORQUE: float, MAX_EXT_TORQUE: float)[source]

Bases: ISafetyControl

This layer handles safety control for the actuator by introducing a maximum slew rate to the torque, current deadzone, and capping of maximum torque.

runOutputConversion(outputIn: list[float]) list[bytes][source]

Converts the output values into a list of bytes that are to be written to the actuator. Practical conversions should be done in this case such as the convention sign change, forcing the dead zone current, and converting to a CAN message.

Parameters:

outputIn (list[float]) – List of outputs to be converted to CAN messages.

Returns:

list of CAN messages that should be sent to the actuators.

Return type:

list[byte]

runSafetyControl(measurementLists: MeasurementLists, deltaTimeAll: deque[float], outputDes: list[float]) list[float][source]

Runs safety control on the actuators (creating a slew rate and clipping the torque to maximum values) for each of the torque outputs.

Parameters:
  • measurementLists (MeasurementLists) – The measurementLists containing old data.

  • deltaTimeAll (deque[float]) – A list of the times between the control iterations.

  • outputDes (list[float]) – A list of outputs for the actuators to be checked.

Returns:

A list of corrected outputs for the actuators.

Return type:

list[float]

setExtActuationConvention(extTorquePositive: bool) None[source]

Used to flip the torque such that extension is positive or negative torque. May be ignored if extension is always negative torque (flexion positive). This is a fairly specific problem to the actuators that we have. This is not enforced as a method in the interface.

Parameters:

extTorquePositive (bool) – Flag to set to reverse the direction of actuation.

Returns:

None

Return type:

None

brace.example.exoskeleton.SlewSafetyChecks.capTorque(torqueIn: float, torqueMinValue: float, torqueMaxValue: float) float[source]

Retains the torque within a specific minimum and maximum value.

Parameters:
  • torqueIn (float) – The desired amount of torque.

  • torqueMinValue (float) – The most negative torque value possible by the actuator (maximum torque in one direction).

  • torqueMaxValue – The most positive torque value possible by the actuator (maximum torque in other direction).

Returns:

The capped torque within these values.

Return type:

float

brace.example.exoskeleton.SlewSafetyChecks.convertTorqueConventionSign(extTorquePositive: bool, torqueIn: float) float[source]

Changes the sign of the torque convention (flexion positive vs extension positive).

Parameters:
  • extTorquePositive (bool) – Whether extension is considered positive, otherwise flexion is considered positive.

  • torqueIn (float) – The torque that should have its sign potentially changed.

Returns:

The corrected torque value according to the actuator.

Return type:

float

brace.example.exoskeleton.SlewSafetyChecks.forceCurrentDeadZone(commandCurrent: float) float[source]

Forces the current to 0 if less than 0.020 mA.

Parameters:

commandCurrent (float) – The current in mA to be sent to the actuator.

Returns:

The current after checks.

Return type:

float

brace.example.exoskeleton.SlewSafetyChecks.torqueToCurrent(desTorque: float) float[source]

Converts the desired torque (Nm) into a current value (mA) determined by Bionic Power’s characteristic curve.

Parameters:

desTorque (float) – The amount of torque that should be sent to the actuator.

Returns:

The amount of converted current to be used by the actuator.

Return type:

float

brace.example.exoskeleton.mainGUI module

brace.example.exoskeleton.mainGUI.handleException(excType, excValue, excTraceback)[source]
brace.example.exoskeleton.mainGUI.main()[source]

Module contents