Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JDETECTOR::JCompass Class Reference

Data structure for compass in three dimensions. More...

#include <JCompass.hh>

Inheritance diagram for JDETECTOR::JCompass:
JLANG::JEquals< JFirst_t, JSecond_t >

Public Member Functions

 JCompass ()
 Default constructor.
 
 JCompass (const double yaw, const double pitch, const double roll)
 Constructor.
 
 JCompass (const JAHRS &data, const JAHRSCalibration &calibration)
 Constructor.
 
 JCompass (const JQuaternion3D &Q)
 Constructor.
 
const JCompassgetCompass () const
 Get compass.
 
void setCompass (const JCompass &compass)
 Set compass.
 
JRotation3D getRotation () const
 Get rotation matrix.
 
JQuaternion3D getQuaternion () const
 Get quaternion.
 
double getYaw () const
 Get yaw compass.
 
double getPitch () const
 Get pitch compass.
 
double getRoll () const
 Get roll compass.
 
bool equals (const JCompass &compass, const double precision=std::numeric_limits< double >::min()) const
 Check equality.
 
void correct (const double declination, const double meridian)
 Correct compass for magnetic declination and meridian convergence angle.
 

Protected Attributes

double yaw
 
double pitch
 
double roll
 

Friends

std::istream & operator>> (std::istream &in, JCompass &compass)
 Read compasss from input.
 
std::ostream & operator<< (std::ostream &out, const JCompass &compass)
 Write compasss to output.
 
JReaderoperator>> (JReader &in, JCompass &compass)
 Read compasss from input.
 
JWriteroperator<< (JWriter &out, const JCompass &compass)
 Write compasss to output.
 

Detailed Description

Data structure for compass in three dimensions.

Definitions of yaw, pitch and roll.

Note that the z-axis of the KM3NeT reference system points up.
So, the yaw angle, measured by the compass is measured from North to East (since in the compass system z-axis points down).
Note also that the sign of the angle JCompass::pitch is maintained and the signs of the angles JCompass::yaw and JCompass::roll inverted when converting to/from a rotation matrix or quaternion.

This class implements the JMATH::JMath and JLANG::JEquals interfaces.

Definition at line 49 of file JCompass.hh.

Constructor & Destructor Documentation

◆ JCompass() [1/4]

JDETECTOR::JCompass::JCompass ( )
inline

Default constructor.

Definition at line 56 of file JCompass.hh.

56 :
57 yaw (0.0),
58 pitch(0.0),
59 roll (0.0)
60 {}

◆ JCompass() [2/4]

JDETECTOR::JCompass::JCompass ( const double yaw,
const double pitch,
const double roll )
inline

Constructor.

Parameters
yawyaw angle [rad]
pitchpitch angle [rad]
rollroll angle [rad]

Definition at line 70 of file JCompass.hh.

72 :
73 yaw (yaw),
74 pitch(pitch),
75 roll (roll)
76 {}

◆ JCompass() [3/4]

JDETECTOR::JCompass::JCompass ( const JAHRS & data,
const JAHRSCalibration & calibration )
inline

Constructor.

Parameters
dataAHRS data
calibrationAHRS calibration

Definition at line 85 of file JCompass.hh.

