Avionics
Dropship Simulator
FMS.cpp
Go to the documentation of this file.
1 #include "Module.h"
2 
3 Fms::Fms(Bus* prmBus, Logger* prmLogger) : Module(prmBus)
4 {
5  logger = prmLogger;
6  bus = prmBus;
7 }
8 
9 void Fms::FrameMove(float fElapsedTime)
10 {
11  if (bus->waypoints.size() == 0)
12  return;
13 
16  static float oldbear = 0.0f;
17 
18  Waypoint nextWaypoint = bus->waypoints.at(0);
19  D3DXVECTOR3 result = bus->Location - nextWaypoint.absoluteLocation();
20  D3DXVECTOR2 result2 = D3DXVECTOR2(result.x, result.y);
21  float dist = D3DXVec2Length(&result2);
22  float bear = atan2f(result2.y, result2.x) - D3DX_PI * 0.5f - bus->HeadingTrue; // so this would give us 0 is north... if we are facing west, as an example, it would be 360 - 270 = +90
24  while (bear >= D3DX_PI) bear -= D3DX_PI * 2.0f;
25  while (bear <= -D3DX_PI) bear += D3DX_PI * 2.0f;
26 
28  // right now we are doing "fly-over"
29  if (fabsf(oldbear) < D3DX_PI * 0.5f && fabsf(bear) > D3DX_PI * 0.5f) // was less than 90 left or right
30  {
31  if (dist < 0.5f && nextWaypoint.type == Waypoint::WaypointType::FinalApproachFix) // .25km laterally
32  {
33  if (bus->AFCS.StandbyLateralMode == Bus::Afcs::LateralModes::Localizer)
34  {
35  Command newCommand;
36  newCommand.name = "AFCS-LateralMode";
37  newCommand.ivalue = static_cast<int>(Bus::Afcs::LateralModes::Localizer);
38  bus->commandStream.push_back(newCommand);
39  newCommand.name = "AFCS-ArmLateralMode";
40  newCommand.ivalue = static_cast<int>(Bus::Afcs::LateralModes::LateralMode_Off);
41  bus->commandStream.push_back(newCommand);
42  }
44  if (bus->AFCS.StandbyVerticalMode == Bus::Afcs::VerticalModes::GlideSlope)
45  {
46  Command newCommand;
47  newCommand.name = "AFCS-VerticalMode";
48  newCommand.ivalue = static_cast<int>(Bus::Afcs::VerticalModes::GlideSlope);
49  bus->commandStream.push_back(newCommand);
50  newCommand.name = "AFCS-ArmVerticalMode";
51  newCommand.ivalue = static_cast<int>(Bus::Afcs::VerticalModes::VerticalMode_Off);
52  bus->commandStream.push_back(newCommand);
53  }
54  }
55  bus->waypoints.erase(bus->waypoints.begin());
56  bus->AFCS.DesiredCourse = D3DX_PI * 1.5f;
57  }
58 
59  oldbear = bear;
60 }
D3DXVECTOR3 absoluteLocation() const
Definition: Waypoint.h:23
std::vector< Command > commandStream
Definition: Bus.h:20
Definition: Logger.h:5
std::vector< Waypoint > waypoints
Definition: Bus.h:367
WaypointType type
Definition: Waypoint.h:21
float HeadingTrue
(4) Heading–primary flight crew reference (if selectable, record discrete, true or magnetic); ...
Definition: Bus.h:44
Definition: Bus.h:12
std::string name
command name
Definition: Command.h:11
Abstract base class for modules By definition, instruments don&#39;t do any of the work (they don&#39;t modif...
Definition: Module.h:11
Definition: Command.h:5
struct Bus::Afcs AFCS
Fms(Bus *prmBus, Logger *prmLogger)
Definition: FMS.cpp:3
enum Bus::Afcs::VerticalModes StandbyVerticalMode
void FrameMove(float fElapsedTime) override
Definition: FMS.cpp:9
Logger * logger
Definition: Module.h:344
int ivalue
Definition: Command.h:21
float DesiredCourse
Definition: Bus.h:121
enum Bus::Afcs::LateralModes StandbyLateralMode
Bus * bus
Definition: Module.h:345
D3DXVECTOR3 Location
Definition: Bus.h:359