mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-05 22:24:47 +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:
@@ -45,11 +45,12 @@
|
|||||||
NavigatorMode::NavigatorMode(Navigator *navigator, const char *name) :
|
NavigatorMode::NavigatorMode(Navigator *navigator, const char *name) :
|
||||||
SuperBlock(navigator, name),
|
SuperBlock(navigator, name),
|
||||||
_navigator(navigator),
|
_navigator(navigator),
|
||||||
_first_run(true)
|
_active(false)
|
||||||
{
|
{
|
||||||
/* load initial params */
|
/* load initial params */
|
||||||
updateParams();
|
updateParams();
|
||||||
/* set initial mission items */
|
/* set initial mission items */
|
||||||
|
on_inactivation();
|
||||||
on_inactive();
|
on_inactive();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,10 +58,8 @@ void
|
|||||||
NavigatorMode::run(bool active)
|
NavigatorMode::run(bool active)
|
||||||
{
|
{
|
||||||
if (active) {
|
if (active) {
|
||||||
if (_first_run) {
|
if (!_active) {
|
||||||
/* first run */
|
/* first run, reset stay in failsafe flag */
|
||||||
_first_run = false;
|
|
||||||
/* Reset stay in failsafe flag */
|
|
||||||
_navigator->get_mission_result()->stay_in_failsafe = false;
|
_navigator->get_mission_result()->stay_in_failsafe = false;
|
||||||
_navigator->set_mission_result_updated();
|
_navigator->set_mission_result_updated();
|
||||||
on_activation();
|
on_activation();
|
||||||
@@ -72,9 +71,15 @@ NavigatorMode::run(bool active)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* periodic updates when inactive */
|
/* periodic updates when inactive */
|
||||||
_first_run = true;
|
if (_active) {
|
||||||
on_inactive();
|
on_inactivation();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
on_inactive();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_active = active;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -82,6 +87,11 @@ NavigatorMode::on_inactive()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
NavigatorMode::on_inactivation()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
NavigatorMode::on_activation()
|
NavigatorMode::on_activation()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -69,10 +69,15 @@ public:
|
|||||||
virtual void on_inactive();
|
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();
|
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
|
* This function is called while the mode is active
|
||||||
*/
|
*/
|
||||||
@@ -82,7 +87,7 @@ protected:
|
|||||||
Navigator *_navigator{nullptr};
|
Navigator *_navigator{nullptr};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _first_run{true};
|
bool _active{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user