SBB Micro
Source code for the self-balancing-bike microcontroller unit (Teensy 4.1-based). 🚀️
|
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). | |
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.
#define ACC_ODR 3333 |
Output data rate of accelerometer (sps).
#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).
#define BR_SPEED_RATIO 1 |
Speed ratio of the brake motor to brake lever (mm/revolution).
#define BR_STEPS 200 |
Number of steps of the brake motor.
#define DEF_LED 500 |
Sampling factor of led in default mode (expressed in units of SAMPLING_TIME).
#define DIST_SCALE 0.25F |
Distance scale.
Units of 0.25m to m.
#define ERR_LED 10000 |
Sampling factor of led in error mode (expressed in units of SAMPLING_TIME).
#define GAIN_ACTCURR 2*MAX_REFCUR |
Gain of actual motor current.
Value from ESCON Studio.
#define GAIN_FORKDISP -152.935F |
Fain of front fork displacement.
Value from frok-displacement sensor calibartion.
#define GAIN_RIDERTRQ 0.141F |
Gain of rider torque (Nm/(mV/V), with 5V supply).
Value from torsiometer calibration.
#define GAIN_STEERPOS 50.9F/180.0F*PI |
Fain of steer position.
Value from steer-angle sensor calibration.
#define GAIN_STEERVEL (2.0F*1000.0F/60.0F*2.0F*PI) |
Gain of steer velocity.
Value from ESCON Studio.
#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.
#define GPSSPEED_SCALE 0.5144F |
GPS speed scale.
Knots to m/s.
#define GYRO_ODR 3333 |
Output data rate of gyrometer (sps).
#define GYRO_SCALE (1.0e-3F*PI/180.0F) |
Gyrometer scale.
mdps to rad/s.
#define GYROX_OFFSET +0.0059F/GYRO_SCALE |
Offset of gyro x.
Value from offset calibration of the IMU.
#define GYROY_OFFSET -0.0066F/GYRO_SCALE |
Offset of gyro y.
Value from offset calibration of the IMU.
#define GYROZ_OFFSET -0.0080F/GYRO_SCALE |
Offset of gyro z.
Value from offset calibration of the IMU.
#define IMU_SAMPLING_FAC 1 |
Sampling factor of IMU (expressed in units of SAMPLING_TIME).
#define LOG_LED 500 |
Sampling factor of led in log mode (expressed in units of SAMPLING_TIME).
#define MAG_ODR 200 |
Output data rate of magnetometer (sps).
#define MAG_SAMPLING_FAC 5 |
Sampling factor of magnetometer (expressed in units of SAMPLING_TIME).
#define MAG_SCALE 0.1F |
Magnetometer scale.
mG to uT.
#define MAX_BR_ACC 25 |
Maximum brake motor acceleration (mm/s2).
#define MAX_BR_DISP 12.0F |
Maximum brake lever displacement (mm).
#define MAX_BR_SPEED 10 |
Maximum brake motor speed (mm/s).
#define MAX_MISSING_SBUS 10*SBUS_SAMPLING_FAC |
Maximum missing packets for SBUS.
Maximum missing packets for the SBUS communication.
#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.
#define MAX_REFCUR 10 |
Maximum reference current.
#define MAX_REFTHROTTLE 1.0F |
Maximum throttle value.
#define MAX_SBUS 1811 |
Maximum value from SBUS.
Maximum value received by the SBUS.
#define MAX_STEER_ANGLE 0.35 |
Maximum steering angle.
Maximum steering angle above which motor drivers are disabled and the system stops.
#define MAX_VOLTAGE 40 |
Maximum battery voltage (overvoltage) (V).
#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.
#define MIN_SBUS 172 |
Minimum value from SBUS.
Minimum value received by the SBUS.
#define MIN_VOLTAGE 15 |
Minimum battery voltage (undervoltage) (V).
#define MTP_LED 250 |
Sampling factor of led in mtp 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 NUM_CH_SBUS 7 |
#define OFFSET_ACTCURR -MAX_REFCUR |
Offset of actual motor current.
Value from ESCON Studio.
#define OFFSET_FORKDISP 0.107F |
Offset of front fork displacement.
Value from frok-displacement sensor calibartion.
#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().
#define OFFSET_STEERPOS -30.7F/180.0F*PI |
Offset of steer position.
Value from steer-angle sensor calibration.
#define OFFSET_STEERVEL (-1000.0F/60.0F*2.0F*PI) |
Offset of steer velocity.
Value from ESCON Studio.
#define OFFSET_VOLTAGE 0.0F |
Offset of voltage.
No offset necessary.
#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.
#define SBUS_BR_CH 6 |
brake channel in SBUS.
Channel of SBUS for brake signal.
#define SBUS_EN_CH 5 |
Enable channel in SBUS.
Channel of SBUS for enable signal.
#define SBUS_ROLL_CH 1 |
Roll channel in SBUS.
Channel of SBUS for roll reference.
#define SBUS_SAMPLING_FAC 14 |
Sampling factor of the SBUSr receiver.
#define SBUS_SEL_CH 7 |
3 selector channel in SBUS.
#define SBUS_THR_OR 3 |
Direct throttle channel in SBUS.
Channel of SBUS for overrideing the throttle channel.
#define SBUS_THROTTLE_CH 2 |
Throttle channel in SBUS.
Channel of SBUS for throttle reference.
#define SPEED_SAMPLING_FAC 1 |
Sampling factor of speed sensor (expressed in units of SAMPLING_TIME).
#define SPEED_SCALE 1.0e-3F |
Speed scale.
mm/s to m/s.
#define TRESHOLD_LOGIC_SBUS 1400 |
#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.
#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.