From 1cb094f12ea75f29384d6d1e968b6e2595fb3ac1 Mon Sep 17 00:00:00 2001 From: Tom Pittenger Date: Fri, 29 Jan 2016 22:38:31 -0800 Subject: [PATCH] Plane: make throttle signed (pos and neg) --- ArduPlane/Attitude.cpp | 2 +- ArduPlane/Log.cpp | 13 ++++++------- ArduPlane/Plane.h | 2 +- ArduPlane/system.cpp | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ArduPlane/Attitude.cpp b/ArduPlane/Attitude.cpp index 3ae1a6b1a3..417f5c1eaf 100644 --- a/ArduPlane/Attitude.cpp +++ b/ArduPlane/Attitude.cpp @@ -1110,7 +1110,7 @@ void Plane::demo_servos(uint8_t i) */ void Plane::adjust_nav_pitch_throttle(void) { - uint8_t throttle = throttle_percentage(); + int8_t throttle = throttle_percentage(); if (throttle < aparm.throttle_cruise && flight_stage != AP_SpdHgtControl::FLIGHT_VTOL) { float p = (aparm.throttle_cruise - throttle) / (float)aparm.throttle_cruise; nav_pitch_cd -= g.stab_pitch_down * 100.0f * p; diff --git a/ArduPlane/Log.cpp b/ArduPlane/Log.cpp index c877b2a608..3dd27a43d5 100644 --- a/ArduPlane/Log.cpp +++ b/ArduPlane/Log.cpp @@ -242,13 +242,12 @@ struct PACKED log_Control_Tuning { int16_t pitch; int16_t throttle_out; int16_t rudder_out; - float accel_y; + int16_t throttle_dem; }; // Write a control tuning packet. Total length : 22 bytes void Plane::Log_Write_Control_Tuning() { - Vector3f accel = ins.get_accel(); struct log_Control_Tuning pkt = { LOG_PACKET_HEADER_INIT(LOG_CTUN_MSG), time_us : AP_HAL::micros64(), @@ -258,7 +257,7 @@ void Plane::Log_Write_Control_Tuning() pitch : (int16_t)ahrs.pitch_sensor, throttle_out : (int16_t)channel_throttle->servo_out, rudder_out : (int16_t)channel_rudder->servo_out, - accel_y : accel.y + throttle_dem : (int16_t)SpdHgt_Controller->get_throttle_demand() }; DataFlash.WriteBlock(&pkt, sizeof(pkt)); } @@ -340,7 +339,7 @@ struct PACKED log_Sonar { float voltage; float baro_alt; float groundspeed; - uint8_t throttle; + int8_t throttle; uint8_t count; float correction; }; @@ -361,7 +360,7 @@ void Plane::Log_Write_Sonar() voltage : rangefinder.voltage_mv()*0.001f, baro_alt : barometer.get_altitude(), groundspeed : gps.ground_speed(), - throttle : (uint8_t)(100 * channel_throttle->norm_output()), + throttle : (int8_t)(100 * channel_throttle->norm_output()), count : rangefinder_state.in_range_count, correction : rangefinder_state.correction }; @@ -483,11 +482,11 @@ static const struct LogStructure log_structure[] = { { LOG_STARTUP_MSG, sizeof(log_Startup), "STRT", "QBH", "TimeUS,SType,CTot" }, { LOG_CTUN_MSG, sizeof(log_Control_Tuning), - "CTUN", "Qcccchhf", "TimeUS,NavRoll,Roll,NavPitch,Pitch,ThrOut,RdrOut,AccY" }, + "CTUN", "Qcccchhh", "TimeUS,NavRoll,Roll,NavPitch,Pitch,ThrOut,RdrOut,ThrDem" }, { LOG_NTUN_MSG, sizeof(log_Nav_Tuning), "NTUN", "QCfccccfIf", "TimeUS,Yaw,WpDist,TargBrg,NavBrg,AltErr,Arspd,Alt,GSpdCM,XT" }, { LOG_SONAR_MSG, sizeof(log_Sonar), - "SONR", "QHfffBBf", "TimeUS,DistCM,Volt,BaroAlt,GSpd,Thr,Cnt,Corr" }, + "SONR", "QHfffbBf", "TimeUS,DistCM,Volt,BaroAlt,GSpd,Thr,Cnt,Corr" }, { LOG_ARM_DISARM_MSG, sizeof(log_Arm_Disarm), "ARM", "QBH", "TimeUS,ArmState,ArmChecks" }, { LOG_ATRP_MSG, sizeof(AP_AutoTune::log_ATRP), diff --git a/ArduPlane/Plane.h b/ArduPlane/Plane.h index eec3c35b89..ce53abb658 100644 --- a/ArduPlane/Plane.h +++ b/ArduPlane/Plane.h @@ -915,7 +915,7 @@ private: void servo_write(uint8_t ch, uint16_t pwm); bool should_log(uint32_t mask); void frsky_telemetry_send(void); - uint8_t throttle_percentage(void); + int8_t throttle_percentage(void); void change_arm_state(void); bool disarm_motors(void); bool arm_motors(AP_Arming::ArmingMethod method); diff --git a/ArduPlane/system.cpp b/ArduPlane/system.cpp index c23c8e37e5..b3cd6bf446 100644 --- a/ArduPlane/system.cpp +++ b/ArduPlane/system.cpp @@ -753,9 +753,9 @@ void Plane::frsky_telemetry_send(void) /* - return throttle percentage from 0 to 100 + return throttle percentage from 0 to 100 for normal use and -100 to 100 when using reverse thrust */ -uint8_t Plane::throttle_percentage(void) +int8_t Plane::throttle_percentage(void) { if (auto_state.vtol_mode) { return quadplane.throttle_percentage();