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

Constant and factor definitions. More...

Macros

#define SAMPLING_TIME   1e3
 Sampling time of the control loop (us).
 
#define SPEED_SAMPLING_FAC   1
 Sampling factor of speed sensor (expressed in units of SAMPLING_TIME).
 
#define IMU_SAMPLING_FAC   1
 Sampling factor of IMU (expressed in units of SAMPLING_TIME).
 
#define MAG_SAMPLING_FAC   5
 Sampling factor of magnetometer (expressed in units of SAMPLING_TIME).
 
#define SBUS_SAMPLING_FAC   14
 Sampling factor of the SBUSr receiver.
 
#define DEF_LED   500
 Sampling factor of led in default mode (expressed in units of SAMPLING_TIME).
 
#define LOG_LED   500
 Sampling factor of led in log mode (expressed in units of SAMPLING_TIME).
 
#define MTP_LED   250
 Sampling factor of led in mtp mode (expressed in units of SAMPLING_TIME).
 
#define ERR_LED   10000
 Sampling factor of led in error mode (expressed in units of SAMPLING_TIME).
 
#define MTPWAIT_LED   100
 Sampling factor of led in mtp wait mode (expressed in units of SAMPLING_TIME).
 
#define ACC_ODR   3333
 Output data rate of accelerometer (sps).
 
#define GYRO_ODR   3333
 Output data rate of gyrometer (sps).
 
#define MAG_ODR   200
 Output data rate of magnetometer (sps).
 
#define SPEED_SCALE   1.0e-3F
 Speed scale.
 
#define DIST_SCALE   0.25F
 Distance scale.
 
#define ACC_SCALE   (-1.0e-3F*9.806F)
 Acceleration scale.
 
#define GYRO_SCALE   (1.0e-3F*PI/180.0F)
 Gyrometer scale.
 
#define MAG_SCALE   0.1F
 Magnetometer scale.
 
#define GPSSPEED_SCALE   0.5144F
 GPS speed scale.
 
#define GAIN_RIDERTRQ   0.141F
 Gain of rider torque (Nm/(mV/V), with 5V supply).
 
#define OFFSET_RIDERTRQ   -(324.11*GAIN_RIDERTRQ)
 Offset of rider torque (mV/V).
 
#define GAIN_STEERPOS   50.9F/180.0F*PI
 Fain of steer position.
 
#define OFFSET_STEERPOS   -30.7F/180.0F*PI
 Offset of steer position.
 
#define GAIN_STEERVEL   (2.0F*1000.0F/60.0F*2.0F*PI)
 Gain of steer velocity.
 
#define OFFSET_STEERVEL   (-1000.0F/60.0F*2.0F*PI)
 Offset of steer velocity.
 
#define GAIN_ACTCURR   2*MAX_REFCUR
 Gain of actual motor current.
 
#define OFFSET_ACTCURR   -MAX_REFCUR
 Offset of actual motor current.
 
#define GAIN_VOLTAGE   3.3F*1.027F*160.0F/10.0F
 Gain of voltage.
 
#define OFFSET_VOLTAGE   0.0F
 Offset of voltage.
 
#define GAIN_FORKDISP   -152.935F
 Fain of front fork displacement.
 
#define OFFSET_FORKDISP   0.107F
 Offset of front fork displacement.
 
#define GYROX_OFFSET   +0.0059F/GYRO_SCALE
 Offset of gyro x.
 
#define GYROY_OFFSET   -0.0066F/GYRO_SCALE
 Offset of gyro y.
 
#define GYROZ_OFFSET   -0.0080F/GYRO_SCALE
 Offset of gyro z.
 
#define NUM_CH_SBUS   7
 Number channels from SBUS.
 
#define MAX_SBUS   1811
 Maximum value from SBUS.
 
#define MIN_SBUS   172
 Minimum value from SBUS.
 
#define ZERO_SBUS   992
 Zero-value for SBUS.
 
#define TRESHOLD_LOGIC_SBUS   1400
 Treshold for SBUS logic channels.
 
#define TRESHOLD_POS_SBUS   1400
 Treshold for positive value.
 
#define TRESHOLD_NEG_SBUS   600
 Treshold for negative value.
 
#define MAX_MISSING_SBUS   10*SBUS_SAMPLING_FAC
 Maximum missing packets for SBUS.
 
#define MAX_REF_INPUT   1
 Maximum value for input reference.
 
#define MIN_REF_INPUT   -1
 Minimum value for input reference.
 
