Siphon Regulator 1.0
Nanosattelite attitude determination and control system.
Loading...
Searching...
No Matches
Loop

Process commands send to MCU through serial port. More...

Macros

#define ANGLE_TOL   5
 
#define STOP_CONST_LEFT   (1000.0f/7.808f)
 
#define STOP_CONST_RIGHT   (1000.0f/11.7f)
 
#define STOP_CONST_OFF_LEFT   1.552f
 
#define STOP_CONST_OFF_RIGHT   0.047f
 
#define GYR_TOL   1.0f
 
#define PULSE_IGNORE   50
 

Functions

void autoread_fcn (uint32_t reg)
 It handles the periodic transmission of the sensor data message.
 
void valve_fcn (uint32_t *p_reg, float *p_set_pos)
 It handles the execution of motion commands.
 
void regul_fcn (uint32_t *p_reg, float set_pos)
 It handles the regulation of the orientation.
 
static void valve_close (void)
 Closes all valves.
 
static void regul_stop (uint32_t *p_reg, uint32_t *p_ticks)
 It provides the stopping pulse.
 
static void regul_return (uint32_t *p_reg, uint32_t *p_ticks, float set_pos)
 It initiates the return to the stable orientation.
 

Variables

sensor_data_t measured_data
 Current sensor measured data.
 
settings_t set_data
 Main system settings.
 

Detailed Description

Process commands send to MCU through serial port.

It contains the functions executed within the main loop. It enables automatic sensor reading, motion commands performing, and attitude regulating.

Necessary definition and function declaration.

Macro Definition Documentation

◆ ANGLE_TOL

#define ANGLE_TOL   5

Precision setting of position.

Definition at line 25 of file loop_fcn_def.h.

◆ GYR_TOL

#define GYR_TOL   1.0f

Ignored motion, it accounts for sensor fluctuation.

Definition at line 40 of file loop_fcn_def.h.

◆ PULSE_IGNORE

#define PULSE_IGNORE   50

Ignored pulse duration in milliseconds, too short pulse for performing

Definition at line 43 of file loop_fcn_def.h.

◆ STOP_CONST_LEFT

#define STOP_CONST_LEFT   (1000.0f/7.808f)

Definition at line 28 of file loop_fcn_def.h.

◆ STOP_CONST_OFF_LEFT

#define STOP_CONST_OFF_LEFT   1.552f

Definition at line 34 of file loop_fcn_def.h.

◆ STOP_CONST_OFF_RIGHT

#define STOP_CONST_OFF_RIGHT   0.047f

Definition at line 37 of file loop_fcn_def.h.

◆ STOP_CONST_RIGHT

#define STOP_CONST_RIGHT   (1000.0f/11.7f)

Definition at line 31 of file loop_fcn_def.h.

Function Documentation

◆ autoread_fcn()

void autoread_fcn ( uint32_t reg)

It handles the periodic transmission of the sensor data message.

Parameters
regcommand register, involves information about system state and switching time of valves

The command register specifies the requested content of the autoread message. If autoread is enabled, the message is transmitted periodically, with the interval defined in the global variable set_data.

The AUTOREAD_BIT in the command register enables the automatic transmission of messages. The AUTOREAD_GYR_BIT, AUTOREAD_POS_BIT, and AUTOREAD_ACC_BIT flags allow the corresponding data to be included in the message.

Definition at line 27 of file loop_fcn.c.

◆ regul_fcn()

void regul_fcn ( uint32_t * p_reg,
float set_pos )

It handles the regulation of the orientation.

Parameters
p_regcommand register, involves information about system state and switching time of valves
set_posthe orientation is maintained by the regulation loop.

If no motion command or regulation method is active, the system checks whether the satellite is moving and whether its orientation remains stable.

If an angular velocity exceeding the allowed tolerance is detected, a stopping pulse is requested. This is handled by the regul_stop() function, which sets the REG_BIT flag. While this flag is set, further testing is blocked. After the pulse duration expires, the function closes the valves and clears the REG_BIT flag.

