Skip to content

Commit d63c114

Browse files
committed
AC_PrecLand: further refactor irlock backend
1 parent ae1aa3a commit d63c114

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

libraries/AC_PrecLand/AC_PrecLand_IRLock.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ extern const AP_HAL::HAL& hal;
1010
// Constructor
1111
AC_PrecLand_IRLock::AC_PrecLand_IRLock(const AC_PrecLand& frontend, AC_PrecLand::precland_state& state)
1212
: AC_PrecLand_Backend(frontend, state),
13-
irlock()
13+
irlock(),
14+
_have_los_meas(false),
15+
_los_meas_time_ms(0)
1416
{
1517
}
1618

@@ -28,26 +30,33 @@ void AC_PrecLand_IRLock::update()
2830

2931
// get new sensor data
3032
irlock.update();
33+
34+
if (irlock.num_targets() > 0 && irlock.last_update_ms() != _los_meas_time_ms) {
35+
irlock.get_unit_vector_body(_los_meas_body);
36+
_have_los_meas = true;
37+
_los_meas_time_ms = irlock.last_update_ms();
38+
}
39+
_have_los_meas = _have_los_meas && AP_HAL::millis()-_los_meas_time_ms <= 1000;
3140
}
3241

3342
// provides a unit vector towards the target in body frame
3443
// returns same as have_los_meas()
3544
bool AC_PrecLand_IRLock::get_los_body(Vector3f& ret) {
3645
if (have_los_meas()) {
37-
irlock.get_unit_vector_body(ret);
46+
ret = _los_meas_body;
3847
return true;
3948
}
4049
return false;
4150
}
4251

4352
// returns system time in milliseconds of last los measurement
4453
uint32_t AC_PrecLand_IRLock::los_meas_time_ms() {
45-
return irlock.last_update_ms();
54+
return _los_meas_time_ms;
4655
}
4756

4857
// return true if there is a valid los measurement available
4958
bool AC_PrecLand_IRLock::have_los_meas() {
50-
return irlock.num_targets() > 0;
59+
return _have_los_meas;
5160
}
5261

5362
#endif // PX4

libraries/AC_PrecLand/AC_PrecLand_IRLock.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class AC_PrecLand_IRLock : public AC_PrecLand_Backend
4242

4343
private:
4444
AP_IRLock_PX4 irlock;
45-
45+
46+
Vector3f _los_meas_body; // unit vector in body frame pointing towards target
47+
bool _have_los_meas; // true if there is a valid measurement from the camera
48+
uint32_t _los_meas_time_ms; // system time in milliseconds when los was measured
4649
};
4750
#endif

0 commit comments

Comments
 (0)