Skip to content

Commit 3903c45

Browse files
committed
#45: Full coverage for application, fixed initialization in timer
1 parent b7044b9 commit 3903c45

File tree

6 files changed

+368
-34
lines changed

6 files changed

+368
-34
lines changed

Src/Application/application.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818

1919
/**
2020
* Frequency divider between the timer interrupt and sending new messages.
21-
* 6 * 16.384 approx 100ms
2221
*/
23-
enum { FLIGHTCOMPUTER_SEND_PERIOD = 6 };
22+
enum { FLIGHTCOMPUTER_SEND_PERIOD = (uint16_t) (100 / 16.383) };
2423

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

29+
static volatile uint8_t fcps_send_mux = 0;
30+
3031
static void timer_tick(void) {
3132
imu_data_t imu_data;
3233
remote_data_t remote_data;
@@ -51,14 +52,14 @@ static void timer_tick(void) {
5152
actuator_cmd.elevon_left = remote_data.elevon_left_mixed - SERVO_REMOTE_OFFSET;
5253
actuator_cmd.elevon_right = remote_data.elevon_right_mixed - SERVO_REMOTE_OFFSET;
5354
break;
54-
case MODE_STABILISED_FAILSAVE: {
55+
case MODE_STABILISED_FAILSAFE: {
5556
controller_result_t controller_result = controller_update(&imu_data, 0, 0);
5657
actuator_cmd.elevon_left = controller_result.elevon_left;
5758
actuator_cmd.elevon_right = controller_result.elevon_right;
5859
actuator_cmd.motor = 0;
5960
break;
6061
}
61-
case MODE_FAILSAVE:
62+
case MODE_FAILSAFE:
6263
actuator_cmd.motor = 0;
6364
actuator_cmd.elevon_left = 0;
6465
actuator_cmd.elevon_right = 0;
@@ -70,7 +71,6 @@ static void timer_tick(void) {
7071
/*
7172
* Send information to FCPS
7273
*/
73-
static volatile uint8_t fcps_send_mux = 0;
7474
fcps_send_mux += 1;
7575
if (fcps_send_mux >= FLIGHTCOMPUTER_SEND_PERIOD) {
7676
flightcomputer_send(&imu_data, &remote_data, &actuator_cmd);
@@ -95,6 +95,8 @@ void application_init(void) {
9595

9696
system_post_init();
9797

98+
fcps_send_mux = 0;
99+
98100
while (true) {
99101
system_reset_watchdog();
100102
}

Src/Application/application.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* * Error Handler initialization
1515
* * IMU initialization
1616
* * Remote initialization
17-
* * Flightcomputer initialization
17+
* * Flight-computer initialization
1818
* * Actuator initialization
1919
* * Mode handler initialization
2020
* * System Post-Initialization
@@ -25,12 +25,12 @@
2525
* The timer performs the following tasks:
2626
* * Call the mode handler to determine the current mode
2727
* * Calculate the actuator commands depending on the mode:
28-
* * In flightcomputer mode: call the controller with the flightcomputer setpoint and the imu data
28+
* * In flight-computer mode: call the controller with the flight-computer setpoint and the imu data
2929
* and use the result as elevon commands, the motor command is taken directly from the flightcomputer setpoint
30-
* * In remote mode: take the remote message as actuator command
31-
* * In stabilisied failsave mode: call the controller with roll: 0, pitch: 0 as setpoint and the imu data
30+
* * In remote mode: take the remote message as actuator command, remapping the elevons from [0, 1000] to [-500, 500]
31+
* * In stabilised failsafe mode: call the controller with roll: 0, pitch: 0 as setpoint and the imu data
3232
* and use the result as elevon commands, the motor command is always 0
33-
* * In failsave mode: set all three commands to 0
33+
* * In failsafe mode: set all three commands to 0
3434
* * Pass the actuator commands to the actuators
3535
* * Every FLIGHTCOMPUTER_SEND_PERIOD frame: pass the current data to flightcomputer_send
3636
* * Call imu_start_sampling

Src/Application/mode_handler.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,16 @@ mode_handler_mode_t mode_handler_handle(imu_data_t *imu_data, remote_data_t *rem
9393
if (remote_data->is_armed) {
9494
return MODE_FLIGHTCOMPUTER;
9595
}
96-
return MODE_STABILISED_FAILSAVE;
96+
return MODE_STABILISED_FAILSAFE;
9797
}
9898

9999
if (remote_active) {
100100
return MODE_REMOTE;
101101
}
102102

103103
if (imu_active) {
104-
return MODE_STABILISED_FAILSAVE;
104+
return MODE_STABILISED_FAILSAFE;
105105
}
106106

107-
return MODE_FAILSAVE;
107+
return MODE_FAILSAFE;
108108
}

Src/Application/mode_handler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ enum {
2424
/**
2525
* Possible flight modes depending on availability and integrity of data.
2626
*/
27-
typedef enum { MODE_FLIGHTCOMPUTER, MODE_REMOTE, MODE_STABILISED_FAILSAVE, MODE_FAILSAVE } mode_handler_mode_t;
27+
typedef enum { MODE_FLIGHTCOMPUTER, MODE_REMOTE, MODE_STABILISED_FAILSAFE, MODE_FAILSAFE } mode_handler_mode_t;
2828

2929
/**
3030
* Initialize the mode handler by setting the timeouts for all devices to true.

0 commit comments

Comments
 (0)