#define SBUS_THROTTLE_CH   2
 Throttle channel in SBUS.
 
#define SBUS_ROLL_CH   1
 Roll channel in SBUS.
 
#define SBUS_EN_CH   5
 Enable channel in SBUS.
 
#define SBUS_BR_CH   6
 brake channel in SBUS.
 
#define SBUS_THR_OR   3
 Direct throttle channel in SBUS.
 
#define SBUS_SEL_CH   7
 3 selector channel in SBUS.
 
#define MAX_REFCUR   10
 Maximum reference current.
 
#define MAX_REFTHROTTLE   1.0F
 Maximum throttle value.
 
#define MIN_VOLTAGE   15
 Minimum battery voltage (undervoltage) (V).
 
#define MAX_VOLTAGE   40
 Maximum battery voltage (overvoltage) (V).
 
#define MAX_STEER_ANGLE   0.35
 Maximum steering angle.
 
#define MAX_BR_SPEED   10
 Maximum brake motor speed (mm/s).
 
#define MAX_BR_ACC   25
 Maximum brake motor acceleration (mm/s2).
 
#define BR_STEPS   200
 Number of steps of the brake motor.
 
#define BR_SPEED_RATIO   1
 Speed ratio of the brake motor to brake lever (mm/revolution).
 
#define MAX_BR_DISP   12.0F
 Maximum brake lever displacement (mm).
 

Detailed Description

Constant and factor definitions.

Definition of the constants and factors. This includes the fundamental sampling time and the sampling factors for sensors etc. (expressed in units of the fundamental sempling time), the output data rate of sensors, the gains, offsets, and conversions for sensors and units, and limits values.

Macro Definition Documentation

◆ ACC_ODR

#define ACC_ODR   3333

Output data rate of accelerometer (sps).

Note
This is not the rate at which the sensor is read (i.e. IMU_SAMPLING_FAC).
See also
IMU_SAMPLING_FAC

◆ ACC_SCALE

#define ACC_SCALE   (-1.0e-3F*9.806F)

Acceleration scale.

mg to m/s^2. -1 is to have actual accelerations (no the inertial ones).

◆ BR_SPEED_RATIO

#define BR_SPEED_RATIO   1

Speed ratio of the brake motor to brake lever (mm/revolution).

◆ BR_STEPS

#define BR_STEPS   200

Number of steps of the brake motor.

◆ DEF_LED

#define DEF_LED   500

Sampling factor of led in default mode (expressed in units of SAMPLING_TIME).

See also
SAMPLING_TIME LedMode::DEF

◆ DIST_SCALE

#define DIST_SCALE   0.25F

Distance scale.

Units of 0.25m to m.

◆ ERR_LED

#define ERR_LED   10000

Sampling factor of led in error mode (expressed in units of SAMPLING_TIME).

See also
SAMPLING_TIME LedMode::ERR

◆ GAIN_ACTCURR

#define GAIN_ACTCURR   2*MAX_REFCUR

Gain of actual motor current.

Value from ESCON Studio.

◆ GAIN_FORKDISP

#define GAIN_FORKDISP   -152.935F

Fain of front fork displacement.

Value from frok-displacement sensor calibartion.

◆ GAIN_RIDERTRQ

#define GAIN_RIDERTRQ   0.141F

Gain of rider torque (Nm/(mV/V), with 5V supply).

Value from torsiometer calibration.

◆ GAIN_STEERPOS

#define GAIN_STEERPOS   50.9F/180.0F*PI

Fain of steer position.

Value from steer-angle sensor calibration.

◆ GAIN_STEERVEL

#define GAIN_STEERVEL   (2.0F*1000.0F/60.0F*2.0F*PI)

Gain of steer velocity.

Value from ESCON Studio.

◆ GAIN_VOLTAGE

#define GAIN_VOLTAGE   3.3F*1.027F*160.0F/10.0F

Gain of voltage.

Value from voltage divider resistors (10k and 150k) and a correction factor from a calibartion.

◆ GPSSPEED_SCALE

#define GPSSPEED_SCALE   0.5144F

GPS speed scale.

Knots to m/s.

◆ GYRO_ODR

#define GYRO_ODR   3333

Output data rate of gyrometer (sps).

Note
This is not the rate at which the sensor is read (i.e. IMU_SAMPLING_FAC).
See also
IMU_SAMPLING_FAC

◆ GYRO_SCALE

#define GYRO_SCALE   (1.0e-3F*PI/180.0F)

Gyrometer scale.

mdps to rad/s.

