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

User-defined functions. More...

Functions

float tempmonGetTemp (void)
 Get the CPU temperature.
 
uint32_t set_arm_clock (uint32_t frequency)
 Set the CPU clock.
 
void start_IObus (void)
 Initialize the IO buses.
 
void set_IObus (void)
 Start the IO buses.
 
void do_zeros (void)
 Perform the zero.
 
void set_GPIO (void)
 Set the GPIO.
 
void start_brake_stepper (void)
 Start the brake stepper motor.
 
void get_sensors (void)
 Get sensor readings.
 
void set_ctrl_input (void)
 Set the control inputs.
 
void do_control (void)
 Update the control loop.
 
void check_error (void)
 Check for errors.
 
bool check_sbus (void)
 Check for SBUS.
 
void set_driver (void)
 Set the drivers.
 
int8_t get_selector (void)
 Get the selector.
 
bool get_enable (void)
 Get the enable.
 
void turnoff_callback (void)
 Callback for tuning off.
 
boolean check_voltage (void)
 Check the battery voltage.
 
time_t getTime ()
 Get internal RTC time.
 
void do_led ()
 Management of the status LED.
 
void serial_flush ()
 Flush the UARTs.
 
void set_ctrl_param ()
 Set custom control parameters.
 
void update_tet (uint32_t t0)
 Update task execution time.
 

Detailed Description

User-defined functions.

Definition of the user defined functions called in main().

See also
main userfun.h

Function Documentation

◆ check_error()

void check_error ( void )

Check for errors.

Function to check for possible errors, such as unfeasible values of signals or limit exceeding. A error state variable is modified if errors are found.

◆ check_sbus()

bool check_sbus ( void )

Check for SBUS.

Function to check for unfeasible values of SBUS channels, which must be within MIN_SBUS and MAX_SBUS. The function checks also for lost frame and fail safe.

Returns
True if success, false for errors.
See also
MIN_SBUS MAX_SBUS

◆ check_voltage()

boolean check_voltage ( void )

Check the battery voltage.

Function to check possible under- or over-voltage of the battery.

Returns
True if the battery voltage is between MIN_VOLTAGE and MAX_VOLTAGE (no under- or over-voltage occured).
See also
MIN_VOLTAGE MAX_VOLTAGE

◆ do_control()

void do_control ( void )

Update the control loop.

Function to update the control loop with the new sensor readings or create the ouput in the case of tests.

See also
Macros

◆ do_led()

void do_led ( )

Management of the status LED.

Function to manage the status LED according to the microcontroller mode. Depending on the LED blinking, the microcontroller mode is:

◆ do_zeros()

void do_zeros ( void )

Perform the zero.

Function to perform the zero-calibration of some sensors. These include the torsiometer, the actual motor current and the actual steer rate. It also sets the pre-defined offsets (e.g. for the gyrometer).

See also
RiderTorque::riderTorque_offset GYROX_OFFSET GYROY_OFFSET GYROZ_OFFSET

◆ get_enable()

bool get_enable ( void )

Get the enable.

Function to get the enable status. Enable is 0 if errors found or remote enable is off.

◆ get_selector()

int8_t get_selector ( void )

Get the selector.

Function to get the selector status. Selector is +/-1/0 depending on the switch on the remote controller.

◆ get_sensors()

void get_sensors ( void )

Get sensor readings.

Function to get the sensor readings (raw values only). Sensors are read with the specified sampling factor.

See also
SAMPLING_TIME SPEED_SAMPLING_FAC IMU_SAMPLING_FAC MAG_SAMPLING_FAC

◆ getTime()

time_t getTime ( )

Get internal RTC time.

Function to get the internal RTC time of the microcontroller.

Returns
The internal RTC time, as a time_t type, which are the seconds elapsed from 1970 1 Jan 00:00:00.

◆ serial_flush()

void serial_flush ( )

Flush the UARTs.

Function to flush the receive buffer of the UARTs.

See also
UART_SPEEDSENS UART_GPS

◆ set_arm_clock()

uint32_t set_arm_clock ( uint32_t frequency)

Set the CPU clock.

Extern function to set the CPU clock.

Parameters
frequencyThe CPU clock in Hz.
Returns
The actual CPU frequency in Hz.
See also
https://forum.pjrc.com/threads/57444-How-to-change-clock-speed-on-Teensy-4-0

◆ set_ctrl_input()

void set_ctrl_input ( void )

Set the control inputs.

Function to convert sensor readings to convenient units.

◆ set_ctrl_param()

void set_ctrl_param ( )

Set custom control parameters.

Function to set custom control parameters in controlParams, e.g. controlParams.propGainSpeed = 0.

Attention
Be sure that modified variables exist.

◆ set_driver()

void set_driver ( void )

Set the drivers.

Function to set the drivers, such as the steer-motor driver and the throttle via the DAC. Drivers are set only if no error is found.

See also
Macros

◆ set_GPIO()

void set_GPIO ( void )

Set the GPIO.

Function to set general-purpose input-output digital pins, depending on their usage. This also includes the assignment of a default (initial) state for the digital output pins.

◆ set_IObus()

void set_IObus ( void )

Start the IO buses.

Function to start the IO buses for the sensors and drivers after initialization. This incluses the setting of sensors (IMU, magnetometer, GPS, ADC, PWM and DAC).

◆ start_brake_stepper()

void start_brake_stepper ( void )

Start the brake stepper motor.

Function to start and set the stepper motor acting on the brake lever.

◆ start_IObus()

void start_IObus ( void )

Initialize the IO buses.

Function to initialize the IO buses for the sensors and drivers. This incluses initialization of SPI and the related sensors (IMU, magnetometer, and DAC), initialization of the UARTs for the speed sensor and GPS.

See also
USED_SPI UART_SPEEDSENS UART_GPS

◆ tempmonGetTemp()

float tempmonGetTemp ( void )
extern

Get the CPU temperature.

Extern function to get the CPU temperature in Celsius degrees.

Returns
The CPU temperature in Celsius degrees.
See also
https://forum.pjrc.com/threads/59813-Teensy-4-0-Internal-Temperature-measurement

◆ turnoff_callback()

void turnoff_callback ( void )

Callback for tuning off.

Callback function called when the microcontroller turns of, in order to end stuff before (e.g. close the log file).

◆ update_tet()

void update_tet ( uint32_t t0)

Update task execution time.

Function to update the TET.

Parameters
t0The initial task time.