SBB Micro
Source code for the self-balancing-bike microcontroller unit (Teensy 4.1-based). 🚀️
Loading...
Searching...
No Matches

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.
 

Detailed Description

Macro definitions.

Definition of the macros for conversions and utilities. This includes definitions of macros for unit conversions and utilities, such such enable macros.

Macro Definition Documentation

◆ BR_DISABLE

#define BR_DISABLE   digitalWriteFast(BR_SLEEP_PIN, !BR_SLEEP_STATE)

Macro for brake motor enable.

See also
BR_SLEEP_PIN BR_SLEEP_STATE

◆ BR_ENABLE

#define BR_ENABLE   digitalWriteFast(BR_SLEEP_PIN, BR_SLEEP_STATE)

Macro for brake motor enable.

See also
BR_SLEEP_PIN BR_SLEEP_STATE

◆ BR_SLEEP_STATE

#define BR_SLEEP_STATE   HIGH

Enable state for brake motor.

◆ CONVERT_ACTCURR_TO_A

#define CONVERT_ACTCURR_TO_A ( X)
Value:
(-(GAIN_ACTCURR * X / (powf(2, ADC_RES) - 1) + OFFSET_ACTCURR))
#define ADC_RES
ADC resolution (in bits).
Definition config.h:51
#define OFFSET_ACTCURR
Offset of actual motor current.
Definition config.h:149
#define GAIN_ACTCURR
Gain of actual motor current.
Definition config.h:148

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.

Parameters
XThe ADC value to convert (in bits).
Returns
The value in rad.
See also
ADC_RES GAIN_STEERVEL OFFSET_STEERVEL

◆ CONVERT_BRLEV_TO_STEPS

#define CONVERT_BRLEV_TO_STEPS ( X)
Value:
#define BR_SPEED_RATIO
Speed ratio of the brake motor to brake lever (mm/revolution).
Definition config.h:187
#define BR_STEPS
Number of steps of the brake motor.
Definition config.h:186

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.

Parameters
XThe brake lever position (mm).
Returns
The number of steps of the steeper motor.
See also
BR_STEPS BR_SPEED_RATIO

◆ CONVERT_CHANNEL_TO_FLOAT

#define CONVERT_CHANNEL_TO_FLOAT ( X,
XMIN,
XMAX )
Value:
(float(X)-MIN_SBUS)/(MAX_SBUS-MIN_SBUS)*(XMAX-XMIN) + XMIN
#define MAX_SBUS
Maximum value from SBUS.
Definition config.h:160
#define MIN_SBUS
Minimum value from SBUS.
Definition config.h:161

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.

Parameters
XThe value of SBUS channel. It must be within MIN_SBUS and MAX_SBUS.
XMINThe minimum value of the float.
XMAXThe maximum value of the float.
Returns
The float value within MIN and MAX.
See also
MAX_SBUS MIN_SBUS

◆ CONVERT_CURRENT_TO_DAC

#define CONVERT_CURRENT_TO_DAC ( X)
Value:
abs(X / MAX_REFCUR * (powf(2, DAC_RES) - 1))
#define DAC_RES
DAC resolution (in bits).
Definition config.h:55
#define MAX_REFCUR
Maximum reference current.
Definition config.h:177

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.

Parameters
XThe reference current.
Returns
The DAC value.
See also
MAX_REFCUR DAC_RES

◆ CONVERT_CURRENT_TO_PWM

#define CONVERT_CURRENT_TO_PWM ( X)
Value:
(PWM_MIN * (powf(2, PWM_RES) - 1) + abs((PWM_MAX - PWM_MIN) * X / MAX_REFCUR * (powf(2, PWM_RES) - 1)))
#define PWM_MAX
Maximum PWM value for motor current reference.
Definition config.h:63
#define PWM_RES
PWM resolution in bit (max is 14).
Definition config.h:60
#define PWM_MIN
Minimum PWM value for motor current reference.
Definition config.h:62

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.

Parameters
XThe reference current.
Returns
The PWM value.
See also
MAX_REFCUR PWM_MIN PWM_MAX PWM_RES

◆ CONVERT_FORKDISP_TO_MM

#define CONVERT_FORKDISP_TO_MM ( X)
Value:
(GAIN_FORKDISP * X / (powf(2, ADC_RES) - 1) + OFFSET_FORKDISP)
#define GAIN_FORKDISP
Fain of front fork displacement.
Definition config.h:152
#define OFFSET_FORKDISP
Offset of front fork displacement.
Definition config.h:153

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.

Parameters
XThe ADC value to conver (in bits).
Returns
The value in volts.
See also
ADC_RES GAIN_FORKDISP OFFSET_FORKDISP

◆ CONVERT_RIDERTRQ_TO_NM

