SBB Micro
Source code for the self-balancing-bike microcontroller unit (Teensy 4.1-based). 🚀️
|
Macro definitions. More...
Macros | |
#define | CONVERT_RIDERTRQ_TO_NM(X) |
Convert rider torque to Nm. | |
#define | CONVERT_STEERPOS_TO_RAD(X) |
Convert steer position to radiants. | |
#define | CONVERT_STEERVEL_TO_RADPS(X) |
Convert steer rate to rad/s. | |
#define | CONVERT_ACTCURR_TO_A(X) |
Convert steer rate to rad/s. | |
#define | CONVERT_CURRENT_TO_PWM(X) |
Convert reference current to PWM value. | |
#define | CONVERT_CURRENT_TO_DAC(X) |
Convert reference current to DAC value. | |
#define | CONVERT_TRHOTTLE_TO_DAC(X) |
Convert reference throttle to DAC value. | |
#define | CONVERT_VOLTAGE_TO_V(X) |
Convert battery voltage to volts. | |
#define | CONVERT_FORKDISP_TO_MM(X) |
Convert fork displacement to millimiters. | |
#define | CONVERT_CHANNEL_TO_FLOAT(X, XMIN, XMAX) |
Convert SBUS channel to float. | |
#define | CONVERT_BRLEV_TO_STEPS(X) |
Convert brake lever position to motor steps. | |
#define | CONVERT_TRHOTTLE_TO_STEPS(X) |
Convert throttle to motor steps. | |
#define | USB_CONNECTED (!bitRead(USB1_PORTSC1,7)) |
Macro for checking the USB connection status-. | |
#define | MTR_EN_STATE HIGH |
Enable state for steer motor. | |
#define | RELAY_EN_STATE HIGH |
Enable state for relay. | |
#define | BR_SLEEP_STATE HIGH |
Enable state for brake motor. | |
#define | MTR_ENABLE digitalWriteFast(MTR_EN_PIN, MTR_EN_STATE), delay(100) |
Macro for motor enable. | |
#define | RELAY_ENABLE digitalWriteFast(RELAY_EN_PIN, RELAY_EN_STATE), delay(500) |
Macro for relay enable. | |
#define | BR_ENABLE digitalWriteFast(BR_SLEEP_PIN, BR_SLEEP_STATE) |
Macro for brake motor enable. | |
#define | BR_DISABLE digitalWriteFast(BR_SLEEP_PIN, !BR_SLEEP_STATE) |
Macro for brake motor enable. | |
#define | LEDON digitalWriteFast(LED_BUILTIN, HIGH) |
Macro for LED on. | |
#define | LEDOFF digitalWriteFast(LED_BUILTIN, LOW) |
Macro for LED off. | |
#define | POWER_OFF SNVS_LPCR |= (1<<6) |
Macro for turning off the microcontroller. | |
Macro definitions.
Definition of the macros for conversions and utilities. This includes definitions of macros for unit conversions and utilities, such such enable macros.
#define BR_DISABLE digitalWriteFast(BR_SLEEP_PIN, !BR_SLEEP_STATE) |
Macro for brake motor enable.
#define BR_ENABLE digitalWriteFast(BR_SLEEP_PIN, BR_SLEEP_STATE) |
Macro for brake motor enable.
#define BR_SLEEP_STATE HIGH |
Enable state for brake motor.
#define CONVERT_ACTCURR_TO_A | ( | X | ) |
Convert steer rate to rad/s.
Macro for the conversion of the steer rate from raw value (in bits from the ADC) to rad/s. The macro makes use of GAIN_STEERVEL, OFFSET_STEERVEL, and ADC_RES to remap the values using a linear interpolation.
X | The ADC value to convert (in bits). |
#define CONVERT_BRLEV_TO_STEPS | ( | X | ) |
Convert brake lever position to motor steps.
Macro for the conversion of the brake lever position (mm) to the number of steps of the steeper motor.
X | The brake lever position (mm). |
#define CONVERT_CHANNEL_TO_FLOAT | ( | X, | |
XMIN, | |||
XMAX ) |
Convert SBUS channel to float.
Macro for the conversion of the value of a SBUS channel from int16_t to a float within a defined range.
X | The value of SBUS channel. It must be within MIN_SBUS and MAX_SBUS. |
XMIN | The minimum value of the float. |
XMAX | The maximum value of the float. |
#define CONVERT_CURRENT_TO_DAC | ( | X | ) |
Convert reference current to DAC value.
Macro for the conversion of the reference current to a DAC value. The macro makes use of MAX_REFCUR, and DAC_RES to remap the values using a linear interpolation. The sign is removed.
X | The reference current. |
#define CONVERT_CURRENT_TO_PWM | ( | X | ) |
Convert reference current to PWM value.
Macro for the conversion of the reference current to a PWM value. The macro makes use of MAX_REFCUR, PWM_MIN, PWM_MAX, and PWM_RES to remap the values using a linear interpolation. The sign is removed.
X | The reference current. |
#define CONVERT_FORKDISP_TO_MM | ( | X | ) |
Convert fork displacement to millimiters.
Macro for the conversion of the fork displacement from raw value (in bits from the ADC) to millimiters. The macro makes use of GAIN_FORKDISP, OFFSET_FORKDISP, and ADC_RES to remap the values using a linear interpolation.
X | The ADC value to conver (in bits). |
#define CONVERT_RIDERTRQ_TO_NM | ( | X | ) |
Convert rider torque to Nm.
Macro for the conversion of the rider torque from raw value (in bits from the ADC) to Nm. The macro makes use of GAIN_RIDERTRQ, OFFSET_RIDERTRQ, and ADC_RES to remap the values using a linear interpolation.
X | The ADC value to convert (in bits). |
#define CONVERT_STEERPOS_TO_RAD | ( | X | ) |
Convert steer position to radiants.
Macro for the conversion of the steer position from raw value (in bits from the ADC) to radiants. The macro makes use of GAIN_STEERPOS, OFFSET_STEERPOS, and ADC_RES to remap the values using a linear interpolation.
X | The ADC value to convert (in bits). |
#define CONVERT_STEERVEL_TO_RADPS | ( | X | ) |
Convert steer rate to rad/s.
Macro for the conversion of the steer rate from raw value (in bits from the ADC) to rad/s. The macro makes use of GAIN_STEERVEL, OFFSET_STEERVEL, and ADC_RES to remap the values using a linear interpolation.
X | The ADC value to convert (in bits). |
#define CONVERT_TRHOTTLE_TO_DAC | ( | X | ) |
Convert reference throttle to DAC value.
Macro for the conversion of the reference throttle to a DAC value. The macro makes use of MAX_REFTHROTTLE, and DAC_RES to remap the values using a linear interpolation. The sign is removed.
X | The reference throttle. |
#define CONVERT_TRHOTTLE_TO_STEPS | ( | X | ) |
Convert throttle to motor steps.
Macro for the conversion of the throttle to the number of steps of the steeper motor.
X | The reference throttle. |
#define CONVERT_VOLTAGE_TO_V | ( | X | ) |
Convert battery voltage to volts.
Macro for the conversion of the battery voltage from raw value (in bits from the ADC) to volts. The macro makes use of GAIN_VOLTAGE, OFFSET_VOLTAGE, and ADC_RES to remap the values using a linear interpolation.
X | The ADC value to conver (in bits). |
#define LEDOFF digitalWriteFast(LED_BUILTIN, LOW) |
Macro for LED off.
Standard value for LED_BUILTIN is 13 in the Arduino environment.
#define LEDON digitalWriteFast(LED_BUILTIN, HIGH) |
Macro for LED on.
Standard value for LED_BUILTIN is 13 in the Arduino environment.
#define MTR_EN_STATE HIGH |
Enable state for steer motor.
#define MTR_ENABLE digitalWriteFast(MTR_EN_PIN, MTR_EN_STATE), delay(100) |
Macro for motor enable.
#define POWER_OFF SNVS_LPCR |= (1<<6) |
Macro for turning off the microcontroller.
Refer to the MCU manual for details.
#define RELAY_EN_STATE HIGH |
Enable state for relay.
#define RELAY_ENABLE digitalWriteFast(RELAY_EN_PIN, RELAY_EN_STATE), delay(500) |
Macro for relay enable.
#define USB_CONNECTED (!bitRead(USB1_PORTSC1,7)) |
Macro for checking the USB connection status-.
See https://forum.pjrc.com/threads/70721-detecting-usb-connection-on-a-teensy-4-0