◆ GYROX_OFFSET

#define GYROX_OFFSET   +0.0059F/GYRO_SCALE

Offset of gyro x.

Value from offset calibration of the IMU.

◆ GYROY_OFFSET

#define GYROY_OFFSET   -0.0066F/GYRO_SCALE

Offset of gyro y.

Value from offset calibration of the IMU.

◆ GYROZ_OFFSET

#define GYROZ_OFFSET   -0.0080F/GYRO_SCALE

Offset of gyro z.

Value from offset calibration of the IMU.

◆ IMU_SAMPLING_FAC

#define IMU_SAMPLING_FAC   1

Sampling factor of IMU (expressed in units of SAMPLING_TIME).

Note
This is the rate at which the sensor is read, not its output data rate (i.e. ACC_ODR or GYRO_ODR).
See also
SAMPLING_TIME ACC_ODR GYRO_ODR

◆ LOG_LED

#define LOG_LED   500

Sampling factor of led in log mode (expressed in units of SAMPLING_TIME).

See also
SAMPLING_TIME LedMode::LOG

◆ MAG_ODR

#define MAG_ODR   200

Output data rate of magnetometer (sps).

Note
This is not the rate at which the sensor is read (i.e. MAG_SAMPLING_FAC).
See also
MAG_SAMPLING_FAC

◆ MAG_SAMPLING_FAC

#define MAG_SAMPLING_FAC   5

Sampling factor of magnetometer (expressed in units of SAMPLING_TIME).

Note
This is the rate at which the sensor is read, not its output data rate (i.e. MAG_ODR).
See also
SAMPLING_TIME MAG_ODR

◆ MAG_SCALE

#define MAG_SCALE   0.1F

Magnetometer scale.

mG to uT.

◆ MAX_BR_ACC

#define MAX_BR_ACC   25

Maximum brake motor acceleration (mm/s2).

◆ MAX_BR_DISP

#define MAX_BR_DISP   12.0F

Maximum brake lever displacement (mm).

◆ MAX_BR_SPEED

#define MAX_BR_SPEED   10

Maximum brake motor speed (mm/s).

◆ MAX_MISSING_SBUS

#define MAX_MISSING_SBUS   10*SBUS_SAMPLING_FAC

Maximum missing packets for SBUS.

Maximum missing packets for the SBUS communication.

Note
Check for missing packet is performed avery SAMPLING_TIME milliseconds.
See also
SAMPLING_TIME

◆ MAX_REF_INPUT

#define MAX_REF_INPUT   1

Maximum value for input reference.

Maximum value for the input reference in the control model. Signals from SBUS (int16_t) are remapped within MIN_SBUS and MAX_SBUS as float numbers.

See also
MIN_SBUS MAX_SBUS CONVERT_CHANNEL_TO_FLOAT

◆ MAX_REFCUR

#define MAX_REFCUR   10

Maximum reference current.

Warning
Must be consistent with that in ESCON studio and Simulink.

◆ MAX_REFTHROTTLE

#define MAX_REFTHROTTLE   1.0F

Maximum throttle value.

Warning
Must be consistent with that in Simulink.

◆ MAX_SBUS

#define MAX_SBUS   1811

Maximum value from SBUS.

Maximum value received by the SBUS.

◆ MAX_STEER_ANGLE

#define MAX_STEER_ANGLE   0.35

Maximum steering angle.

Maximum steering angle above which motor drivers are disabled and the system stops.

◆ MAX_VOLTAGE

#define MAX_VOLTAGE   40

Maximum battery voltage (overvoltage) (V).

◆ MIN_REF_INPUT

#define MIN_REF_INPUT   -1

Minimum value for input reference.

Minimum value for the input reference in the control model. Signals from SBUS (int16_t) are remapped within MIN_SBUS and MAX_SBUS as float numbers.

See also
MIN_SBUS MAX_SBUS CONVERT_CHANNEL_TO_FLOAT

◆ MIN_SBUS

#define MIN_SBUS   172

Minimum value from SBUS.

Minimum value received by the SBUS.

◆ MIN_VOLTAGE

#define MIN_VOLTAGE   15

Minimum battery voltage (undervoltage) (V).

◆ MTP_LED

#define MTP_LED   250

Sampling factor of led in mtp mode (expressed in units of SAMPLING_TIME).

See also
SAMPLING_TIME LedMode::MTP

◆ MTPWAIT_LED

#define MTPWAIT_LED   100

Sampling factor of led in mtp wait mode (expressed in units of SAMPLING_TIME).

