WSF
WsfSixDOF_Route.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2020 Infoscitex, a DCS Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFSIXDOFROUTE_HPP
13#define WSFSIXDOFROUTE_HPP
14
15#include "wsf_six_dof_export.h"
16
17#include <map>
18#include <memory>
19#include <vector>
20
21#include "UtLLAPos.hpp"
22#include "UtVec2.hpp"
23#include "UtVec3.hpp"
26
27namespace wsf
28{
29namespace six_dof
30{
31class WSF_SIX_DOF_EXPORT Route
32{
33public:
34 // Default constructor
35 Route() = default;
36
37 // Return a deep copy of this route
38 Route* Clone() const;
39
40 // Destructor
41 ~Route() = default;
42
43 // Geometric data computed once based on a route from one waypoint to another
45 {
46 double trackDistance_m = 0.0; // Distance from prev wpt to curr wpt
47 double trackEndHdg_rad = 0.0; // Heading when current wpt is reached
48 double trackStartHdg_rad = 0.0; // Heading initially taken from prev wpt to curr wpt
49 double slantRange_m = 0.0; // 3D distance from prev to curr meters
50 double slope_rad = 0.0; // Angle from prev wpt to curr wpt
51 double rangeTrack_m = 0.0; // distance from current position to curr wpt
52 double earthNED[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; // Transform matrix for earth NED coordinates
53 UtVec3d currWptVector; // LLA Position of the current waypoint vector
54 UtVec3d prevWptVector; // LLA Position of the previous waypoint vector
55 UtVec3d trackVector; // Vector from previous to current waypoint
56 };
57
58 // Calculate heading and bank angle for roll-only waypoint navigation
59 static void CalcAimHeadingAndBankAngle(const Waypoint* aPrevWpt, // Pointer to prev wpt
60 const Waypoint* aCurrWpt, // Pointer to curr wpt
61 const Waypoint* aNextWpt, // Pointer to next wpt
62 const sRouteSegment* aCurrSegment, // Pointer to curr route segment
63 const sRouteSegment* aNextSegment, // Pointer to next route segment
64 const UtLLAPos& aCurrentPos_lla, // Current position
65 const UtVec2d& aCurrentVel_mps, // Current velocity
66 CommonController::WaypointNavData& aNavData, // Output of nav data for autopilot
67 double aTurnRollInMultiplier, // Roll-in multiplier for autopilot
68 double aRouteAllowableAngleError_rad, // Allowable angular error for route heading
69 double aHeading_rad, // Current heading
70 double aSpeed_mps, // Current speed
71 double aMaxBankAngle_rad, // Max allowed bank angle
72 double aMaxBankRate_rad_s, // Max allowed bank rate
73 double aMaxG_g, // Max allowed turn g
74 double aDeltaT_sec,
75 bool& aAchievedWaypoint);
76
77 // Calculate heading angle for yaw-only navigation waypoint
78 static void CalcYawAimHeadingAngle(const Waypoint* aPrevWpt, // Pointer to prev wpt
79 const Waypoint* aCurrWpt, // Pointer to curr wpt
80 const Waypoint* aNextWpt, // Pointer to next wpt
81 const sRouteSegment* aCurrSegment, // Pointer to curr route segment
82 const sRouteSegment* aNextSegment, // Pointer to next route segment
83 const UtLLAPos& aCurrentPos_lla, // Current position
84 const UtVec2d& aCurrentVel_mps, // Current velocity
85 CommonController::WaypointNavData& aNavData, // Output of nav data for autopilot
86 double aRouteAllowableAngleError_rad, // Allowable angular error for route heading
87 double aHeading_rad, // Current heading
88 double aSpeed_mps, // Current speed
89 double aMaxG_g, // Max allowed turn g
90 double aDeltaT_sec,
91 bool& aAchievedWaypoint);
92
93 // Calculate heading angle for taxi navigation waypoint
94 static void CalcTaxiAimHeadingAngle(const Waypoint* aPrevWpt, // Pointer to prev wpt
95 const Waypoint* aCurrWpt, // Pointer to curr wpt
96 const Waypoint* aNextWpt, // Pointer to next wpt
97 const sRouteSegment* aCurrSegment, // Pointer to curr route segment
98 const sRouteSegment* aNextSegment, // Pointer to next route segment
99 const UtLLAPos& aCurrentPos_lla, // Current position
100 const UtVec2d& aCurrentVel_mps, // Current velocity
101 CommonController::WaypointNavData& aNavData, // Output of nav data for autopilot
102 float aHeading_rad, // Current heading
103 double aTurnRadius_ft, // Desired turn radius
104 double aDeltaT_sec,
105 bool& aAchievedWaypoint);
106
107 // Calculate vertical rate data for waypoint navigation
109
110 // Get the start heading from one waypoint to another
111 static double GetInitialHeading_rad(const UtLLAPos& aLLAStart, const UtLLAPos& aLLAEnd);
112 // Get the radius of a turn
113 static double GetTurnRadius_m(double aSpeed_mps, double aBankAngle_rad);
114
115 // Get the radius of a turn from the lateral G
116 static double GetTurnRadiusFromLateralG_m(double aSpeed_mps, double aLateralG_g);
117
118 // Get the distance at which point the vehicle needs to start turning based on turn geometry
119 static double GetTurnLeadDistance_m(double aTurnAngle_rad, double aTurnRadius_m);
120
121 // Get the start heading, end heading, and distance between two LLA positions
122 static double GetDistanceBetweenWaypoints_m(const UtLLAPos& aStartLLA,
123 const UtLLAPos& aEndLLA,
124 double& aStartHdg_rad,
125 double& aEndHdg_rad);
126
127 // Perform one time computations for the geometry of a curve between 3 waypoints
128 static std::unique_ptr<sRouteSegment> CalcSegmentGeometry(const Waypoint* aPrevWpt, const Waypoint* aCurrWpt);
129
130 // Return the first element in the mRoute vector. Using this and GetNextWaypoint, the entire
131 // route can be iterated across
132 const Waypoint* GetFirstElement() const;
133
134 // Given a waypoint, return the next waypoint in the route or 0 if it is the last waypoint.
135 const Waypoint* GetNextWaypoint(const Waypoint* aWaypoint) const;
136
137 // Return the waypoint at the specified index
138 const Waypoint* GetWaypointAtIndex(size_t aIndex) const;
139
140 // Return the index of the given waypoint in the route
141 size_t GetWaypointIndex(const Waypoint* aWaypoint) const;
142
143 // Determine whether the waypoint was passed
144 static bool PassedWaypoint(float aDT, const CommonController::WaypointNavData& aNavData);
145
146 // Determine whether the waypoint was achieved, either by passing or approaching
147 static bool AchievedWaypoint(float aDT,
148 const CommonController::WaypointNavData& aNavData,
149 const Waypoint* aWaypoint,
150 const Waypoint* aNextWaypoint);
151
152 // Add a waypoint to the route if the waypoint is valid and not present in the route.
153 // Note: Traveling to the same waypoint multiple times can be accomplished using the
154 // "GoTo"
155 void AddWaypointToRouteEnd(std::unique_ptr<Waypoint>& aWaypoint);
156
157 // Add a waypoint to the start of the route
158 void AddWaypointToRouteStart(std::unique_ptr<Waypoint>& aWaypoint);
159
160 // Return the size of the mRoute vector
161 size_t GetNumberOfWaypoints() const;
162
163 // Return a const pointer to the route
164 const std::vector<std::unique_ptr<Waypoint>>& GetRoute() const { return mRoute; }
165
166 // Populate the segment map
167 void ComputeSegmentMap();
168
169 // Add a segment to the segment map.
170 void AddSegment(Waypoint* aWaypoint, std::unique_ptr<sRouteSegment>& aSegment);
171
172 // Return a route segment corresponding to a waypoint.
173 // Note: Given a segment from point A to point B, the segment is mapped using
174 // point A as the key.
175 sRouteSegment* GetRouteSegment(const Waypoint* aWaypoint) const;
176
177private:
178 Route& operator=(const Route& aSrc) = delete;
179
180 // Copy constructor
181 Route(const Route& aSrc);
182
183 // Vector of waypoint pointers that defines a navigation route
184 std::vector<std::unique_ptr<Waypoint>> mRoute;
185
186 // Map of route segments
187 // Note: Given a segment from point A to point B, the segment is mapped using
188 // point A as the key.
189 std::map<Waypoint*, std::unique_ptr<sRouteSegment>> mSegments;
190};
191} // namespace six_dof
192} // namespace wsf
193
194#endif // WSFSIXDOFROUTE_H
Definition WsfSixDOF_Route.hpp:32
static void CalcYawAimHeadingAngle(const Waypoint *aPrevWpt, const Waypoint *aCurrWpt, const Waypoint *aNextWpt, const sRouteSegment *aCurrSegment, const sRouteSegment *aNextSegment, const UtLLAPos &aCurrentPos_lla, const UtVec2d &aCurrentVel_mps, CommonController::WaypointNavData &aNavData, double aRouteAllowableAngleError_rad, double aHeading_rad, double aSpeed_mps, double aMaxG_g, double aDeltaT_sec, bool &aAchievedWaypoint)
Definition WsfSixDOF_Route.cpp:390
size_t GetNumberOfWaypoints() const
Definition WsfSixDOF_Route.cpp:899
static double GetTurnRadiusFromLateralG_m(double aSpeed_mps, double aLateralG_g)
Definition WsfSixDOF_Route.cpp:872
static void CalcAimHeadingAndBankAngle(const Waypoint *aPrevWpt, const Waypoint *aCurrWpt, const Waypoint *aNextWpt, const sRouteSegment *aCurrSegment, const sRouteSegment *aNextSegment, const UtLLAPos &aCurrentPos_lla, const UtVec2d &aCurrentVel_mps, CommonController::WaypointNavData &aNavData, double aTurnRollInMultiplier, double aRouteAllowableAngleError_rad, double aHeading_rad, double aSpeed_mps, double aMaxBankAngle_rad, double aMaxBankRate_rad_s, double aMaxG_g, double aDeltaT_sec, bool &aAchievedWaypoint)
Definition WsfSixDOF_Route.cpp:164
const Waypoint * GetWaypointAtIndex(size_t aIndex) const
Definition WsfSixDOF_Route.cpp:84
const Waypoint * GetFirstElement() const
Definition WsfSixDOF_Route.cpp:904
Route * Clone() const
Definition WsfSixDOF_Route.cpp:37
static void CalcTaxiAimHeadingAngle(const Waypoint *aPrevWpt, const Waypoint *aCurrWpt, const Waypoint *aNextWpt, const sRouteSegment *aCurrSegment, const sRouteSegment *aNextSegment, const UtLLAPos &aCurrentPos_lla, const UtVec2d &aCurrentVel_mps, CommonController::WaypointNavData &aNavData, float aHeading_rad, double aTurnRadius_ft, double aDeltaT_sec, bool &aAchievedWaypoint)
Definition WsfSixDOF_Route.cpp:595
const Waypoint * GetNextWaypoint(const Waypoint *aWaypoint) const
Definition WsfSixDOF_Route.cpp:42
static std::unique_ptr< sRouteSegment > CalcSegmentGeometry(const Waypoint *aPrevWpt, const Waypoint *aCurrWpt)
Definition WsfSixDOF_Route.cpp:117
static double GetTurnRadius_m(double aSpeed_mps, double aBankAngle_rad)
Definition WsfSixDOF_Route.cpp:867
static bool AchievedWaypoint(float aDT, const CommonController::WaypointNavData &aNavData, const Waypoint *aWaypoint, const Waypoint *aNextWaypoint)
Definition WsfSixDOF_Route.cpp:820
void AddWaypointToRouteStart(std::unique_ptr< Waypoint > &aWaypoint)
Definition WsfSixDOF_Route.cpp:963
static bool PassedWaypoint(float aDT, const CommonController::WaypointNavData &aNavData)
Definition WsfSixDOF_Route.cpp:804
size_t GetWaypointIndex(const Waypoint *aWaypoint) const
Definition WsfSixDOF_Route.cpp:96
static void CalcVerticalSpeed(CommonController::WaypointNavData &aNavData)
Definition WsfSixDOF_Route.cpp:788
static double GetDistanceBetweenWaypoints_m(const UtLLAPos &aStartLLA, const UtLLAPos &aEndLLA, double &aStartHdg_rad, double &aEndHdg_rad)
Definition WsfSixDOF_Route.cpp:882
const std::vector< std::unique_ptr< Waypoint > > & GetRoute() const
Definition WsfSixDOF_Route.hpp:164
static double GetTurnLeadDistance_m(double aTurnAngle_rad, double aTurnRadius_m)
Definition WsfSixDOF_Route.cpp:877
static double GetInitialHeading_rad(const UtLLAPos &aLLAStart, const UtLLAPos &aLLAEnd)
Definition WsfSixDOF_Route.cpp:844
void AddWaypointToRouteEnd(std::unique_ptr< Waypoint > &aWaypoint)
Definition WsfSixDOF_Route.cpp:947
Definition WsfSixDOF_Waypoint.hpp:26
Definition WsfSA_Processor.hpp:35
Function definitions for those who need run-time access to the version.
Definition WsfComm.cpp:32
Definition WsfSixDOF_CommonController.hpp:65
Definition WsfSixDOF_Route.hpp:45
UtVec3d trackVector
Definition WsfSixDOF_Route.hpp:55
UtVec3d prevWptVector
Definition WsfSixDOF_Route.hpp:54
UtVec3d currWptVector
Definition WsfSixDOF_Route.hpp:53
double slope_rad
Definition WsfSixDOF_Route.hpp:50
double rangeTrack_m
Definition WsfSixDOF_Route.hpp:51
double earthNED[3][3]
Definition WsfSixDOF_Route.hpp:52
double slantRange_m
Definition WsfSixDOF_Route.hpp:49
double trackStartHdg_rad
Definition WsfSixDOF_Route.hpp:48
double trackDistance_m
Definition WsfSixDOF_Route.hpp:46
double trackEndHdg_rad
Definition WsfSixDOF_Route.hpp:47
Copyrights Multiple, All Rights Reserved