Commit a6619148 authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾

Use doReposition and doOverride commands asynchronously

parent 903e38b3
...@@ -157,12 +157,16 @@ static int doReposition(float la, float lo, float radius, float y) { ...@@ -157,12 +157,16 @@ static int doReposition(float la, float lo, float radius, float y) {
return doMavlinkCommand(command, "Entering loiter mode failed"); return doMavlinkCommand(command, "Entering loiter mode failed");
} }
static void doReposition_async(float la, float lo, float radius, float y) {
std::thread(doReposition, la, lo, radius, y).detach();
}
static void updateProjection(double current_lat, double current_lon) { static void updateProjection(double current_lat, double current_lon) {
Coordinates position{ current_lat, current_lon }; Coordinates position{ current_lat, current_lon };
projected_destination = getProjectionCoordinates(targeted_destination, projected_destination = getProjectionCoordinates(targeted_destination,
position); position);
return doReposition( doReposition_async(
(float)projected_destination.latitude, (float)projected_destination.latitude,
(float)projected_destination.longitude, (float)projected_destination.longitude,
DEFAULT_RADIUS, DEFAULT_RADIUS,
...@@ -175,7 +179,7 @@ static long long int getTimestamp() { ...@@ -175,7 +179,7 @@ static long long int getTimestamp() {
return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count(); return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
} }
int updateLogAndProjection(void) { void updateLogAndProjection(void) {
std::ostringstream oss; std::ostringstream oss;
Telemetry::Position position; Telemetry::Position position;
Telemetry::FixedwingMetrics metrics; Telemetry::FixedwingMetrics metrics;
...@@ -192,11 +196,9 @@ int updateLogAndProjection(void) { ...@@ -192,11 +196,9 @@ int updateLogAndProjection(void) {
log(oss.str()); log(oss.str());
if (projected_destination.latitude != 0 || targeted_destination.latitude != 0) { if (projected_destination.latitude != 0 || targeted_destination.latitude != 0) {
return updateProjection(position.latitude_deg, position.longitude_deg); updateProjection(position.latitude_deg, position.longitude_deg);
} }
} }
return 0;
} }
// Connexion management functions // Connexion management functions
...@@ -347,30 +349,37 @@ static int setAltitude(float altitude) { ...@@ -347,30 +349,37 @@ static int setAltitude(float altitude) {
return doOverride(altitude, last_override_speed, "Setting altitude failed"); return doOverride(altitude, last_override_speed, "Setting altitude failed");
} }
int loiter(double la, double lo, float a, float radius) { static void setAltitude_async(float altitude) {
int result = doReposition((float)la, (float)lo, radius, 0); std::thread(setAltitude, altitude).detach();
result |= setAltitude(a); }
return result;
void loiter(double la, double lo, float a, float radius) {
doReposition_async((float)la, (float)lo, radius, 0);
setAltitude_async(a);
} }
int setAirSpeed(float airspeed) { static int setAirSpeed(float airspeed) {
last_override_speed = airspeed; last_override_speed = airspeed;
return doOverride(last_override_altitude, airspeed, return doOverride(last_override_altitude, airspeed,
"Setting airspeed failed"); "Setting airspeed failed");
} }
int setTargetCoordinates(double la, double lo, float a) { void setAirSpeed_async(float airspeed) {
int result; std::thread(setAirSpeed, airspeed).detach();
if (!mavsdk_started) }
return -1;
void setTargetCoordinates(double la, double lo, float a) {
if (!mavsdk_started) {
log_error("Mavsdk not started");
return;
}
Telemetry::Position position = telemetry->position(); Telemetry::Position position = telemetry->position();
targeted_destination.latitude = la; targeted_destination.latitude = la;
targeted_destination.longitude = lo; targeted_destination.longitude = lo;
result = updateProjection(position.latitude_deg, position.longitude_deg); updateProjection(position.latitude_deg, position.longitude_deg);
result |= setAltitude(a); setAltitude_async(a);
return result;
} }
// Information functions // Information functions
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment