-
Notifications
You must be signed in to change notification settings - Fork 13.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement ModuleParams inheritance and DEFINE_PARAMETERS in the LandDetector class #12209
Merged
+51
−38
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
aabe8da
Refactor the LandDetector class to
mcsauder 55d52c4
Delete _measure_interval and redundant parentheses in LandDetector.h.
mcsauder bf67344
Revert changes to the check_params(const bool force) declaration/defi…
mcsauder a0d3f51
Add check_params(true) call to the LandDetector start() method. Break…
mcsauder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Refactor the LandDetector class to
- Reduce duplicate code in LandDetector _check_params() method. - Standardize naming cases. - Implement DEFINE_PARAMETERS() macro.
commit aabe8da5ecf1bfe33ae9dbc14052f904c9c56bdc
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -43,6 +43,7 @@ | |||||
#pragma once | ||||||
|
||||||
#include <px4_module.h> | ||||||
#include <px4_module_params.h> | ||||||
#include <lib/hysteresis/hysteresis.h> | ||||||
#include <parameters/param.h> | ||||||
#include <perf/perf_counter.h> | ||||||
|
@@ -57,7 +58,7 @@ using namespace time_literals; | |||||
namespace land_detector | ||||||
{ | ||||||
|
||||||
class LandDetector : public ModuleBase<LandDetector>, px4::ScheduledWorkItem | ||||||
class LandDetector : public ModuleBase<LandDetector>, ModuleParams, px4::ScheduledWorkItem | ||||||
{ | ||||||
public: | ||||||
enum class LandDetectionState { | ||||||
|
@@ -71,7 +72,6 @@ class LandDetector : public ModuleBase<LandDetector>, px4::ScheduledWorkItem | |||||
LandDetector(); | ||||||
virtual ~LandDetector(); | ||||||
|
||||||
static int task_spawn(int argc, char *argv[]); | ||||||
|
||||||
/** @see ModuleBase */ | ||||||
static int custom_command(int argc, char *argv[]) | ||||||
|
@@ -88,27 +88,26 @@ class LandDetector : public ModuleBase<LandDetector>, px4::ScheduledWorkItem | |||||
/** | ||||||
* @return current state. | ||||||
*/ | ||||||
LandDetectionState get_state() const | ||||||
{ | ||||||
return _state; | ||||||
} | ||||||
LandDetectionState get_state() const { return _state; } | ||||||
|
||||||
/** | ||||||
* Get the work queue going. | ||||||
*/ | ||||||
void start(); | ||||||
|
||||||
static int task_spawn(int argc, char *argv[]); | ||||||
|
||||||
protected: | ||||||
|
||||||
/** | ||||||
* Update uORB topics. | ||||||
* Update parameters. | ||||||
*/ | ||||||
virtual void _update_topics() = 0; | ||||||
virtual void _update_params() = 0; | ||||||
|
||||||
/** | ||||||
* Update parameters. | ||||||
* Update uORB topics. | ||||||
*/ | ||||||
virtual void _update_params() = 0; | ||||||
virtual void _update_topics() = 0; | ||||||
|
||||||
/** | ||||||
* @return true if UAV is in a landed state. | ||||||
|
@@ -143,7 +142,7 @@ class LandDetector : public ModuleBase<LandDetector>, px4::ScheduledWorkItem | |||||
/** Run main land detector loop at this interval. */ | ||||||
static constexpr uint32_t LAND_DETECTOR_UPDATE_INTERVAL = 20_ms; | ||||||
|
||||||
orb_advert_t _landDetectedPub{nullptr}; | ||||||
orb_advert_t _land_detected_pub{nullptr}; | ||||||
vehicle_land_detected_s _landDetected{}; | ||||||
|
||||||
LandDetectionState _state{LandDetectionState::LANDED}; | ||||||
|
@@ -154,26 +153,33 @@ class LandDetector : public ModuleBase<LandDetector>, px4::ScheduledWorkItem | |||||
systemlib::Hysteresis _ground_contact_hysteresis{true}; | ||||||
systemlib::Hysteresis _ground_effect_hysteresis{false}; | ||||||
|
||||||
struct actuator_armed_s _arming {}; | ||||||
actuator_armed_s _arming {}; | ||||||
|
||||||
private: | ||||||
void Run() override; | ||||||
|
||||||
void _check_params(bool force = false); | ||||||
void _check_params(); | ||||||
|
||||||
void Run() override; | ||||||
|
||||||
void _update_state(); | ||||||
|
||||||
param_t _p_total_flight_time_high{PARAM_INVALID}; | ||||||
param_t _p_total_flight_time_low{PARAM_INVALID}; | ||||||
bool _previous_armed_state{false}; ///< stores the previous actuator_armed.armed state | ||||||
|
||||||
uint32_t _measure_interval{LAND_DETECTOR_UPDATE_INTERVAL}; | ||||||
bkueng marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
uint64_t _total_flight_time{0}; ///< in microseconds | ||||||
|
||||||
hrt_abstime _takeoff_time{0}; | ||||||
|
||||||
perf_counter_t _cycle_perf; | ||||||
perf_counter_t _cycle_perf{(perf_alloc(PC_ELAPSED, "land_detector_cycle"))}; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed! Thanks for spotting that! |
||||||
|
||||||
bool _previous_arming_state{false}; ///< stores the previous _arming.armed state | ||||||
uORB::Subscription _actuator_armed_sub{ORB_ID(actuator_armed)}; | ||||||
uORB::Subscription _param_update_sub{ORB_ID(parameter_update)}; | ||||||
|
||||||
uORB::Subscription _parameterSub{ORB_ID(parameter_update)}; | ||||||
uORB::Subscription _armingSub{ORB_ID(actuator_armed)}; | ||||||
DEFINE_PARAMETERS( | ||||||
(ParamInt<px4::params::LND_FLIGHT_T_HI>) _param_total_flight_time_high, | ||||||
(ParamInt<px4::params::LND_FLIGHT_T_LO>) _param_total_flight_time_low | ||||||
); | ||||||
}; | ||||||
|
||||||
} // namespace land_detector |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is
force
removed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Beat, thanks for your review! I removed
force
becausecheck_params()
is private, so we know nothing outside of the class is utilizing it, and the only place it now gets called is settingforce
tofalse
, so it has become unneeded.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs to be called with
force=true
here: https://github.com/PX4/Firmware/pull/12209/files#diff-1fd2cab203a1ba1c362f2dd76a74542fL84. Otherwise_total_flight_time
does not necessarily get initialized. This only worked because there were other param changes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Beat. So this is broken in current master? I have to admit that I'm a little confused, in the tests I show above only the
LAND_FLIGHT_T_HI
andLAND_FLIGHT_T_LO
are changed, no others. It is also verifiable with no parameter chances in the flight logs below. I'll gladly revert this change though if it's important.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. We always have other param changes at the end of a flight, which is why it worked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @bkueng. I pushed up a commit that calls
_check_params(true)
within the constructor so that it gets initialized once as used to be the case prior to 106ee28.Let me know if you think this is appropriate, and otherwise, if it needs to be forced at each
Run()
call, we can deprecate the bool arg and theif
statement so that_check_params()
can be effectively an_update_params()
call each iteration.EDITED ABOVE - call moved to the constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bkueng , moving to the constructor absolutely breaks the detector. I am removing it and squashing that commit out of existence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @bkueng, placing the call back in the
start()
method works fine and I think will satisfy the concerns. Latest commit functions fine, flight tested here: https://review.px4.io/plot_app?log=cdc782c2-9999-4f49-a98a-2de786ce5c6fLet me know if you have any other thoughts! Thanks again for your review!