See also
SAMPLING_TIME LedMode::MTPWAIT

◆ NUM_CH_SBUS

#define NUM_CH_SBUS   7

Number channels from SBUS.

Number of the stored channel from the SBUS.

See also
RemoteCtrl

◆ OFFSET_ACTCURR

#define OFFSET_ACTCURR   -MAX_REFCUR

Offset of actual motor current.

Value from ESCON Studio.

◆ OFFSET_FORKDISP

#define OFFSET_FORKDISP   0.107F

Offset of front fork displacement.

Value from frok-displacement sensor calibartion.

◆ OFFSET_RIDERTRQ

#define OFFSET_RIDERTRQ   -(324.11*GAIN_RIDERTRQ)

Offset of rider torque (mV/V).

Value from torsiometer calibration. Actually this is not strickly necessary, since a zero procedure is performed in do_zeros().

◆ OFFSET_STEERPOS

#define OFFSET_STEERPOS   -30.7F/180.0F*PI

Offset of steer position.

Value from steer-angle sensor calibration.

◆ OFFSET_STEERVEL

#define OFFSET_STEERVEL   (-1000.0F/60.0F*2.0F*PI)

Offset of steer velocity.

Value from ESCON Studio.

◆ OFFSET_VOLTAGE

#define OFFSET_VOLTAGE   0.0F

Offset of voltage.

No offset necessary.

◆ SAMPLING_TIME

#define SAMPLING_TIME   1e3

Sampling time of the control loop (us).

This is also the fundamental sampling time of the system. All other sampling times are expresed in units of this value.

Warning
Must be consistent with that in Simulink.

◆ SBUS_BR_CH

#define SBUS_BR_CH   6

brake channel in SBUS.

Channel of SBUS for brake signal.

Warning
Channel number is one-based.

◆ SBUS_EN_CH

#define SBUS_EN_CH   5

Enable channel in SBUS.

Channel of SBUS for enable signal.

Warning
Channel number is one-based.

◆ SBUS_ROLL_CH

#define SBUS_ROLL_CH   1

Roll channel in SBUS.

Channel of SBUS for roll reference.

Warning
Channel number is one-based.

◆ SBUS_SAMPLING_FAC

#define SBUS_SAMPLING_FAC   14

Sampling factor of the SBUSr receiver.

Note
This is the rate at which the sensor is read, not its output data rate.
Warning
Not used now. SBUS is read as fast as possible.
See also
SAMPLING_TIME

◆ SBUS_SEL_CH

#define SBUS_SEL_CH   7

3 selector channel in SBUS.

Warning
Channel number is one-based.

◆ SBUS_THR_OR

#define SBUS_THR_OR   3

Direct throttle channel in SBUS.

Channel of SBUS for overrideing the throttle channel.

Warning
Channel number is one-based.

◆ SBUS_THROTTLE_CH

#define SBUS_THROTTLE_CH   2

Throttle channel in SBUS.

Channel of SBUS for throttle reference.

Warning
Channel number is one-based.

◆ SPEED_SAMPLING_FAC

#define SPEED_SAMPLING_FAC   1

Sampling factor of speed sensor (expressed in units of SAMPLING_TIME).

Note
This is the rate at which the sensor is read, not its output data rate.
Warning
Not used now. Speed sensor is read as fast as possible.
See also
SAMPLING_TIME

◆ SPEED_SCALE

#define SPEED_SCALE   1.0e-3F

Speed scale.

mm/s to m/s.

◆ TRESHOLD_LOGIC_SBUS

#define TRESHOLD_LOGIC_SBUS   1400

Treshold for SBUS logic channels.

Treshold value for logic state received by the SBUS. If greaten than this value, it is a high state.

Attention
This value should be larger than ZERO_SBUS, in order to recognize it as a low state.
See also
ZERO_SBUS

◆ TRESHOLD_NEG_SBUS

#define TRESHOLD_NEG_SBUS   600

Treshold for negative value.

Treshold value for positive state received by the SBUS. If lower than this value, it is a -1.

◆ TRESHOLD_POS_SBUS

#define TRESHOLD_POS_SBUS   1400

Treshold for positive value.

Treshold value for positive state received by the SBUS. If greaten than this value, it is a +1.

◆ ZERO_SBUS

#define ZERO_SBUS   992

Zero-value for SBUS.

Value corresponding to zero for the SBUS. This is hust the average of MAX_SBUS and MIN_SBUS.

See also
MAX_SBUS MIN_SBUS