Skip to content

Commit

Permalink
#45: Full coverage for application, fixed initialization in timer
Browse files Browse the repository at this point in the history
  • Loading branch information
aul12 committed Jan 1, 2023
1 parent b7044b9 commit 3903c45
Show file tree
Hide file tree
Showing 6 changed files with 368 additions and 34 deletions.
12 changes: 7 additions & 5 deletions Src/Application/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@

/**
* Frequency divider between the timer interrupt and sending new messages.
* 6 * 16.384 approx 100ms
*/
enum { FLIGHTCOMPUTER_SEND_PERIOD = 6 };
enum { FLIGHTCOMPUTER_SEND_PERIOD = (uint16_t) (100 / 16.383) };

/**
* Offset from the remote data (in [0, 1000]) to the servo_motor_cmd data (in [-500, 500])
*/
enum { SERVO_REMOTE_OFFSET = 1000U / 2 };

static volatile uint8_t fcps_send_mux = 0;

static void timer_tick(void) {
imu_data_t imu_data;
remote_data_t remote_data;
Expand All @@ -51,14 +52,14 @@ static void timer_tick(void) {
actuator_cmd.elevon_left = remote_data.elevon_left_mixed - SERVO_REMOTE_OFFSET;
actuator_cmd.elevon_right = remote_data.elevon_right_mixed - SERVO_REMOTE_OFFSET;
break;
case MODE_STABILISED_FAILSAVE: {
case MODE_STABILISED_FAILSAFE: {
controller_result_t controller_result = controller_update(&imu_data, 0, 0);
actuator_cmd.elevon_left = controller_result.elevon_left;
actuator_cmd.elevon_right = controller_result.elevon_right;
actuator_cmd.motor = 0;
break;
}
case MODE_FAILSAVE:
case MODE_FAILSAFE:
actuator_cmd.motor = 0;
actuator_cmd.elevon_left = 0;
actuator_cmd.elevon_right = 0;
Expand All @@ -70,7 +71,6 @@ static void timer_tick(void) {
/*
* Send information to FCPS
*/
static volatile uint8_t fcps_send_mux = 0;
fcps_send_mux += 1;
if (fcps_send_mux >= FLIGHTCOMPUTER_SEND_PERIOD) {
flightcomputer_send(&imu_data, &remote_data, &actuator_cmd);
Expand All @@ -95,6 +95,8 @@ void application_init(void) {

system_post_init();

fcps_send_mux = 0;

while (true) {
system_reset_watchdog();
}
Expand Down
10 changes: 5 additions & 5 deletions Src/Application/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* * Error Handler initialization
* * IMU initialization
* * Remote initialization
* * Flightcomputer initialization
* * Flight-computer initialization
* * Actuator initialization
* * Mode handler initialization
* * System Post-Initialization
Expand All @@ -25,12 +25,12 @@
* The timer performs the following tasks:
* * Call the mode handler to determine the current mode
* * Calculate the actuator commands depending on the mode:
* * In flightcomputer mode: call the controller with the flightcomputer setpoint and the imu data
* * In flight-computer mode: call the controller with the flight-computer setpoint and the imu data
* and use the result as elevon commands, the motor command is taken directly from the flightcomputer setpoint
* * In remote mode: take the remote message as actuator command
* * In stabilisied failsave mode: call the controller with roll: 0, pitch: 0 as setpoint and the imu data
* * In remote mode: take the remote message as actuator command, remapping the elevons from [0, 1000] to [-500, 500]
* * In stabilised failsafe mode: call the controller with roll: 0, pitch: 0 as setpoint and the imu data
* and use the result as elevon commands, the motor command is always 0
* * In failsave mode: set all three commands to 0
* * In failsafe mode: set all three commands to 0
* * Pass the actuator commands to the actuators
* * Every FLIGHTCOMPUTER_SEND_PERIOD frame: pass the current data to flightcomputer_send
* * Call imu_start_sampling
Expand Down
6 changes: 3 additions & 3 deletions Src/Application/mode_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ mode_handler_mode_t mode_handler_handle(imu_data_t *imu_data, remote_data_t *rem
if (remote_data->is_armed) {
return MODE_FLIGHTCOMPUTER;
}
return MODE_STABILISED_FAILSAVE;
return MODE_STABILISED_FAILSAFE;
}

if (remote_active) {
return MODE_REMOTE;
}

if (imu_active) {
return MODE_STABILISED_FAILSAVE;
return MODE_STABILISED_FAILSAFE;
}

return MODE_FAILSAVE;
return MODE_FAILSAFE;
}
2 changes: 1 addition & 1 deletion Src/Application/mode_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum {
/**
* Possible flight modes depending on availability and integrity of data.
*/
typedef enum { MODE_FLIGHTCOMPUTER, MODE_REMOTE, MODE_STABILISED_FAILSAVE, MODE_FAILSAVE } mode_handler_mode_t;
typedef enum { MODE_FLIGHTCOMPUTER, MODE_REMOTE, MODE_STABILISED_FAILSAFE, MODE_FAILSAFE } mode_handler_mode_t;

/**
* Initialize the mode handler by setting the timeouts for all devices to true.
Expand Down
Loading

0 comments on commit 3903c45

Please sign in to comment.