86 {
87 using namespace std;
88 using namespace JPP;
89
90 double A0 = data.AHRS_A0;
91 double A1 = data.AHRS_A1;
92 double A2 = data.AHRS_A2;
93
94 double H0 = data.AHRS_H0;
95 double H1 = data.AHRS_H1;
96 double H2 = data.AHRS_H2;
97
98 A0 -= calibration.ACC_OFFSET_X;
99 A1 -= calibration.ACC_OFFSET_Y;
100 A2 -= calibration.ACC_OFFSET_Z;
101
102 JMatrix3D(calibration.ACC_ROT_XX, calibration.ACC_ROT_XY, calibration.ACC_ROT_XZ,
103 calibration.ACC_ROT_YX, calibration.ACC_ROT_YY, calibration.ACC_ROT_YZ,
104 calibration.ACC_ROT_ZX, calibration.ACC_ROT_ZY, calibration.ACC_ROT_ZZ).transform(A0, A1, A2);
105
106 H0 -= 0.5 * (calibration.MAG_XMIN + calibration.MAG_XMAX);
107 H1 -= 0.5 * (calibration.MAG_YMIN + calibration.MAG_YMAX);
108 H2 -= 0.5 * (calibration.MAG_ZMIN + calibration.MAG_ZMAX);
109
110 JMatrix3D(calibration.MAG_ROT_XX, calibration.MAG_ROT_XY, calibration.MAG_ROT_XZ,
111 calibration.MAG_ROT_YX, calibration.MAG_ROT_YY, calibration.MAG_ROT_YZ,
112 calibration.MAG_ROT_ZX, calibration.MAG_ROT_ZY, calibration.MAG_ROT_ZZ).transform(H0, H1, H2);
113
114 // from CLB->DOM (rotation around X) + from nautical (X-North, Y-East, Z-down) to UTM-like (X: East, Y: North, Z:up)
115
116 double prev0 = A0;
117 A0 = -A1;
118 A1 = prev0;
119 A2 = A2;
120
121 prev0 = H0;
122 H0 = -H1;
123 H1 = prev0;
124 H2 = H2;
125
126 this->roll = atan2(A1, A2);
127 this->pitch = atan2(-A0, sqrt(A1*A1 + A2*A2));
128 this->yaw = atan2(H0 * cos(pitch) + H1 * sin(pitch) * sin(roll) + H2 * sin(pitch) * cos(roll), H1 * cos(pitch) - H2 * sin(pitch) );
129 }
void transform(double &__x, double &__y, double &__z) const
Transform.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Calibration.
Definition JHead.hh:330

◆ JCompass() [4/4]

JDETECTOR::JCompass::JCompass ( const JQuaternion3D & Q)
inline

Constructor.

Parameters
Qquaternion

Definition at line 137 of file JCompass.hh.

137 :
138 yaw (0.0),
139 pitch(0.0),
140 roll (0.0)
141 {
142 using namespace std;
143
144 this->yaw = atan2(2.0*(Q.getA()*Q.getD() + Q.getB()*Q.getC()), 1.0 - 2.0*(Q.getC()*Q.getC() + Q.getD()*Q.getD()));
145
146 double tp = 2.0*(Q.getA()*Q.getC() - Q.getB()*Q.getD());
147 this->pitch = 2.0*atan2(sqrt(1.0 + tp), sqrt(1.0 - tp) ) - M_PI / 2.0;
148
149 this->roll = atan2(2.0*(Q.getA()*Q.getB() + Q.getC()*Q.getD()), 1.0 - 2.0*(Q.getB()*Q.getB() + Q.getC()*Q.getC()));
150 }

Member Function Documentation

◆ getCompass()

const JCompass & JDETECTOR::JCompass::getCompass ( ) const
inline

Get compass.

Returns
this compass

Definition at line 158 of file JCompass.hh.

159 {
160 return static_cast<const JCompass&>(*this);
161 }
JCompass()
Default constructor.
Definition JCompass.hh:56

◆ setCompass()

void JDETECTOR::JCompass::setCompass ( const JCompass & compass)
inline

Set compass.

Parameters
compasscompass

Definition at line 169 of file JCompass.hh.

170 {
171 static_cast<JCompass&>(*this) = compass;
172 }

◆ getRotation()

JRotation3D JDETECTOR::JCompass::getRotation ( ) const
inline

Get rotation matrix.

This is active rotation matrix taken from passive meausurements.

Returns
rotation matrix

Definition at line 181 of file JCompass.hh.

182 {
183 using namespace JPP;
184
185 const JRotation3D Rx = JRotation3X(+this->getRoll());
186 const JRotation3D Ry = JRotation3Y(+this->getPitch());
187 const JRotation3D Rz = JRotation3Z(+this->getYaw());
188
189 return (Rz * Ry * Rx);
190 }
double getYaw() const
Get yaw compass.
Definition JCompass.hh:221
double getRoll() const
Get roll compass.
Definition JCompass.hh:243
double getPitch() const
Get pitch compass.
Definition JCompass.hh:232
Rotation around X-axis.
Rotation around Y-axis.
Rotation around Z-axis.

◆ getQuaternion()

JQuaternion3D JDETECTOR::JCompass::getQuaternion ( ) const
inline

Get quaternion.

Returns
quaternion

