mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-01 15:24:08 +08:00
Navigator: Add on_inactivation() interface.
This allows to run a command / function once when being deactivated. This avoids having flight modes which are not active run unnecessary code all the time.
This commit is contained in:
parent
0f8f5d29be
commit
447c167d3e
@ -45,11 +45,12 @@
|
||||
NavigatorMode::NavigatorMode(Navigator *navigator, const char *name) :
|
||||
SuperBlock(navigator, name),
|
||||
_navigator(navigator),
|
||||
_first_run(true)
|
||||
_active(false)
|
||||
{
|
||||
/* load initial params */
|
||||
updateParams();
|
||||
/* set initial mission items */
|
||||
on_inactivation();
|
||||
on_inactive();
|
||||
}
|
||||
|
||||
@ -57,10 +58,8 @@ void
|
||||
NavigatorMode::run(bool active)
|
||||
{
|
||||
if (active) {
|
||||
if (_first_run) {
|
||||
/* first run */
|
||||
_first_run = false;
|
||||
/* Reset stay in failsafe flag */
|
||||
if (!_active) {
|
||||
/* first run, reset stay in failsafe flag */
|
||||
_navigator->get_mission_result()->stay_in_failsafe = false;
|
||||
_navigator->set_mission_result_updated();
|
||||
on_activation();
|
||||
@ -72,9 +71,15 @@ NavigatorMode::run(bool active)
|
||||
|
||||
} else {
|
||||
/* periodic updates when inactive */
|
||||
_first_run = true;
|
||||
on_inactive();
|
||||
if (_active) {
|
||||
on_inactivation();
|
||||
|
||||
} else {
|
||||
on_inactive();
|
||||
}
|
||||
}
|
||||
|
||||
_active = active;
|
||||
}
|
||||
|
||||
void
|
||||
@ -82,6 +87,11 @@ NavigatorMode::on_inactive()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
NavigatorMode::on_inactivation()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
NavigatorMode::on_activation()
|
||||
{
|
||||
|
||||
@ -69,10 +69,15 @@ public:
|
||||
virtual void on_inactive();
|
||||
|
||||
/**
|
||||
* This function is called one time when mode become active, pos_sp_triplet must be initialized here
|
||||
* This function is called one time when mode becomes active, pos_sp_triplet must be initialized here
|
||||
*/
|
||||
virtual void on_activation();
|
||||
|
||||
/**
|
||||
* This function is called one time when mode becomes inactive
|
||||
*/
|
||||
virtual void on_inactivation();
|
||||
|
||||
/**
|
||||
* This function is called while the mode is active
|
||||
*/
|
||||
@ -82,7 +87,7 @@ protected:
|
||||
Navigator *_navigator{nullptr};
|
||||
|
||||
private:
|
||||
bool _first_run{true};
|
||||
bool _active{false};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user