2 #include "../Extensions.h" 16 #pragma region Commands 21 if (command.
delay != 0.0f)
continue;
23 if (command.
name ==
"AFCS-VerticalModeCycle")
26 newCommand.
name =
"AFCS-VerticalMode";
29 case Bus::Afcs::VerticalModes::VerticalMode_Off: newCommand.
ivalue =
static_cast<int>(Bus::Afcs::VerticalModes::Pitch);
31 case Bus::Afcs::VerticalModes::Pitch: newCommand.
ivalue =
static_cast<int>(Bus::Afcs::VerticalModes::VerticalSpeed);
33 case Bus::Afcs::VerticalModes::VerticalSpeed: newCommand.
ivalue =
static_cast<int>(Bus::Afcs::VerticalModes::Altitude);
35 default: newCommand.
ivalue =
static_cast<int>(Bus::Afcs::VerticalModes::VerticalMode_Off);
41 else if (command.
name ==
"AFCS-LateralModeCycle")
44 newCommand.
name =
"AFCS-LateralMode";
47 case Bus::Afcs::LateralModes::LateralMode_Off: newCommand.
ivalue =
static_cast<int>(Bus::Afcs::LateralModes::Roll);
49 case Bus::Afcs::LateralModes::Roll: newCommand.
ivalue =
static_cast<int>(Bus::Afcs::LateralModes::Heading);
51 case Bus::Afcs::LateralModes::Heading:
54 newCommand.
ivalue = static_cast<int>(Bus::Afcs::LateralModes::Navigation);
56 newCommand.
ivalue =
static_cast<int>(Bus::Afcs::LateralModes::LateralMode_Off);
59 default: newCommand.
ivalue =
static_cast<int>(Bus::Afcs::LateralModes::LateralMode_Off);
65 else if (command.
name ==
"AFCS-VerticalMode")
73 newCommand.
name =
"AFCS-LateralMode";
74 newCommand.
ivalue =
static_cast<int>(Bus::Afcs::LateralModes::Roll);
84 newCommand.
name =
"AFCS-LateralMode";
85 newCommand.
ivalue =
static_cast<int>(Bus::Afcs::LateralModes::LateralMode_Off);
91 newCommand.
name =
"AFCS-Autopilot";
98 newCommand.
name =
"AFCS-ArmVerticalMode";
99 newCommand.
ivalue =
static_cast<int>(Bus::Afcs::VerticalModes::VerticalMode_Off);
113 else if (command.
name ==
"AFCS-PitchSetting")
118 else if (command.
name ==
"AFCS-VsiSetting")
123 else if (command.
name ==
"AFCS-AltitudeSetting")
128 else if (command.
name ==
"AFCS-ArmLateralMode")
133 else if (command.
name ==
"AFCS-ArmVerticalMode")
138 else if (command.
name ==
"AFCS-LateralMode")
167 newCommand.
name =
"AFCS-VerticalMode";
168 newCommand.
ivalue =
static_cast<int>(Bus::Afcs::VerticalModes::Pitch);
178 newCommand.
name =
"AFCS-VerticalMode";
179 newCommand.
ivalue =
static_cast<int>(Bus::Afcs::VerticalModes::VerticalMode_Off);
185 newCommand.
name =
"AFCS-Autopilot";
186 newCommand.
bvalue =
false;
192 newCommand.
name =
"AFCS-ArmLateralMode";
193 newCommand.
ivalue =
static_cast<int>(Bus::Afcs::LateralModes::LateralMode_Off);
200 else if (command.
name ==
"AFCS-RollSetting")
205 else if (command.
name ==
"AFCS-HeadingRelative")
210 else if (command.
name ==
"AFCS-AutopilotCycle")
213 newCommand.
name =
"AFCS-Autopilot";
218 else if (command.
name ==
"AFCS-Autopilot")
227 newCommand.
name =
"AFCS-VerticalMode";
228 newCommand.
ivalue =
static_cast<int>(Bus::Afcs::VerticalModes::Pitch);
235 newCommand.
name =
"APDisconnect";
239 newCommand.
name =
"AFCS-Autothrottle";
240 newCommand.
bvalue =
false;
246 else if (command.
name ==
"AFCS-Autothrottle")
257 else if (command.
name ==
"AFCS-SetThrust")
266 #pragma region Vertical Modes 274 D3DXVECTOR2 diff2 = D3DXVECTOR2(diff3.x, diff3.y);
275 float dist = D3DXVec2Length(&diff2);
276 float desiredaltitude = -(
bus->
waypoints.at(0).absoluteLocation().z - sinf(0.05235987755982988730771072305466f) * dist);
295 D3DXVECTOR2 diff2 = D3DXVECTOR2(diff3.x, diff3.y);
296 float dist = D3DXVec2Length(&diff2);
297 float desiredaltitude = -(
bus->
waypoints.at(1).absoluteLocation().z - sinf(0.05235987755982988730771072305466f) * dist);
317 newCommand.
name =
"CChord";
364 static float smoothalt = 0.0f;
368 static float lastAltitudeUpdate = 0.0f;
369 lastAltitudeUpdate += fElapsedTime;
370 static float oldaltitude = 0.0f;
371 float altdiff = smoothalt - oldaltitude;
375 lastAltitudeUpdate = 0.0f;
377 else if (lastAltitudeUpdate > 1.0f)
379 oldaltitude = smoothalt;
386 if (diff > 0.052359877559829887307710723054658f)
387 diff = 0.052359877559829887307710723054658f;
388 else if (diff < -0.052359877559829887307710723054658f)
389 diff = -0.052359877559829887307710723054658f;
411 static float pitch = 0.0f;
414 static float oldpitchrate = 0.0f;
425 float desiredrate = deltapitch * 0.3f;
427 if (desiredrate > 0.052359877559829887307710723054658f)
428 desiredrate = 0.052359877559829887307710723054658f;
429 else if (desiredrate < -0.052359877559829887307710723054658f)
430 desiredrate = -0.052359877559829887307710723054658f;
440 static float oldcorrection = 0.0f;
443 float effectivechange = oldpitchrate - currentrate;
444 float magnify = 1.0f;
446 magnify = fabsf(oldcorrection - effectivechange) / fabsf(oldcorrection) + 1.0f;
450 else if (magnify < 0.1f)
465 oldpitchrate = currentrate;
469 oldcorrection = (desiredrate - currentrate) * magnify * fElapsedTime * 0.3f *
PitchAggression;
470 if (oldcorrection > 0.52359877559829887307710723054658f)
471 oldcorrection = 0.52359877559829887307710723054658f;
472 else if (oldcorrection < -0.52359877559829887307710723054658f)
473 oldcorrection = -0.52359877559829887307710723054658f;
491 command.
name =
"AltitudeCoupler";
504 #pragma region Lateral Modes 514 D3DXVECTOR2 result2 = D3DXVECTOR2(result.x, result.y);
515 float dist = D3DXVec2Length(&result2);
516 float bear = atan2f(result2.y, result2.x) - D3DX_PI * 0.5f -
bus->
HeadingTrue;
517 if (bear >= D3DX_PI * 2.0f)
518 bear -= D3DX_PI * 2.0f;
519 else if (bear < 0.0f)
520 bear += D3DX_PI * 2.0f;
531 if (hdg2obj > D3DX_PI * 2.0f)
532 hdg2obj -= D3DX_PI * 2.0f;
533 else if (hdg2obj < 0.0f)
534 hdg2obj += D3DX_PI * 2.0f;
545 if (correct > D3DX_PI)
546 correct -= D3DX_PI * 2.0f;
547 else if (correct < -D3DX_PI)
548 correct += D3DX_PI * 2.0f;
549 if (correct > D3DX_PI * 0.5f)
550 correct = D3DX_PI - correct;
551 else if (correct < -D3DX_PI * 0.5f)
552 correct = -D3DX_PI - correct;
560 if (correct > D3DX_PI * 0.25f)
561 correct = D3DX_PI * 0.25f;
562 else if (correct < -D3DX_PI * 0.25f)
563 correct = -D3DX_PI * 0.25f;
565 correct *= dist * 0.25f;
569 if (trkadj > D3DX_PI * 2.0f)
570 trkadj -= D3DX_PI * 2.0f;
571 else if (trkadj < 0.0f)
572 trkadj += D3DX_PI * 2.0f;
583 newCommand.
name =
"AFCS-LateralMode";
584 newCommand.
ivalue =
static_cast<int>(Bus::Afcs::LateralModes::Heading);
594 if (desiredroll < -D3DX_PI)
596 else if (desiredroll > D3DX_PI)
601 if (desiredroll > 0.523599f)
602 desiredroll = 0.523599f;
603 else if (desiredroll < -0.523599f)
604 desiredroll = -0.523599f;
617 float desiredrate = deltaroll * 0.3f;
627 float ratediff = desiredrate - currentRollRate;
D3DXVECTOR3 absoluteLocation() const
const float PitchAggression
const float RollAggression
std::vector< Command > commandStream
enum Bus::Afcs::LateralModes CurrentLateralMode
std::vector< Waypoint > waypoints
float IndicatedAirspeed
(3) Indicated Airspeed in km per second?
static float Clamp(float x, float min, float max)
float PitchAttitude
(6) Pitch attitude;
float HeadingTrue
(4) Heading–primary flight crew reference (if selectable, record discrete, true or magnetic); ...
std::string name
command name
float RollAttitude
(7) Roll attitude;
Afcs(Bus *prmBus, Logger *prmLogger)
void FrameMove(float fElapsedTime) override
Abstract base class for modules By definition, instruments don't do any of the work (they don't modif...
enum Bus::Afcs::VerticalModes StandbyVerticalMode
enum Bus::Afcs::VerticalModes CurrentVerticalMode
float delay
wait number of seconds before executing command
enum Bus::Afcs::LateralModes StandbyLateralMode
VerticalModes
so I guess we allow them to fly until they get to x degrees off
float GlideslopeDeviation