Skip to content

Commit

Permalink
add guidance loop to 'new' control
Browse files Browse the repository at this point in the history
all this guidance code should really be better factorized
  • Loading branch information
gautierhattenberger committed Apr 20, 2017
1 parent 59c5a23 commit 9e57986
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions conf/modules/guidance_full_pid_fw.xml
Expand Up @@ -75,10 +75,12 @@
</settings>
<header>
<file name="guidance_v_n.h"/>
<file name="guidance_h.h"/>
</header>
<init fun="v_ctl_init()"/>
<makefile target="ap|sim|nps" firmware="fixedwing">
<file name="guidance_v_n.c" dir="$(SRC_FIRMWARE)/guidance"/>
<file name="guidance_h.c" dir="$(SRC_FIRMWARE)/guidance"/>
<define name="CTRL_TYPE_H" value="firmwares/fixedwing/guidance/guidance_v_n.h" type="string"/>
</makefile>
</module>
38 changes: 38 additions & 0 deletions sw/airborne/firmwares/fixedwing/guidance/guidance_v_n.c
Expand Up @@ -179,6 +179,44 @@ void v_ctl_init(void)
v_ctl_throttle_setpoint = 0;
}

void v_ctl_guidance_loop(void)
{
if (v_ctl_mode == V_CTL_MODE_AUTO_ALT) {
v_ctl_altitude_loop();
}
#if CTRL_VERTICAL_LANDING
if (v_ctl_mode == V_CTL_MODE_LANDING) {
v_ctl_landing_loop();
} else {
#endif
if (v_ctl_mode == V_CTL_MODE_AUTO_THROTTLE) {
v_ctl_throttle_setpoint = nav_throttle_setpoint;
v_ctl_pitch_setpoint = nav_pitch;
} else {
if (v_ctl_mode >= V_CTL_MODE_AUTO_CLIMB) {
v_ctl_climb_loop();
} /* v_ctl_mode >= V_CTL_MODE_AUTO_CLIMB */
} /* v_ctl_mode == V_CTL_MODE_AUTO_THROTTLE */
#if CTRL_VERTICAL_LANDING
} /* v_ctl_mode == V_CTL_MODE_LANDING */
#endif

#if defined V_CTL_THROTTLE_IDLE
Bound(v_ctl_throttle_setpoint, TRIM_PPRZ(V_CTL_THROTTLE_IDLE * MAX_PPRZ), MAX_PPRZ);
#endif

#ifdef V_CTL_POWER_CTL_BAT_NOMINAL
if (vsupply > 0.) {
v_ctl_throttle_setpoint *= 10. * V_CTL_POWER_CTL_BAT_NOMINAL / (float)vsupply;
v_ctl_throttle_setpoint = TRIM_UPPRZ(v_ctl_throttle_setpoint);
}
#endif

if (autopilot.kill_throttle || (!autopilot.flight_time && !autopilot.launch)) {
v_ctl_throttle_setpoint = 0;
}
}

/**
* outer loop
* \brief Computes v_ctl_climb_setpoint and sets v_ctl_auto_throttle_submode
Expand Down

0 comments on commit 9e57986

Please sign in to comment.