diff --git a/README.md b/README.md index 649abc155c4656ffc1e716f3769e3746bc2eedd5..cec57fe67ae0fb07fb9289157eed3c83056c3b1e 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ -# GNC Recruitment Assigment +# GNC Recruitment Assignment -In this assigment, the goal is to create algorithm able to detect the apogee of the rocket during the flight and comand the opening of the parachute. +In this assignment, the goal is to create algorithm able to detect the apogee of the rocket during a generic flight and command the opening of the parachute. The file `main.m` load the logs of a previous flight and then simulates the flight of the rocket. The first part of the script logs the logs of the sensors of a previous flight which will be then used for the simulation. -The second part replicates how the on-board software interacts with the sensors, at each iteration the script gets new sensor measurments and pass them to the function `apogee_detector.m`, which detects the apogee and, on the real rocket, commands the explultion of the parachute. The avaliable sensor measurments are a barometer, a 6-axis IMU (accelerometer and gyroscope) and a GPS. +The second part replicates how the on-board software interacts with the sensors, at each iteration the script gets new sensor measurements and pass them to the function `apogee_detector.m`, which detects the apogee and, on the real rocket, commands the expulsion of the parachute. The available sensor measurements are a barometer, a 6-axis IMU (accelerometer and gyroscope) and a GPS. The third part is used just to plot the result and display the apogee detection. -Your task is to develop the function `apogee_detector.m` : +**Your task is to develop the function `apogee_detector.m` :** ```matlab function [ flag_apogee, data] = apogee_detector( pressure_measurment, IMU_measurment, GPS_measurment, data) @@ -16,34 +16,46 @@ function [ flag_apogee, data] = apogee_detector( pressure_measurment, IMU_measur % insert your code here ``` -which uses the datas measured during the flight as input and outputs the boolean variable `flag_apogee`, which must be: +which uses the data measured in real time during the flight as input and outputs the boolean variable `flag_apogee`, which must be: -* 1 during the instants where the rocket is at the apogee +* 1 during the instants where the rocket is considered to be at the apogee * 0 otherwise -This algorithm is safe critical, because the detection of the apogeee comands the opening of the parachute. So the algorithm that you will develop should be resilient and work even in off nominal conditions where: +## How organize the work -* the apogeee height may change from the one contained in the logs -* the trajectory of the rocket may change from the one contained in the logs -* unexpected faults may happen +To organize the work, it's suggested to divide it in 2 tasks: -To take into acount these factors, the function that you will submit will be tested with the logs of a different flight. +1. **Define what's it is the apogee**: of course the apogee can be defined as the point of the trajectory where the vertical velocity is 0, but this definition is not applicable. Sensors have noise that disturbs the measurements, even at apogee the vertical velocity estimated is never equal to 0. Instead of detecting the exact instant of the apogee, it suggested to **define a region of the trajectory** where **it is reasonable** to assume that the rocket is at the apogee, or near it, and detect the apogee when the rocket enters in that region. **Finding the condition/conditions that define that region is part of the assignment**. + *(For example, the function detects the apogee when the altitude is > of 2700m. This condition define a zone that, in the logged flight, is near the apogee... but what happens if the rocket never reaches 2700m ? Or if at that altitude it is still moving with high vertical speed? This condition might work for this flight, but is not reliable in a general case and it is considered a bad choice. )* +2. **Implement an algorithm that detects the apogee**: starting from the definition of apogee found in the previous point, implement an algorithm in `apogee_detector.m` that detects the apogee. -**data:** it is a support variable that you can use if and however you want. It is declared inside `main.m`; if you want to use it you have to declare it there, otherwise you can just leave it as it is. +## Algorithm requirements -**pressure_measurment:** the barometer is used to measure the atmosferic pressure during the flight +This algorithm is safe critical, because the detection of the apogee commands the opening of the parachute. The algorithm that you will develop should be **resilient and work even in off nominal conditions** where: + +* **the apogee altitude might change** from the one contained in the logs, depending on the flight conditions. The motor might under-perform or over-perform with respect to the nominal condition, so it not possible to define *a priori* the exact altitude of the apogee. In addition, the target apogee height could also change from flight to flight. +* **the trajectory of the rocket may change** from the one contained in the logs. Wind or other external phenomenons will *slightly* change the trajectory. Also, launches with different target apogee altitudes (a.e 3 Km vs 9 Km) will have different trajectories. +* **sensors measurements are not perfect**. As said before, sensors are subjected to noise and delays which alter the measurements. This phenomenon is also visible from the logs. + +To take into account these factors, the function that you will submit will be tested with the logs of a different flight. + +## Input variables + +**data:** it is a support variable that you can use if and however you want, for example it could store previous sensors measurements or counters. It is declared inside `main.m`; if you want to use it you have to declare it there, otherwise you can just leave it as it is. + +**pressure_measurement:** the barometer is used to measure the atmospheric pressure during the flight | pressure | | :------: | | Pa | -**IMU_measurment:** the reference axis are the body-axis of the rocket. +**IMU_measurement:** the reference axis are the body-axis of the rocket. | acceleration_X | acceleration_Y | acceleration_Z | angular_speed_X | angular_speed_Y | angular_speed_Z | | :------------: | :------------: | :------------: | :-------------: | :-------------: | :-------------: | | m/s^2 | m/s^2 | m/s^2 | rad/s | rad/s | rad/s | -**GPS_measurment:** +**GPS_measurement:** | latitude | longitude | altitude (from sea level) | | :-------------: | --------------- | :-----------------------: | diff --git a/apogee_detector.m b/apogee_detector.m index 76d905f5cdee220d1a2e28b288fbb460b3d71e8b..066c0fc073ba00237e3c69c105ff3c45dbf9c180 100644 --- a/apogee_detector.m +++ b/apogee_detector.m @@ -1,7 +1,7 @@ function [flag_apogee, data] = apogee_detector(pressure_measurment, IMU_measurment, GPS_measurment, data) %{ ------DESCRIPTION OF INPUT MEASURMENTS----- +-----DESCRIPTION OF INPUT MEASUREMENTS----- pressure_measurment(1) = pressure [Pa] @@ -13,10 +13,10 @@ IMU_measurment(5) = angular speed along rocket Y axis [rad/s] IMU_measurment(6) = angular speed along rocket Z axis [rad/s] GPS_measurments(1) = latitude -GPS_measurments(2) = latitude +GPS_measurments(2) = longitude GPS_measurments(3) = altitude from sea level [m] ------DESCRIPTION OF OUTPUT VARIABLES----- +-----DESCRIPTION OF OUTPUT VARIABLE----- flag_apogee = boolean variable which MUST be set by this function to: - 1 if the rocket is at the apogee @@ -25,7 +25,14 @@ flag_apogee = boolean variable which MUST be set by this function to: %} - +%%%% EXAMPLE OF (BAD) IMPLEMENTATION, just to see how flag_apogee should be set +% if GPS_measurment(3) > 2700 +% flag_apogee = 1; +% else +% flag_apogee = 0; +% end +%%%% + % Insert here the code diff --git a/main.m b/main.m index 50f7c8cbb09232b39591dd2ee48e59d6dbba08f8..d5cef2d2c1bea51a510a54d1b4cac6d3bc0694c0 100644 --- a/main.m +++ b/main.m @@ -21,7 +21,7 @@ flag_apogee = 0; apogee_time = -1; % Simulation -for t = 0:20000:300*1e6 +for t = 0:2000:300*1e6 % Getting measurment form sensors pressure_measurment = baro(floor(t/dt_baro)+1,2); @@ -44,36 +44,49 @@ if apogee_time < 0 error("The apogee time is negative") end +lift_off_time = 102.4; %[s] +landing_time = 232.406; %[s] + % Plot baro figure; plot(baro(:,1)/1e6, baro(:,2) ); -grid minor; xlabel('time'); ylabel('Pa'); +grid minor; xlabel('time [s]'); ylabel('Pa'); xline(apogee_time/1e6, '--', "apogee"); +xline(lift_off_time, '-', "lift off"); +xline(landing_time, '-', "landing"); title('Barometer') % Plot accelerometer figure(); subplot(3,1,1); plot(IMU(:,1)/1e6, IMU(:,2) ); -grid minor; xlabel('time'); ylabel('m/s^2'); +grid minor; xlabel('time [s]'); ylabel('m/s^2'); xline(apogee_time/1e6, '--', "apogee"); +xline(lift_off_time, '-', "lift off"); +xline(landing_time, '-', "landing"); title('Accelerometer X') subplot(3,1,2); plot(IMU(:,1)/1e6, IMU(:,3) ); -grid minor; xlabel('time'); ylabel('m/s^2'); +grid minor; xlabel('time [s]'); ylabel('m/s^2'); xline(apogee_time/1e6, '--', "apogee"); +xline(lift_off_time, '-', "lift off"); +xline(landing_time, '-', "landing"); title('Accelerometer Y') subplot(3,1,3); plot(IMU(:,1)/1e6, IMU(:,4) ); -grid minor; xlabel('time'); ylabel('m/s^2'); +grid minor; xlabel('time [s]'); ylabel('m/s^2'); xline(apogee_time/1e6, '--', "apogee"); +xline(lift_off_time, '-', "lift off"); +xline(landing_time, '-', "landing"); title('Accelerometer Z') % Plot GPS figure(); plot(GPS(:,1)/1e6, GPS(:,4) ); -grid minor; xlabel('time'); ylabel('m'); +grid minor; xlabel('time [s]'); ylabel('m'); xline(apogee_time/1e6, '--', "apogee"); -title('GPS height') \ No newline at end of file +xline(lift_off_time, '-', "lift off"); +xline(landing_time, '-', "landing"); +title('GPS height')