-
Notifications
You must be signed in to change notification settings - Fork 4
[WIP]Feature/pixy parser #43
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
base: master-0.4
Are you sure you want to change the base?
Changes from all commits
4224d0f
9f1cced
7fc24b1
069b7f6
9262b4c
72f2db7
dbbed62
fe2e771
f73a0e9
2e54c88
fbdace8
678deb4
d708c47
450780d
d68e06e
994bcc5
c01757e
38ebe77
375834c
3b522dc
cfb4535
704cb71
2cf6299
d433453
12ff4e2
6b3f480
ca1fe8b
38ebfae
6a77ae0
9886d14
849b610
59575de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,8 @@ | |
| #include <AP_UAVCAN/AP_UAVCAN.h> | ||
| #endif | ||
|
|
||
| //param show PLND_type | ||
|
|
||
| extern const AP_HAL::HAL& hal; | ||
|
|
||
| const AP_Param::GroupInfo AC_PrecLand::var_info[] = { | ||
|
|
@@ -178,8 +180,7 @@ void AC_PrecLand::update(float rangefinder_alt_cm, bool rangefinder_alt_valid) | |
| } | ||
| } | ||
|
|
||
| bool AC_PrecLand::target_acquired() | ||
| { | ||
| bool AC_PrecLand::target_acquired() { | ||
| if ((AP_HAL::millis()-_last_update_ms) >= 2000) { | ||
| _estimator_initialized = false; | ||
| _target_acquired = false; | ||
|
|
@@ -188,6 +189,17 @@ bool AC_PrecLand::target_acquired() | |
| return _target_acquired; | ||
| } | ||
|
|
||
| void AC_PrecLand::set_target_acquired(bool _target_acquired_value) { | ||
|
Contributor
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. why use an _ prefix on the variable name for a function? |
||
| if (_target_acquired_value == false) { | ||
| _target_acquired = _target_acquired_value; | ||
| _estimator_initialized = false; | ||
| } | ||
| else { | ||
| _target_acquired = _target_acquired_value; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| bool AC_PrecLand::get_height_above_target_cm(int32_t& ret) { | ||
| #if !HAL_WITH_UAVCAN | ||
| return false; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ class AC_PrecLand_Backend | |
| { | ||
| public: | ||
| // Constructor | ||
| AC_PrecLand_Backend(const AC_PrecLand& frontend, AC_PrecLand::precland_state& state) : | ||
| AC_PrecLand_Backend(AC_PrecLand& frontend, AC_PrecLand::precland_state& state) : | ||
|
Contributor
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. why remove the const? Better to expose the data you want in the state struct |
||
| _frontend(frontend), | ||
| _state(state) {} | ||
|
|
||
|
|
@@ -43,6 +43,6 @@ class AC_PrecLand_Backend | |
| int8_t get_bus(void) const { return _frontend._bus.get(); } | ||
|
|
||
| protected: | ||
| const AC_PrecLand& _frontend; // reference to precision landing front end | ||
| AC_PrecLand& _frontend; // reference to precision landing front end | ||
|
Contributor
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. should leave const alone |
||
| AC_PrecLand::precland_state &_state; // reference to this instances state | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,59 @@ | ||
|
|
||
| #include <AP_HAL/AP_HAL.h> | ||
| #include "AC_PrecLand_IRLock.h" | ||
| #include <GCS_MAVLink/GCS.h> | ||
|
|
||
| extern const AP_HAL::HAL& hal; | ||
|
|
||
| // Constructor | ||
| AC_PrecLand_IRLock::AC_PrecLand_IRLock(const AC_PrecLand& frontend, AC_PrecLand::precland_state& state) | ||
| AC_PrecLand_IRLock::AC_PrecLand_IRLock(AC_PrecLand& frontend, AC_PrecLand::precland_state& state) | ||
| : AC_PrecLand_Backend(frontend, state), | ||
| irlock(), | ||
| _have_los_meas(false), | ||
| _los_meas_time_ms(0) | ||
| _los_meas_time_ms(0), | ||
|
Contributor
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. we don't actually need to initialise values to 0 or false, as it happens automatically (as we override memory allocation with a function that zeros memory) |
||
| _multiple_target_timestamp_log(), | ||
| _index(0) | ||
| { | ||
| } | ||
|
|
||
| // init - perform initialisation of this backend | ||
| void AC_PrecLand_IRLock::init() | ||
| void AC_PrecLand_IRLock::init() | ||
|
Contributor
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. added extra whitespace? |
||
| { | ||
| irlock.init(get_bus()); | ||
| } | ||
|
|
||
| //multiple_target_check - Checks if multiple targets detected for 500 ms continously. If yes, sets target_acquired=False which calls contingency landing | ||
| void AC_PrecLand_IRLock::multiple_target_check() | ||
| { | ||
| if (_index == 24) { | ||
|
Contributor
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. magic value 24? Maybe you means ARRAY_SIZE(_multiple_target_timestamp_log) or add a #define for it?
Contributor
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. also, why 24 anyway? Array is 25 long, so shouldn't we set to zero if value is 25? |
||
| _index = 0; | ||
| } | ||
| _multiple_target_timestamp_log[_index] = irlock.num_targets(); | ||
| _index++; | ||
|
|
||
| /* | ||
| printf("\n _multiple_target_timestamp_log: "); | ||
| for (size_t j=0; j<24; j++) { | ||
| printf("%u ", _multiple_target_timestamp_log[j]); | ||
| } | ||
| */ | ||
| size_t count = 0; | ||
| for (size_t j=0; j<24; j++) { | ||
|
Contributor
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. why is j size_t ? more magic values of 24 which look wrong |
||
| if (_multiple_target_timestamp_log[j] > 1) { | ||
| count++; | ||
| } | ||
| } | ||
| uint16_t multiple_target_count_percentage = count*100/25; | ||
| // printf("\nCount: %u -- Multiple_target_count_percentage: %u", irlock.num_targets(), multiple_target_count_percentage); | ||
| if (multiple_target_count_percentage >= 80) { | ||
|
Contributor
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. why is 80% the threshold? |
||
| // printf("\n----------------------------------------------------------------------HIGH COUNT PERCENTAGE: %u ------setting TARGET ACQUIRED FALSE -- %", multiple_target_count_percentage); | ||
| gcs().send_text(MAV_SEVERITY_CRITICAL, "Multiple Targets Detected"); | ||
|
Contributor
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. at what rate will this message appear? We don't want to flood the link |
||
| // Send sn alert telling multiple targets detected | ||
| _frontend.set_target_acquired(false); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // update - give chance to driver to get updates from sensor | ||
| void AC_PrecLand_IRLock::update() | ||
| { | ||
|
|
@@ -31,6 +67,7 @@ void AC_PrecLand_IRLock::update() | |
| irlock.get_unit_vector_body(_los_meas_body); | ||
| _have_los_meas = true; | ||
| _los_meas_time_ms = irlock.last_update_ms(); | ||
| multiple_target_check(); | ||
| } | ||
| _have_los_meas = _have_los_meas && AP_HAL::millis()-_los_meas_time_ms <= 1000; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <AP_Common/AP_Common.h> | ||
|
|
@@ -19,7 +20,7 @@ class AC_PrecLand_IRLock : public AC_PrecLand_Backend | |
| public: | ||
|
|
||
| // Constructor | ||
| AC_PrecLand_IRLock(const AC_PrecLand& frontend, AC_PrecLand::precland_state& state); | ||
| AC_PrecLand_IRLock(AC_PrecLand& frontend, AC_PrecLand::precland_state& state); | ||
|
|
||
| // perform any required initialisation of backend | ||
| void init() override; | ||
|
|
@@ -37,10 +38,17 @@ class AC_PrecLand_IRLock : public AC_PrecLand_Backend | |
| // return true if there is a valid los measurement available | ||
| bool have_los_meas() override; | ||
|
|
||
| //multiple_target_check - Checks if multiple targets detected for 500 ms continously. | ||
| //If yes, sets target_acquired=False which calls contingency landing | ||
| void multiple_target_check(); | ||
|
|
||
|
|
||
| private: | ||
| AP_IRLock_I2C irlock; | ||
|
|
||
| Vector3f _los_meas_body; // unit vector in body frame pointing towards target | ||
| bool _have_los_meas; // true if there is a valid measurement from the camera | ||
| uint32_t _los_meas_time_ms; // system time in milliseconds when los was measured | ||
| uint32_t _multiple_target_timestamp_log[25]; // array of timestamps when multiple targets detected | ||
|
Contributor
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. this is 25, whereas above 24 is used. A #define or const would be good |
||
| size_t _index; | ||
| }; | ||
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's best not to change formatting for no reason. Also please follow the ArduPilot style guide.
http://ardupilot.org/dev/docs/style-guide.html