Skip to content
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

Algorithm improvement:While loop&CPU utilization is high #4788

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions AirLib/src/vehicles/multirotor/api/MultirotorApiBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <iostream>
#include <fstream>

#include <windows.h>

namespace msr
{
namespace airlib
Expand Down Expand Up @@ -346,7 +348,7 @@ namespace airlib

//until we are at the end of the path (last seg is always zero size)
while (!waiter.isTimeout() && (next_path_loc.seg_index < path_segs.size() - 1 || goal_dist > 0)) { //current position is approximately at the last end point

Sleep(30);
float seg_velocity = path_segs.at(next_path_loc.seg_index).seg_velocity;
float path_length_remaining = path_length - path_segs.at(cur_path_loc.seg_index).seg_path_length - cur_path_loc.offset;
if (seg_velocity > getMultirotorApiParams().min_vel_for_breaking && path_length_remaining <= breaking_dist) {
Expand Down Expand Up @@ -918,7 +920,7 @@ namespace airlib
//if auto mode requested for lookahead then calculate based on velocity
float command_period_dist = velocity * getCommandPeriod();
float lookahead = command_period_dist * (adaptive_lookahead > 0 ? min_factor : max_factor);
lookahead = std::max(lookahead, getDistanceAccuracy() * 1.5f); //50% more than distance accuracy
lookahead = (std::max)(lookahead, getDistanceAccuracy() * 1.5f); //50% more than distance accuracy
return lookahead;
}

Expand Down