If the deviation between set_pos and the measured orientation exceeds ANGLE_TOL, a return motion operation is required. This operation is initiated by the regul_return() function, which triggers the start pulse. The remaining steps are handled by valve_fcn(), to which the execution flow seamlessly transitions.

The CMD0_BIT flag allows this entire regulation mechanism to be disabled.

Definition at line 183 of file loop_fcn.c.

◆ regul_return()

static void regul_return ( uint32_t * p_reg,
uint32_t * p_ticks,
float set_pos )
static

It initiates the return to the stable orientation.

Parameters
p_regcommand register, involves information about system state and switching time of valves
p_ticksnumber of ticks until the pulse is stopped
set_posthe orientation is maintained by the regulation loop.

It triggers the first pulse of the RETURN method. It sets the REG_BIT and RETURN_BIT flags. The appropriate valve is selected so that the correction path is as short as possible. The DIR_BIT flag is also configured to ensure proper stopping behavior.The pulse duration is taken directly from the global variable set_data. The REG_BIT flag ensures that, once the pulse duration expires, the valves are closed.

◆ regul_stop()

static void regul_stop ( uint32_t * p_reg,
uint32_t * p_ticks )
static

It provides the stopping pulse.

Parameters
p_regcommand register, involves information about system state and switching time of valves
p_ticksnumber of ticks until the pulse is stopped

Based on the sign of the polarization value, one of the valves is opened: the right valve for a positive value and the left valve for a negative value. The required pulse duration is then computed from the measured angular velocity. Pulses that are too short are ignored. By setting the REG_BIT flag, the system activates the condition that closes the valve once the computed time has elapsed.

◆ valve_close()

static void valve_close ( void )
static

Closes all valves.

◆ valve_fcn()

void valve_fcn ( uint32_t * p_reg,
float * p_set_pos )

It handles the execution of motion commands.

Parameters
p_regcommand register, involves information about system state and switching time of valves
p_set_posthe orientation is maintained by the regulation loop.

It is a state machine that selects the appropriate function based on the configuration of the command register.

Available states:

State RUN_BIT PULSE_BIT TURN_BIT HOME_BIT RETURN_BIT
START 1 1 X X X
START 1 X 1 X X
START 1 X X 1 X
FLY 1 0 0 0 X
STOP PULSE 0 1 X X X
STOP TURN 0 0 1 X X
STOP HOME 0 0 0 1 X
STOP RETURN 0 0 0 0 1

The START state indicates that a start pulse is requested. In addition to the corresponding command flag, at least one of the PULSE_BIT, TURN_BIT, or HOME_BIT flags must be set, while the RUN_BIT flag must be cleared. The valve closing time is initialized, and — based on the value of DIR_BIT — the appropriate valve is opened. After each command is executed, the value of set_pos is updated.

The STOP states occur after a pulse has been triggered and its duration has elapsed. They are selected based on the command flag that is active at that moment.

STOP PULSE is activated by the PULSE_BIT flag. In this state, the valves are simply closed and the PULSE_BIT flag is cleared.

STOP TURN is activated by the TURN_BIT flag. The required orientation is computed using set_data.angle. The TURN_BIT flag is cleared, and by setting the RUN_BIT flag, the system transitions into the FLY state.

STOP HOME is activated by the HOME_BIT flag. The required orientation is set according to set_data.home. The HOME_BIT flag is cleared, and the system enters the FLY state by setting RUN_BIT.

STOP RETURN is activated by the RETURN_BIT flag. The required orientation is set to p_set_home. The RETURN_BIT flag is cleared, and the RUN_BIT flag is set, causing a transition to the FLY state.

The FLY state is active when only the RUN_BIT flag is set. The satellite is in free flight, and the system waits until the stop condition is satisfied. Once the condition is met, the DIR_BIT flag is inverted and the duration of the stopping pulse is computed. The system then transitions to the START state with the PULSE_BIT flag set.

Definition at line 69 of file loop_fcn.c.

Variable Documentation

◆ measured_data

sensor_data_t measured_data
extern

Current sensor measured data.

Definition at line 60 of file main.c.

◆ set_data

settings_t set_data
extern

Main system settings.

Definition at line 61 of file main.c.