Command Documentation (v1.4.0)
This document provides comprehensive descriptions of all commands available in the system, along with their associated codes, detailed descriptions, properties, and response objects where applicable. Each section is categorized for easy reference.
Table of Contents
Motor Commands
INITIALIZE_MOTOR
- Code:
0x01 - Description: The
INITIALIZE_MOTORcommand is used to initialize a specific motor on the system, preparing it for operation. This involves setting up the motor's internal state and configuration, allowing it to respond to subsequent control commands. This command must be executed before any other motor-related commands to ensure proper functionality. - Category: Motor
- Properties:
motor_index(uint8_t): The index of the motor to initialize. Valid values range from 0 to 3, where each number corresponds to a different motor.is_reversed(bool): This property determines whether the motor's rotation direction should be reversed. By default, this is set tofalse, meaning the motor will rotate in the standard direction.
SET_MOTOR_SPEED
- Code:
0x02 - Description: The
SET_MOTOR_SPEEDcommand allows you to control the speed of a specified motor by providing a PWM (Pulse Width Modulation) value. This command directly influences the motor's output speed and direction, based on the PWM value provided. A positive value will spin the motor forward, while a negative value will reverse its direction. - Category: Motor
- Properties:
motor_index(uint8_t): Identifies which motor (from 0 to 3) you want to set the speed for.pwm(double): The PWM value that controls the motor speed. The value ranges from -100.0 to 100.0, where -100.0 represents full speed in reverse, 0 stops the motor, and 100.0 represents full speed forward.
STOP_MOTOR
- Code:
0x03 - Description: The
STOP_MOTORcommand is designed to immediately halt the specified motor by setting its speed to zero. This command is essential in situations where you need to stop motor movement quickly and safely, ensuring the motor remains stationary until further commands are issued. - Category: Motor
- Properties:
motor_index(uint8_t): Specifies the motor that should be stopped. The value ranges from 0 to 3.
BRAKE_MOTOR
- Code:
0x04 - Description: The
BRAKE_MOTORcommand activates the braking mechanism for the specified motor, which helps to bring the motor to a stop more rapidly than simply setting the speed to zero. This command is particularly useful in applications where precise stopping is critical, such as in robotics or automated machinery. - Category: Motor
- Properties:
motor_index(uint8_t): Identifies which motor to brake. The value ranges from 0 to 3.
Motor Controller Commands
INITIALIZE_MOTOR_CONTROLLER
- Code:
0x05 - Description: The
INITIALIZE_MOTOR_CONTROLLERcommand configures and initializes the motor controller for a specific motor. This command is crucial for enabling closed-loop control, where the motor's speed and position can be precisely managed using feedback from an encoder. The setup includes specifying the encoder to use, tuning the PID control constants, and setting limits on the controller's operation. - Category: Motor Controller
- Properties:
motor_index(uint8_t): Identifies the motor to be controlled. Valid range is 0 to 3.is_reversed(bool): Determines if the motor's direction should be inverted. Default isfalse.encoder_index(uint8_t): Selects the encoder associated with the motor. Range is 0 to 3.is_encoder_reversed(bool): Determines if the encoder's counting direction is inverted, independently ofis_reversed. Set this so that a positive commanded speed produces a positive measured speed (i.e. negative feedback). Default isfalse.encoder_resolution(double): Sets the resolution of the encoder in ticks per revolution. This value cannot be negative or zero.kp(double): The proportional constant of the PID controller, influencing how much the motor's output will change in response to a given error.ki(double): The integral constant of the PID controller, which helps to eliminate steady-state error by considering the cumulative sum of errors over time.kd(double): The derivative constant of the PID controller, which predicts future error based on its rate of change, helping to dampen the response.integral_limit(double): The maximum allowable integral value to prevent wind-up. If set to zero or negative, the integral part of the PID is effectively disabled.
SET_MOTOR_TARGET_SPEED
- Code:
0x06 - Description: The
SET_MOTOR_TARGET_SPEEDcommand is used to set the target rotational speed for a motor in radians per second. This command is particularly useful when precise control of motor speed is required, as it works in conjunction with the motor controller to maintain the specified speed despite changes in load or other variables. - Category: Motor Controller
- Properties:
motor_index(uint8_t): Specifies the motor for which the target speed should be set. Valid values range from 0 to 3.speed(double): The target speed in radians per second.
RESET_MOTOR_CONTROLLER
- Code:
0x07 - Description: The
RESET_MOTOR_CONTROLLERcommand resets the state of the motor controller associated with a specific motor. This command is useful for reinitializing the controller, clearing any errors, or returning it to a known state before reconfiguring or restarting the motor operation. - Category: Motor Controller
- Properties:
motor_index(uint8_t): Identifies which motor's controller to reset. Valid range is 0 to 3.
GET_MOTOR_CONTROLLER_STATE
- Code:
0x08 - Description: The
GET_MOTOR_CONTROLLER_STATEcommand retrieves the current state of the motor controller for a specified motor. This includes all relevant parameters such as PID constants, target speed, current speed, error, and output. This command is essential for monitoring the performance and status of the motor controller in real-time. - Category: Motor Controller
- Properties:
motor_index(uint8_t): Specifies the motor for which the controller state should be retrieved. Valid range is 0 to 3.
- Response:
motor_controller_state(object): An object containing detailed information about the current state of the motor controller, including PID constants, target speed, and current speed.
DELETE_MOTOR_CONTROLLER
- Code:
0x09 - Description: The
DELETE_MOTOR_CONTROLLERcommand removes the motor controller configuration for a specified motor. This effectively disables the controller, reverting the motor to manual control mode. Use this command when you no longer require closed-loop control for a motor. - Category: Motor Controller
- Properties:
motor_index(uint8_t): Identifies which motor's controller to delete. Valid range is 0 to 3.
SET_CONTROLLER_FREQUENCY
- Code:
0x0A - Description: The
SET_CONTROLLER_FREQUENCYcommand sets the global update frequency (in Hz) of the closed-loop motor controller task. All motor controllers share a single control loop, so this frequency is global and affects every running controller as well as any created afterwards; the PID sampling time is updated to match. The requested value is clamped to the supported range of 1 to 1000 Hz (the 1000 Hz maximum is bounded by the 1 ms RTOS tick) and quantized to whole milliseconds (period_ms = 1000 / frequency), so effective frequencies are 1000/N Hz. A value of 0 is invalid and ignored. Defaults to 10 Hz (100 ms) at start-up. - Category: Motor Controller
- Properties:
frequency(uint16_t): The controller update frequency in Hz. Valid range 1 to 1000 Hz; values outside are clamped, and 0 is ignored.
GET_CONTROLLER_FREQUENCY
- Code:
0x0B - Description: The
GET_CONTROLLER_FREQUENCYcommand retrieves the current global update frequency (in Hz) of the closed-loop motor controller task. - Category: Motor Controller
- Response:
frequency(uint16_t): The current controller update frequency in Hz (1 to 1000 Hz).
Encoder Commands
INITIALIZE_ENCODER
- Code:
0x11 - Description: The
INITIALIZE_ENCODERcommand sets up an encoder for use, configuring it with the appropriate resolution and direction. This command is a prerequisite for any operations that rely on encoder feedback, such as motor control or odometry calculations. - Category: Encoder
- Properties:
encoder_index(uint8_t): Specifies the encoder to initialize. Valid range is 0 to 3.encoder_resolution(double): Sets the resolution of the encoder in ticks per revolution. The value must be positive.is_reversed(bool): Determines if the encoder's direction is inverted. Default isfalse.
GET_ENCODER_VALUE
- Code:
0x12 - Description: The
GET_ENCODER_VALUEcommand retrieves the current value of the encoder, typically representing the number of ticks counted since the last reset or initialization. This value is crucial for determining the position or distance traveled by a motor or platform. - Category: Encoder
- Properties:
encoder_index(uint8_t): Specifies the encoder from which to retrieve the value. Valid range is 0 to 3.
- Response:
encoderValue(uint16_t): The current tick count of the encoder, representing its current position.
START_ENCODER_ODOMETRY
- Code:
0x13 - Description: The
START_ENCODER_ODOMETRYcommand begins the calculation of odometry data based on the encoder's readings. This is essential for tracking the movement and position of a robot or platform in relation to its starting point. - Category: Encoder
- Properties:
encoder_index(uint8_t): Identifies the encoder for which to start odometry calculations. Valid range is 0 to 3.
RESET_ENCODER_ODOMETRY
- Code:
0x14 - Description: The
RESET_ENCODER_ODOMETRYcommand resets the odometry calculations for a specific encoder, effectively setting the current position to zero. This command is useful when recalibrating or re-zeroing the position of a platform or motor. - Category: Encoder
- Properties:
encoder_index(uint8_t): Identifies the encoder for which to reset odometry. Valid range is 0 to 3.
STOP_ENCODER_ODOMETRY
- Code:
0x15 - Description: The
STOP_ENCODER_ODOMETRYcommand halts the ongoing odometry calculations for a specified encoder. Use this command when odometry data is no longer needed or before reconfiguring the encoder. - Category: Encoder
- Properties:
encoder_index(uint8_t): Identifies the encoder for which to stop odometry calculations. Valid range is 0 to 3.
GET_ENCODER_ODOMETRY
- Code:
0x16 - Description: The
GET_ENCODER_ODOMETRYcommand retrieves the current odometry data for the specified encoder, providing information on the distance traveled or position in radians. This is critical for applications requiring precise movement tracking. - Category: Encoder
- Properties:
encoder_index(uint8_t): Specifies the encoder from which to retrieve the odometry data. Valid range is 0 to 3.
- Response:
odometry(double): The current odometry value in radians, indicating the rotation or position tracked by the encoder.
SET_ODOMETRY_FREQUENCY
- Code:
0x17 - Description: The
SET_ODOMETRY_FREQUENCYcommand sets the global update frequency (in Hz) of the odometry task. A single odometry task integrates all encoder and platform odometry, so this frequency is global. The requested value is clamped to the supported range of 1 to 1000 Hz (the 1000 Hz maximum is bounded by the 1 ms RTOS tick) and quantized to whole milliseconds (period_ms = 1000 / frequency), so effective frequencies are 1000/N Hz. A value of 0 is invalid and ignored. Defaults to 20 Hz (50 ms) at start-up. - Category: Encoder
- Properties:
frequency(uint16_t): The odometry update frequency in Hz. Valid range 1 to 1000 Hz; values outside are clamped, and 0 is ignored.
GET_ODOMETRY_FREQUENCY
- Code:
0x18 - Description: The
GET_ODOMETRY_FREQUENCYcommand retrieves the current global update frequency (in Hz) of the odometry task. - Category: Encoder
- Response:
frequency(uint16_t): The current odometry update frequency in Hz (1 to 1000 Hz).
GPIO Commands
INITIALIZE_GPIO_PIN
- Code:
0x20 - Description: The
INITIALIZE_GPIO_PINcommand prepares a digital GPIO pin for operation, configuring it as either an input or output pin. This command is essential for setting up pins before using them in your application, whether for reading sensors or controlling devices. - Category: GPIO
- Properties:
pin_number(uint8_t): The number of the GPIO pin to initialize.mode(uint8_t): The mode to set for the GPIO pin. Modes: 0 = INPUT_PULLDOWN, 1 = INPUT_PULLUP, 2 = INPUT_NOPULL, 3 = OUTPUT.
SET_GPIO_PIN_STATE
- Code:
0x21 - Description: The
SET_GPIO_PIN_STATEcommand allows you to set the state of a GPIO pin, either turning it on (HIGH) or off (LOW). This command is typically used to control external devices like LEDs, relays, or other components connected to the GPIO pin. - Category: GPIO
- Properties:
pin_number(uint8_t): The number of the GPIO pin to set.state(uint8_t): The desired state of the pin. 0 = LOW, 1 = HIGH.
GET_GPIO_PIN_STATE
- Code:
0x22 - Description: The
GET_GPIO_PIN_STATEcommand reads the current state of a specified GPIO pin, returning whether it is currently HIGH or LOW. This is useful for monitoring the status of inputs like buttons or switches. - Category: GPIO
- Properties:
pin_number(uint8_t): The number of the GPIO pin to read.
- Response:
state(uint8_t): The current state of the pin. 0 = LOW, 1 = HIGH.
TOGGLE_GPIO_PIN_STATE
- Code:
0x23 - Description: The
TOGGLE_GPIO_PIN_STATEcommand flips the state of a GPIO pin from HIGH to LOW or from LOW to HIGH. This is particularly useful for creating simple toggling behaviors, such as blinking an LED. - Category: GPIO
- Properties:
pin_number(uint8_t): The number of the GPIO pin to toggle.
SET_STATUS_LED_STATE
- Code:
0x25 - Description: The
SET_STATUS_LED_STATEcommand controls the state of a status LED on the system, turning it on or off. This LED is often used to indicate the operational status of the system or to provide visual feedback for certain conditions. - Category: GPIO
- Properties:
state(uint8_t): The desired state of the status LED. 0 = OFF, 1 = ON.
TOGGLE_STATUS_LED_STATE
- Code:
0x26 - Description: The
TOGGLE_STATUS_LED_STATEcommand changes the current state of the status LED, turning it on if it was off, or off if it was on. This can be used to create visual indicators for system events or statuses. - Category: GPIO