From b0da1aeffdfb1bb64596d6bd638ccd7c2180006c Mon Sep 17 00:00:00 2001
From: StaY <stephane.yang@ensea.fr>
Date: Thu, 26 Oct 2023 17:38:22 +0200
Subject: [PATCH] update fly_monitor : re-add limit to motor control

---
 Com_server/fly_monitor/src/Data_Drone.cpp            | 12 ++++++------
 .../fly_monitor/src/TestDroneRemoteControl.cpp       |  1 +
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/Com_server/fly_monitor/src/Data_Drone.cpp b/Com_server/fly_monitor/src/Data_Drone.cpp
index 2c93207..2d914ad 100644
--- a/Com_server/fly_monitor/src/Data_Drone.cpp
+++ b/Com_server/fly_monitor/src/Data_Drone.cpp
@@ -986,8 +986,8 @@ int Drone::command_kill(int terminate)
 int Drone::command_directControl(float x, float y, float z, float r)
 {
    int16_t xx,yy,zz,rr;
-   float upper_limit = 0.5;
-   float lower_limit = -0.5;
+   float upper_limit = 0.75;
+   float lower_limit = -0.75;
    
    // Range limitation
    if (x > 1.f || x < -1.f || y > 1.f || y < -1.f || z > 1.f || z < 0.f || r > 1.f || r < -1.f)
@@ -997,12 +997,12 @@ int Drone::command_directControl(float x, float y, float z, float r)
 
    if (x > upper_limit) x = upper_limit;
    if (x < lower_limit) x = lower_limit;
-   if (y > 1.f) y = 1.f;
-   if (y < -1.f) y = -1.f;
+   if (y > upper_limit) y = upper_limit;
+   if (y < lower_limit) y = lower_limit;
    if (z > 1.f ) z =  1.f;
    if (z < -1.f) z = -1.f;
-   if (r > 1.f) r = 1.f;
-   if (r < -1.f) r = -1.f;
+   if (r > upper_limit) r = upper_limit;
+   if (r < lower_limit) r = lower_limit;
    
    xx=static_cast<int16_t>(x * 1000);
    yy=static_cast<int16_t>(y * 1000);
diff --git a/Com_server/fly_monitor/src/TestDroneRemoteControl.cpp b/Com_server/fly_monitor/src/TestDroneRemoteControl.cpp
index 5c41aad..abd97a8 100644
--- a/Com_server/fly_monitor/src/TestDroneRemoteControl.cpp
+++ b/Com_server/fly_monitor/src/TestDroneRemoteControl.cpp
@@ -600,6 +600,7 @@ int command_loop()
       // x, y, z, r = pitch, roll, throttle, yaw
       
       cout << "\nSet mode to position control" << endl;
+      drone1.enable_altitude_control = 1;
       drone1.flight_mode = FlightMode::Posctl;
    }
    else if(buffer_command=="tone")
-- 
GitLab