Module: encoder

Executive Summary

Module that acts as an encoder to the reaction wheel speeds. It models both the discretization of the speed measurement, as well as signal status such as nominal, off and stuck.

Message Connection Descriptions

The following table lists all the module input and output messages. The module msg connection is set by the user from python. The msg type contains a link to the message structure definition, while the description provides information on what this message is used for.

Module I/O Messages

Msg Variable Name

Msg Type

Description

rwSpeedInMsg

RWSpeedMsgPayload

Input reaction wheel speed message.

rwSpeedOutMsg

RWSpeedMsgPayload

Output reaction wheel speed message.

Detailed Module Description

This module simulates two different encoder features: discretization and signal status. Discretization truncates the output reaction wheel speed to a set resolution. As for the signal status, it can be set as SIGNAL_NOMINAL for normal working conditions, but can also simulate failures of the type SIGNAL_OFF (output wheel speed is 0) and SIGNAL_STUCK (output wheel speed is constant and equal to the one given at the previous iteration).

This module applies each of its features to each wheel individually, and so it is important to set the number of reaction wheels in use. It is also important to note that, because for the first iteration the time step is set at 0, the wheel speeds will not be discretized for the first time step and the encoder will output the true wheel speeds.

Discretization

Under normal operating conditions, the discretizer works by setting the wheel speed as a multiple of the resolution of the sensor. This resolution is calculated through the number of clicks per rotation that the sensor can handle. Let \(N\) be the number of clicks measured during a time step:

\[N = \texttt{trunc}(\Omega_{\text{in}}\Delta t \frac{n}{2\pi} + \Delta N)\]

where \(\Omega_{\text{in}}\) is the input wheel speed, \(\Delta t\) is the time step, \(n\) is the number of clicks per rotation and \(\Delta N\) is the remaining clicks that were not accounted for in the previous iteration. The trunc() function truncates the result, effectively rounding down to the nearest integer. The output wheel speed \(\Omega_{\text{out}}\) is computed using the following equation:

\[\Omega_{\text{out}} = N\frac{2\pi}{n\Delta t}\]

The remaining clicks value is also updated as follows:

\[\Delta N = \Omega_{\text{in}}\Delta t \frac{n}{2\pi} + \Delta N - N\]

As expected, the smaller the value of \(n\), the greater the discretization errors will be. Also, the discretization will be more noticeable when the wheel speeds are close to 0.

Signal Status

The module accepts three different signal status, which are SIGNAL_NOMINAL, SIGNAL_OFF and SIGNAL_STUCK. When the signal is nominal, all the previous features apply and the wheel speeds are only affected by the discretization. When the signal is off, both the wheel speed and the remaining clicks are set to zero, which models a shutdown of the encoder. Finally, when the signal is stuck, all the variables remain constant from the previous iteration, including the wheel speeds and the remaining clicks.

Model Functions

The functions of the encoder model are:

  • Discretization: Discretizes the wheel speeds in terms of the given resolution.

  • Signal Status: Changes the output wheel speed depending on the encoder signal for each wheel.

Model Assumptions and Limitations

This code makes the following assumptions:

  • Wheel speed is constant for each time step: A simple Euler integration is used to compute the number of clicks.

  • All encoders precision are the same: The encoder module aplies the same resolution to each reaction wheel.

User Guide

This section contains conceptual overviews of the code and clear examples for the prospective user.

Module Setup

The encoder module is created in python using:

1wheelSpeedEncoder = encoder.Encoder()
2wheelSpeedEncoder.ModelTag = 'rwSpeedsEncoder'

A sample setup is done using:

1wheelSpeedEncoder.clicksPerRotation = 2048
2wheelSpeedEncoder.numRW = numRW

class Encoder : public SysModel
#include <encoder.h>

wheel speed encoder module class

Public Functions

Encoder()

This is the constructor for the module class. It sets default variable values and initializes the various parts of the model

~Encoder()

Module Destructor.

void Reset(uint64_t CurrentSimNanos)

This method is used to reset the module.

Returns:

void

void UpdateState(uint64_t CurrentSimNanos)

This method runs the encoder module in the sim.

void readInputMessages()

This method reads the speed input message

void writeOutputMessages(uint64_t CurrentClock)

This method writes encoded the wheel speed message.

Parameters:

CurrentClock – The clock time associated with the model call

Returns:

void

void encode(uint64_t CurrentSimNanos)

This method applies an encoder to the reaction wheel speeds.

Public Members

Message<RWSpeedMsgPayload> rwSpeedOutMsg

[rad/s] reaction wheel speed output message

ReadFunctor<RWSpeedMsgPayload> rwSpeedInMsg

[rad/s] reaction wheel speed input message

int rwSignalState[MAX_EFF_CNT]

vector of reaction wheel signal states

int clicksPerRotation

number of clicks per full rotation

int numRW

number of reaction wheels

BSKLogger bskLogger

&#8212; BSK Logging

Private Members

RWSpeedMsgPayload rwSpeedBuffer

reaction wheel speed buffer for internal calculations

RWSpeedMsgPayload rwSpeedConverted

reaction wheel speed buffer for converted values

double remainingClicks[MAX_EFF_CNT]

remaining clicks from the previous iteration

uint64_t prevTime

&#8212; Previous simulation time observed