EMANE  1.2.1
positionorientationvelocity.inl
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - Adjacent Link LLC, Bridgewater, New Jersey
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * * Neither the name of Adjacent Link LLC nor the names of its
16  * contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 namespace
34 {
35  inline
36  EMANE::Orientation adjustOrientation(const EMANE::Orientation & orientation,
37  const EMANE::Velocity & velocity)
38  {
39  double dYaw{velocity.getAzimuthDegrees() + orientation.getYawDegrees()};
40 
41  // set yaw to [0 to 360)
42  EMANE::Utils::AI_TO_BE_DEGREES(dYaw, 0.0, 360.0);
43 
44  double dPitch{velocity.getElevationDegrees() + orientation.getPitchDegrees()};
45 
46  // set dpitch to [0 to 360)
47  EMANE::Utils::AI_TO_BE_DEGREES(dPitch, 0.0, 360.0);
48 
49  // set pitch to [-90 to 90]
51 
52  return {orientation.getRollDegrees(),dPitch,dYaw};
53  }
54 }
55 
56 inline
58  position_{},
59  orientation_{},
60  velocity_{},
61  bValid_{},
62  bHasOrientation_{},
63  bHasVelocity_{}{}
64 
65 inline
67  const std::pair<const Orientation &, bool> & orientation,
68  const std::pair<const Velocity &, bool> & velocity):
69  position_{position},
70  orientation_{orientation.first},
71  velocity_{velocity.first},
72  bValid_{true},
73  bHasOrientation_{orientation.second},
74  bHasVelocity_{velocity.second},
75  positionECEF_{position},
76  adjustedOrientation_{adjustOrientation(orientation_,velocity_)}{}
77 
78 inline
80  const std::pair<const Orientation &, bool> & orientation,
81  const std::pair<const Velocity &, bool> & velocity)
82 {
83  if(position == position_ &&
84  (!orientation.second || orientation.first == orientation_) &&
85  (!velocity.second || velocity.first == velocity_))
86  {
87  return false;
88  }
89  else
90  {
91  bValid_ = true;
92 
93  if(position != position_)
94  {
95  position_ = position;
96  positionECEF_ = PositionECEF(position_);
97  }
98 
99  bool bCalculateAdjustedOrientation{false};
100 
101  if(orientation.second)
102  {
103  orientation_ = orientation.first;
104  bHasOrientation_ = true;
105  bCalculateAdjustedOrientation = true;
106  }
107 
108  if(velocity.second)
109  {
110  velocity_ = velocity.first;
111  bHasVelocity_ = true;
112  bCalculateAdjustedOrientation = true;
113  }
114 
115  if(bCalculateAdjustedOrientation)
116  {
117  adjustedOrientation_ = adjustOrientation(orientation_,velocity_);
118  }
119 
120  return true;
121  }
122 }
123 
124 inline
126 {
127  return position_;
128 }
129 
130 inline
131 std::pair<const EMANE::Orientation &, bool> EMANE::PositionOrientationVelocity::getOrientation() const
132 {
133  return {orientation_,bHasOrientation_};
134 }
135 
136 inline
137 std::pair<const EMANE::Orientation &, bool> EMANE::PositionOrientationVelocity::getAdjustedOrientation() const
138 {
139  return {adjustedOrientation_,bHasOrientation_ || bHasVelocity_};
140 }
141 
142 inline
143 std::pair<const EMANE::Velocity &, bool> EMANE::PositionOrientationVelocity::getVelocity() const
144 {
145  return {velocity_,bHasVelocity_};
146 }
147 
148 inline
150 {
151  return positionECEF_;
152 }
153 
154 inline
156 {
157  const auto & selfECEF = getPositionECEF();
158  const auto & otherECEF = other.getPositionECEF();
159 
160  double dX{otherECEF.getX() - selfECEF.getX()};
161  double dY{otherECEF.getY() - selfECEF.getY()};
162  double dZ{ otherECEF.getZ() - selfECEF.getZ()};
163 
164  double dLatitudeRadians{position_.getLatitudeRadians()};
165  double dLongitudeRadians{position_.getLongitudeRadians()};
166 
167  double dNorthMeters{-dX * sin(dLatitudeRadians) * cos(dLongitudeRadians) -
168  dY * sin(dLatitudeRadians) * sin(dLongitudeRadians) +
169  dZ * cos(dLatitudeRadians)};
170 
171  double dEastMeters{-dX * sin(dLongitudeRadians) + dY * cos(dLongitudeRadians)};
172 
173  double dUpMeters{dX * cos(dLatitudeRadians) * cos(dLongitudeRadians) +
174  dY * cos(dLatitudeRadians) * sin(dLongitudeRadians) +
175  dZ * sin(dLatitudeRadians)};
176 
177  PositionNEU otherNEU{dNorthMeters,dEastMeters,dUpMeters};
178 
179  if(bHasOrientation_ || bHasVelocity_)
180  {
181  otherNEU.rotate(adjustedOrientation_);
182  }
183 
184  return otherNEU;
185 };
186 
187 inline
189 {
190  return bValid_==false;
191 }
double getRollDegrees() const
Definition: orientation.inl:56
Holds the velocity elements associated with an NEM&#39;s location information.
Definition: velocity.h:48
double getYawDegrees() const
Definition: orientation.inl:68
std::pair< const Orientation &, bool > getAdjustedOrientation() const
double getElevationDegrees() const
Definition: velocity.inl:60
std::pair< const Orientation &, bool > getOrientation() const
bool update(const Position &position, const std::pair< const Orientation &, bool > &orientation, const std::pair< const Velocity &, bool > &velocity)
double getAzimuthDegrees() const
Definition: velocity.inl:54
void AI_TO_BE_DEGREES(double &val, const double A, const double B)
double getPitchDegrees() const
Definition: orientation.inl:62
void NEG_90_TO_POS_90_DEGREES(double &val)
std::pair< const Velocity &, bool > getVelocity() const
void rotate(const Orientation &orientation)
Definition: positionneu.inl:66
double getX() const
double getLatitudeRadians() const
Definition: position.inl:72
Holds pitch, yaw and roll.
Definition: orientation.h:45
PositionNEU getPositionNEU(const PositionOrientationVelocity &other) const
Holds latitude, longitude and altitude.
Definition: position.h:47
double getLongitudeRadians() const
Definition: position.inl:78