WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
PointingVectorMeasurements.hpp
Go to the documentation of this file.
1/******************************************************************************
2* Copyright (c) ATTX LLC 2024. All Rights Reserved.
3*
4* This software and associated documentation (the "Software") are the
5* proprietary and confidential information of ATTX, LLC. The Software is
6* furnished under a license agreement between ATTX and the user organization
7* and may be used or copied only in accordance with the terms of the agreement.
8* Refer to 'license/attx_license.adoc' for standard license terms.
9*
10* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
11* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
12* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
13* transmitted in any form or by any means, for any purpose, without the express
14* written permission of ATTX, LLC.
15******************************************************************************/
16
17#ifndef GNCUTILS_EKF_POINTING_VECTOR_MEASUREMENTS_H
18#define GNCUTILS_EKF_POINTING_VECTOR_MEASUREMENTS_H
19
21#include "dynamics/Quaternion.h"
22
23namespace warpos {
24
25 // ***** Define the number of measurement vector elements, observer vector elements, and measurement noise elements ***** //
26 // Pointing vector (e.g. magnetometer, sun sensor) expressed in body frame coordinates
28 // Here observer state acts as a parameter inputs and must include: Expected pointing vector experienced by the
29 // sensor expressed in body frame coordinates.
31 // Every element of the measurement has an associated Gaussian noise.
33
60 template<uint32 N>
61 class PointingVectorMeasurements : public Measurements<N, POINTING_MEASUREMENT_MEASUREMENT_VECTOR_ELEMENTS, POINTING_MEASUREMENT_OBSERVER_VECTOR_ELEMENTS>{
62 public:
68 PointingVectorMeasurements(uint32 state_quat_index, uint32 observer_pointing_index = 0, uint32 observer_quat_index = 3, uint32 meas_pointing_index = 0) :
69 _quat_idx(state_quat_index),
70 _obs_pointing_idx(observer_pointing_index),
71 _obs_quat_idx(observer_quat_index),
72 _meas_pointing_idx(meas_pointing_index) {};
73
80 int16 calculateMeasurements(floating_point time,
81 const std::array<floating_point, N> &tar_state,
82 const std::array<floating_point, POINTING_MEASUREMENT_OBSERVER_VECTOR_ELEMENTS> &obs_state,
83 floating_point expected_measurement[POINTING_MEASUREMENT_MEASUREMENT_VECTOR_ELEMENTS]) override;
84
91 int16 calculateMeasurementsMatrix(floating_point time,
92 const std::array<floating_point, N> &tar_state,
93 const std::array<floating_point, POINTING_MEASUREMENT_OBSERVER_VECTOR_ELEMENTS> &obs_state,
94 floating_point measurement_Jacobian[N*POINTING_MEASUREMENT_MEASUREMENT_VECTOR_ELEMENTS]) override;
95
96 private:
98 uint32 _quat_idx;
100 uint32 _obs_pointing_idx;
102 uint32 _obs_quat_idx;
104 uint32 _meas_pointing_idx;
105
107 clockwerk::Quaternion _quat_body_ref;
111 clockwerk::Quaternion _quat_mag_body;
112
115 };
116
117
124 template<uint32 N>
126 const std::array<floating_point, N> &tar_state,
127 const std::array<floating_point, POINTING_MEASUREMENT_OBSERVER_VECTOR_ELEMENTS> &obs_state,
128 floating_point expected_measurement[POINTING_MEASUREMENT_MEASUREMENT_VECTOR_ELEMENTS]) {
129 // Gather the attitude quaternion
130 _quat_body_ref.setFromArray(&tar_state[_quat_idx]);
131 // Gather the mag field vector from params
132 _mag__ref.setFromArray(&obs_state[_obs_pointing_idx]);
133 // Rotate the expected local mag field from reference frame to body frame
134 _dummy3 = _quat_body_ref*_mag__ref;
135 // Output the result
136 _dummy3.getAsArray(&expected_measurement[_meas_pointing_idx]);
137
138 return NO_ERROR;
139 }
140
147 template<uint32 N>
149 const std::array<floating_point, N> &tar_state,
150 const std::array<floating_point, POINTING_MEASUREMENT_OBSERVER_VECTOR_ELEMENTS> &obs_state,
151 floating_point measurement_Jacobian[N*POINTING_MEASUREMENT_MEASUREMENT_VECTOR_ELEMENTS]) {
152 // Make sure quaternion index doesn't overrun the array
153 if (_quat_idx + 4 > N) {return ERROR_DIMENSIONS;}
154
155 // Gather the attitude quaternion
156 _quat_body_ref.setFromArray(&tar_state[_quat_idx]);
157
158 // Gather the mag field vector from params
159 _mag__ref.setFromArray(&obs_state[_obs_pointing_idx]);
160
161 // Compute the nonzero Jacobian term
162 clockwerk::Matrix<3, 4> dhdq = _quat_body_ref.dRotatedVec_dQuat(_mag__ref);
163
164 // Make matrix of all zeros and edit the correct terms
165 for(uint32 i = 0; i < N*POINTING_MEASUREMENT_MEASUREMENT_VECTOR_ELEMENTS; i++) {
166 measurement_Jacobian[i] = 0.0;
167 }
168 for (uint32 i = 0; i < 3; ++i) {
169 for (uint32 j = 0; j < 4; ++j) {
170 measurement_Jacobian[i*N + j+_quat_idx] = dhdq.get(i, j);
171 }
172 }
173 return NO_ERROR;
174 }
175}
176
177#endif
Standard vector class derived from Matrix.
Definition CartesianVector.hpp:39
Matrix math implementation.
Definition Matrix.hpp:55
int16 get(uint32 row, uint32 col, floating_point &result) const
Function to get a single value in the matrix.
Definition Matrix.hpp:394
void setFromArray(const floating_point *start_ptr, bool column_major=false)
Function to set the values of the matrix row-wise.
Definition Matrix.hpp:412
Quaternion class for attitude representation.
Definition Quaternion.h:68
Definition Measurements.hpp:41
int16 calculateMeasurements(floating_point time, const std::array< floating_point, N > &tar_state, const std::array< floating_point, POINTING_MEASUREMENT_OBSERVER_VECTOR_ELEMENTS > &obs_state, floating_point expected_measurement[POINTING_MEASUREMENT_MEASUREMENT_VECTOR_ELEMENTS]) override
Function to calculate a measurement from current state of system.
Definition PointingVectorMeasurements.hpp:125
int16 calculateMeasurementsMatrix(floating_point time, const std::array< floating_point, N > &tar_state, const std::array< floating_point, POINTING_MEASUREMENT_OBSERVER_VECTOR_ELEMENTS > &obs_state, floating_point measurement_Jacobian[N *POINTING_MEASUREMENT_MEASUREMENT_VECTOR_ELEMENTS]) override
Function to calculate the measurement function Jacobian from current state of system.
Definition PointingVectorMeasurements.hpp:148
PointingVectorMeasurements(uint32 state_quat_index, uint32 observer_pointing_index=0, uint32 observer_quat_index=3, uint32 meas_pointing_index=0)
Constructor of the class.
Definition PointingVectorMeasurements.hpp:68
#define NO_ERROR
Error code in the case where matrix math executed successfully.
Definition clockwerkerrors.h:34
#define ERROR_DIMENSIONS
Definition clockwerkerrors.h:41
Definition DeadReckon.cpp:20
const uint32 POINTING_MEASUREMENT_MEASUREMENT_VECTOR_ELEMENTS(3)
const uint32 POINTING_MEASUREMENT_OBSERVER_VECTOR_ELEMENTS(3)
const uint32 POINTING_MEASUREMENT_MEASUREMENT_NOISE_ELEMENTS(3)