#define CONVERT_RIDERTRQ_TO_NM ( X)
Value:
(GAIN_RIDERTRQ * X / (powf(2, ADC_RES) - 1) * 3.3F / 5.0F * 1.0e3 + OFFSET_RIDERTRQ)
#define GAIN_RIDERTRQ
Gain of rider torque (Nm/(mV/V), with 5V supply).
Definition config.h:142
#define OFFSET_RIDERTRQ
Offset of rider torque (mV/V).
Definition config.h:143

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.

Parameters
XThe ADC value to convert (in bits).
Returns
The value in Nm.
See also
ADC_RES GAIN_RIDERTRQ OFFSET_RIDERTRQ

◆ CONVERT_STEERPOS_TO_RAD

#define CONVERT_STEERPOS_TO_RAD ( X)
Value:
(GAIN_STEERPOS * X / (powf(2, ADC_RES) - 1) + OFFSET_STEERPOS)
#define GAIN_STEERPOS
Fain of steer position.
Definition config.h:144
#define OFFSET_STEERPOS
Offset of steer position.
Definition config.h:145

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.

Parameters
XThe ADC value to convert (in bits).
Returns
The value in radiants.
See also
ADC_RES GAIN_STEERPOS OFFSET_STEERPOS

◆ CONVERT_STEERVEL_TO_RADPS

#define CONVERT_STEERVEL_TO_RADPS ( X)
Value:
#define OFFSET_STEERVEL
Offset of steer velocity.
Definition config.h:147
#define GAIN_STEERVEL
Gain of steer velocity.
Definition config.h:146
#define STEERVEL_RATIO
Speed ratio of steer velocity.
Definition config.h:341

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.

Parameters
XThe ADC value to convert (in bits).
Returns
The value in rad.
See also
ADC_RES GAIN_STEERVEL OFFSET_STEERVEL

◆ CONVERT_TRHOTTLE_TO_DAC

#define CONVERT_TRHOTTLE_TO_DAC ( X)
Value:
(X / MAX_REFTHROTTLE * (powf(2, DAC_RES) - 1))
#define MAX_REFTHROTTLE
Maximum throttle value.
Definition config.h:178

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.

Parameters
XThe reference throttle.
Returns
The DAC value.
See also
MAX_REFTHROTTLE DAC_RES

◆ CONVERT_TRHOTTLE_TO_STEPS

#define CONVERT_TRHOTTLE_TO_STEPS ( X)
Value:
#define MAX_BR_DISP
Maximum brake lever displacement (mm).
Definition config.h:188
#define CONVERT_BRLEV_TO_STEPS(X)
Convert brake lever position to motor steps.
Definition config.h:299

Convert throttle to motor steps.

Macro for the conversion of the throttle to the number of steps of the steeper motor.

Parameters
XThe reference throttle.
Returns
The number of steps of the steeper motor.
See also
CONVERT_BRLEV_TO_STEPS

◆ CONVERT_VOLTAGE_TO_V

#define CONVERT_VOLTAGE_TO_V ( X)
Value:
(GAIN_VOLTAGE * X / (powf(2, ADC_RES) - 1) + OFFSET_VOLTAGE)
#define OFFSET_VOLTAGE
Offset of voltage.
Definition config.h:151
#define GAIN_VOLTAGE
Gain of voltage.
Definition config.h:150

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.

Parameters
XThe ADC value to conver (in bits).
Returns
The value in volts.
See also
ADC_RES GAIN_VOLTAGE OFFSET_VOLTAGE

◆ LEDOFF

#define LEDOFF   digitalWriteFast(LED_BUILTIN, LOW)

Macro for LED off.

Standard value for LED_BUILTIN is 13 in the Arduino environment.

◆ LEDON

#define LEDON   digitalWriteFast(LED_BUILTIN, HIGH)

Macro for LED on.

Standard value for LED_BUILTIN is 13 in the Arduino environment.

◆ MTR_EN_STATE

#define MTR_EN_STATE   HIGH

Enable state for steer motor.

◆ MTR_ENABLE

#define MTR_ENABLE   digitalWriteFast(MTR_EN_PIN, MTR_EN_STATE), delay(100)

Macro for motor enable.

See also
MTR_EN_PIN MTR_EN_STATE

◆ POWER_OFF

#define POWER_OFF   SNVS_LPCR |= (1<<6)

Macro for turning off the microcontroller.

Refer to the MCU manual for details.

See also
https://forum.pjrc.com/threads/59125-Is-there-a-hook-to-know-when-the-on-off-pin-on-the-Teensy-4-0-has-been-grounded

◆ RELAY_EN_STATE

#define RELAY_EN_STATE   HIGH

Enable state for relay.

◆ RELAY_ENABLE

#define RELAY_ENABLE   digitalWriteFast(RELAY_EN_PIN, RELAY_EN_STATE), delay(500)

Macro for relay enable.

See also
RELAY_EN_PIN RELAY_EN_STATE

◆ USB_CONNECTED

#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