Definition at line 198 of file JCompass.hh.

199 {
200 using namespace JPP;
201
202 const double cy = cos(0.5 * yaw);
203 const double sy = sin(0.5 * yaw);
204 const double cp = cos(0.5 * pitch);
205 const double sp = sin(0.5 * pitch);
206 const double cr = cos(0.5 * roll);
207 const double sr = sin(0.5 * roll);
208
209 return JQuaternion3D(cr * cp * cy + sr * sp * sy,
210 sr * cp * cy - cr * sp * sy,
211 cr * sp * cy + sr * cp * sy,
212 cr * cp * sy - sr * sp * cy);
213 }
Data structure for unit quaternion in three dimensions.

◆ getYaw()

double JDETECTOR::JCompass::getYaw ( ) const
inline

Get yaw compass.

Returns
yaw compass

Definition at line 221 of file JCompass.hh.

222 {
223 return yaw;
224 }

◆ getPitch()

double JDETECTOR::JCompass::getPitch ( ) const
inline

Get pitch compass.

Returns
pitch compass

Definition at line 232 of file JCompass.hh.

233 {
234 return pitch;
235 }

◆ getRoll()

double JDETECTOR::JCompass::getRoll ( ) const
inline

Get roll compass.

Returns
roll compass

Definition at line 243 of file JCompass.hh.

244 {
245 return roll;
246 }

◆ equals()

bool JDETECTOR::JCompass::equals ( const JCompass & compass,
const double precision = std::numeric_limits<double>::min() ) const
inline

Check equality.

Parameters
compasscompass
precisionnumerical precision
Returns
true if compass's are equal; else false

Definition at line 256 of file JCompass.hh.

258 {
259 return (fabs(getYaw() - compass.getYaw()) <= precision &&
260 fabs(getPitch() - compass.getPitch()) <= precision &&
261 fabs(getRoll() - compass.getRoll()) <= precision);
262 }

◆ correct()

void JDETECTOR::JCompass::correct ( const double declination,
const double meridian )
inline

Correct compass for magnetic declination and meridian convergence angle.

Parameters
declinationmagnetic declination [rad]
meridianmeridian convergence angle [rad]

Definition at line 271 of file JCompass.hh.

272 {
273 this->yaw -= declination;
274 this->yaw += meridian;
275 }

Friends And Related Symbol Documentation

◆ operator>> [1/2]

std::istream & operator>> ( std::istream & in,
JCompass & compass )
friend

Read compasss from input.

Parameters
ininput stream
compasscompasss
Returns
input stream

Definition at line 285 of file JCompass.hh.

286 {
287 in >> compass.yaw >> compass.pitch >> compass.roll;
288
289 return in;
290 }

◆ operator<< [1/2]

std::ostream & operator<< ( std::ostream & out,
const JCompass & compass )
friend

Write compasss to output.

Parameters
outoutput stream
compasscompass
Returns
output stream

Definition at line 300 of file JCompass.hh.

301 {
302 out << compass.getYaw() << ' ' << compass.getPitch() << ' ' << compass.getRoll();
303
304 return out;
305 }

◆ operator>> [2/2]

JReader & operator>> ( JReader & in,
JCompass & compass )
friend

Read compasss from input.

Parameters
inreader
compasscompasss
Returns
reader

Definition at line 315 of file JCompass.hh.

316 {
317 in >> compass.yaw;
318 in >> compass.pitch;
319 in >> compass.roll;
320
321 return in;
322 }

◆ operator<< [2/2]

JWriter & operator<< ( JWriter & out,
const JCompass & compass )
friend

Write compasss to output.

Parameters
outwriter
compasscompasss
Returns
writer

Definition at line 332 of file JCompass.hh.

333 {
334 out << compass.yaw;
335 out << compass.pitch;
336 out << compass.roll;
337
338 return out;
339 }

Member Data Documentation

◆ yaw

double JDETECTOR::JCompass::yaw
protected

Definition at line 343 of file JCompass.hh.

◆ pitch

double JDETECTOR::JCompass::pitch
protected

Definition at line 344 of file JCompass.hh.

◆ roll

double JDETECTOR::JCompass::roll
protected

Definition at line 345 of file JCompass.hh.


The documentation for this class was generated from the following file: