Do syscall for time once, outside of loop

This commit is contained in:
Julian Kent 2019-09-11 16:01:32 +02:00 committed by Daniel Agar
parent b27d6a958a
commit 39451b811a

View File

@ -253,7 +253,9 @@ void CollisionPrevention::_calculateConstrainedSetpoint(Vector2f &setpoint,
float setpoint_length = setpoint.norm();
if (getElapsedTime(&_obstacle_map_body_frame.timestamp) < RANGE_STREAM_TIMEOUT_US) {
hrt_abstime constrain_time = getTime();
if ((constrain_time - _obstacle_map_body_frame.timestamp) < RANGE_STREAM_TIMEOUT_US) {
if (setpoint_length > 0.001f) {
Vector2f setpoint_dir = setpoint / setpoint_length;
@ -267,7 +269,7 @@ void CollisionPrevention::_calculateConstrainedSetpoint(Vector2f &setpoint,
for (int i = 0; i < INTERNAL_MAP_USED_BINS; i++) { //disregard unused bins at the end of the message
//delete stale values
auto data_age = getElapsedTime(&_data_timestamps[i]);
hrt_abstime data_age = constrain_time - _data_timestamps[i];
if (data_age > RANGE_STREAM_TIMEOUT_US) {
_obstacle_map_body_frame.distances[i] = UINT16_MAX;