Ok. I got everything working except the Autopilot.
In my version it moves up and down and the scripted in remains steady?
The code looks similar to the lua? in the image the y goes to about 5 and then -5. collective goes up and down
void R4::SetAutopilot_Altitude() {
VECTOR3 airspdvec;
if (altitude_hold == 1) {
//Proportional error
double altitude = GetAltitude(ALTMODE_MEANRAD);
double propoportional_error = altitude_target - altitude;
// sprintf(oapiDebugString(), "target %f alt %f", altitude_target,altitude);
//Derivative error
GetAirspeedVector(FRAME_LOCAL, airspdvec);
double derivative_error = airspdvec.y;
sprintf(oapiDebugString(), "target %f alt %f y %f", altitude_target, altitude, derivative_error);
//calculate control response using PD gains determined by Ziegler-Nichols tuning method.
double Ku = 0.84; //Ultimate gain
double Tu = 2.73; //Ultimate period (s)
double Kp = 0.8 * Ku;
double Kd = 0.125 * Tu;
collective_input = Kp * propoportional_error + Kd * derivative_error;
SetThrusterGroupLevel(THGROUP_HOVER, collective_input);
}
}
lua
local set_autopilot = {}
function set_autopilot.altitude()
if altitude_hold == true then
--Proportional error
local altitude = vi:get_altitude(ALTMODE.MEANRAD)
local proportional_error = altitude_target - altitude
--Derivative error
local derivative_error = -vi:get_airspeedvector(REFFRAME.LOCAL).y
--calculate control response using PD gains determined by Ziegler-Nichols tuning method.
local Ku = 0.84 --Ultimate gain
local Tu = 2.73 --Ultimate period (s)
local Kp = 0.8*Ku
local Kd = 0.125*Tu
collective_input = Kp * proportional_error + Kd * derivative_error
vi:set_thrustergrouplevel(THGROUP.HOVER, collective_input)
end
end
return set_autopilot
In my version it moves up and down and the scripted in remains steady?
The code looks similar to the lua? in the image the y goes to about 5 and then -5. collective goes up and down
void R4::SetAutopilot_Altitude() {
VECTOR3 airspdvec;
if (altitude_hold == 1) {
//Proportional error
double altitude = GetAltitude(ALTMODE_MEANRAD);
double propoportional_error = altitude_target - altitude;
// sprintf(oapiDebugString(), "target %f alt %f", altitude_target,altitude);
//Derivative error
GetAirspeedVector(FRAME_LOCAL, airspdvec);
double derivative_error = airspdvec.y;
sprintf(oapiDebugString(), "target %f alt %f y %f", altitude_target, altitude, derivative_error);
//calculate control response using PD gains determined by Ziegler-Nichols tuning method.
double Ku = 0.84; //Ultimate gain
double Tu = 2.73; //Ultimate period (s)
double Kp = 0.8 * Ku;
double Kd = 0.125 * Tu;
collective_input = Kp * propoportional_error + Kd * derivative_error;
SetThrusterGroupLevel(THGROUP_HOVER, collective_input);
}
}
lua
local set_autopilot = {}
function set_autopilot.altitude()
if altitude_hold == true then
--Proportional error
local altitude = vi:get_altitude(ALTMODE.MEANRAD)
local proportional_error = altitude_target - altitude
--Derivative error
local derivative_error = -vi:get_airspeedvector(REFFRAME.LOCAL).y
--calculate control response using PD gains determined by Ziegler-Nichols tuning method.
local Ku = 0.84 --Ultimate gain
local Tu = 2.73 --Ultimate period (s)
local Kp = 0.8*Ku
local Kd = 0.125*Tu
collective_input = Kp * proportional_error + Kd * derivative_error
vi:set_thrustergrouplevel(THGROUP.HOVER, collective_input)
end
end
return set_autopilot