nakujaproject / N4-Recovery

RND for N4 recovery team
2 stars 1 forks source link

eliminate magic numbers in state macines conditions check #26

Open bytecod3 opened 4 months ago

bytecod3 commented 4 months ago

Powered flight transition

Initial proposal was to measure a countdown based on the ignition time. To transition to powered flight, we count down from say 5 seconds countdown. After this, the FC(flight computer) automatically switches to powered flight. if(countdown_timer > 5) state = powered_flight

Problem

However, this is a magic number that can vary greatly based on the class of the motor being used, and if it is hardcoded into the software, it will be difficult to determine accurately during launch

Proposed method

A better method to use is to measure the altitude from ground. If the altitude is above say 50m, then the rocket MUST be in powered flight. This altitude can be got from the altimeter being used.

PWRD_FLGHT_THRESHOLD = 50; // meters
altitude = altimeter.getAltitude();
rocket_altitude =  current_altitude - base_altitude;
if ( rocket_altitude > PWRD_FLGHT_THRESHOLD) state = powered_flight; 

Drogue parachute transition

To deploy the parachute, we have to wait for some seconds after apogee is detected. After max_height of the rocket, the rocket should be coming down. once this max height is detected, start a countdown timer. Actually start a countdown timer for each max value received from the altimeter. the software will have to reset the countdown timer for each max value detected.

proposed algorithm for drougue deploy
// measure current altitude 
current_altitude = altimeter.getAltitude();
max_val = current_altitude;

// timer.start();

// read the altitude again
// log this new  max value
// compare the original max_value and this current one 
if(current_max_val > max_value) {
    timer.restart();
    max_value = current_max_value
} else {
   // at this point, the max_value has been reached and the rocket is going down
  // check if the the timer has exceeded the countdown to drogue deploy
    if(timer_val > 5 seconds) {
         // eject drogue parachute
         drogue.eject()
    }
}
Swooping-Evil commented 4 months ago

Drogue Deploy

Another issue we need to consider is the natural delay time it takes for the parachute to deploy once the eject command has been delivered. This delay may make any other coded delays (such as the timer) seem redundant.