Jpp 19.3.0-rc.2
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 // invert axis for central-logic board being upside down in optical module
115
116 A0 = A0;
117 A1 = -A1;
118 A2 = -A2;
119
120 H0 = H0;
121 H1 = -H1;
122 H2 = -H2;
123
124 this->roll = atan2(-A1, -A2);
125 this->pitch = atan2(A0, sqrt(A1*A1 + A2*A2));
126 this->yaw = atan2(H2 * sin(roll) - H1 * cos(roll), H0 * cos(pitch) + H1 * sin(pitch) * sin(roll) + H2 * sin(pitch) * cos(roll));
127 }
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 135 of file JCompass.hh.

135 :
136 yaw (0.0),
137 pitch(0.0),
138 roll (0.0)
139 {
140 using namespace std;
141
142 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()));
143
144 const double sp = 2.0*(Q.getA()*Q.getC() - Q.getD()*Q.getB());
145
146 if (sp >= +1.0)
147 this->pitch = asin(+1.0);
148 else if (sp <= -1.0)
149 this->pitch = asin(-1.0);
150 else
151 this->pitch = asin(sp);
152
153 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()));
154 }

Member Function Documentation

◆ getCompass()

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

Get compass.

Returns
this compass

Definition at line 162 of file JCompass.hh.

163 {
164 return static_cast<const JCompass&>(*this);
165 }
JCompass()
Default constructor.
Definition JCompass.hh:56

◆ setCompass()

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

Set compass.

Parameters
compasscompass

Definition at line 173 of file JCompass.hh.

174 {
175 static_cast<JCompass&>(*this) = compass;
176 }

◆ getRotation()

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

Get rotation matrix.

Returns
rotation matrix

Definition at line 184 of file JCompass.hh.

185 {
186 using namespace JPP;
187
188 const JRotation3D Rx = JRotation3X(-this->getRoll());
189 const JRotation3D Ry = JRotation3Y(+this->getPitch());
190 const JRotation3D Rz = JRotation3Z(-this->getYaw());
191
192 return (Rz * Ry * Rx);
193 }
double getYaw() const
Get yaw compass.
Definition JCompass.hh:224
double getRoll() const
Get roll compass.
Definition JCompass.hh:246
double getPitch() const
Get pitch compass.
Definition JCompass.hh:235
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 201 of file JCompass.hh.

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

◆ getYaw()

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

Get yaw compass.

Returns
yaw compass

Definition at line 224 of file JCompass.hh.

225 {
226 return yaw;
227 }

◆ getPitch()

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

Get pitch compass.

Returns
pitch compass

Definition at line 235 of file JCompass.hh.

236 {
237 return pitch;
238 }

◆ getRoll()

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

Get roll compass.

Returns
roll compass

Definition at line 246 of file JCompass.hh.

247 {
248 return roll;
249 }

◆ 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 259 of file JCompass.hh.

261 {
262 return (fabs(getYaw() - compass.getYaw()) <= precision &&
263 fabs(getPitch() - compass.getPitch()) <= precision &&
264 fabs(getRoll() - compass.getRoll()) <= precision);
265 }

◆ 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 274 of file JCompass.hh.

275 {
276 this->yaw += declination;
277 this->yaw -= meridian;
278 }

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 288 of file JCompass.hh.

289 {
290 in >> compass.yaw >> compass.pitch >> compass.roll;
291
292 return in;
293 }

◆ 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 303 of file JCompass.hh.

304 {
305 out << compass.getYaw() << ' ' << compass.getPitch() << ' ' << compass.getRoll();
306
307 return out;
308 }

◆ operator>> [2/2]

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

Read compasss from input.

Parameters
inreader
compasscompasss
Returns
reader

Definition at line 318 of file JCompass.hh.

319 {
320 in >> compass.yaw;
321 in >> compass.pitch;
322 in >> compass.roll;
323
324 return in;
325 }

◆ operator<< [2/2]

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

Write compasss to output.

Parameters
outwriter
compasscompasss
Returns
writer

Definition at line 335 of file JCompass.hh.

336 {
337 out << compass.yaw;
338 out << compass.pitch;
339 out << compass.roll;
340
341 return out;
342 }

Member Data Documentation

◆ yaw

double JDETECTOR::JCompass::yaw
protected

Definition at line 346 of file JCompass.hh.

◆ pitch

double JDETECTOR::JCompass::pitch
protected

Definition at line 347 of file JCompass.hh.

◆ roll

double JDETECTOR::JCompass::roll
protected

Definition at line 348 of file JCompass.hh.


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