Skip to content
Snippets Groups Projects
Commit 5ac86801 authored by Nicolò Caruso's avatar Nicolò Caruso Committed by Matteo Pancotti
Browse files

[ARP] Propagator state log

Now PropagatorState is logged, the user-defined reference costructor and eigen vector3f were removed since logger needs trivially copiable structs
parent e283f416
No related branches found
No related tags found
No related merge requests found
...@@ -52,9 +52,13 @@ void Propagator::step() ...@@ -52,9 +52,13 @@ void Propagator::step()
: oldState); : oldState);
// Update Position propagating it with velocity // Update Position propagating it with velocity
state.x_prop = state.x_prop + state.v_prop * updatePeriod; state.setXProp(state.getXProp() + state.getVProp() * updatePeriod);
state.nPropagations++; state.nPropagations++;
state.timestamp = TimestampTimer::getTimestamp(); state.timestamp = TimestampTimer::getTimestamp();
// Log propagator state
PropagatorState logState(state);
Boardcore::Logger::getInstance().log(logState);
} }
void Propagator::setRocketNasState(const NASState& newRocketNasState) void Propagator::setRocketNasState(const NASState& newRocketNasState)
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#pragma once #pragma once
#include <algorithms/Algorithm.h> #include <algorithms/Algorithm.h>
#include <logger/Logger.h>
#include <miosix.h> #include <miosix.h>
#include <chrono> #include <chrono>
......
...@@ -31,50 +31,22 @@ namespace Boardcore ...@@ -31,50 +31,22 @@ namespace Boardcore
{ {
/** /**
* @brief Struct containing the state of the propagator. Stores the timestamp of * @brief State of the propagator, taking into account the prediction steps (0
* the propagation, the number of propagations since the last NAS rocket packet * if true NAS state) and the propagated NAS
* and the propagated NAS state already divided in significant vectors so that * @note Can be logged.
* computations with the NAS state are easier. *
* It also exposes a method to retrieve the propagated NAS state as a NASState
* structure.
*/ */
struct PropagatorState struct PropagatorState
{ {
uint64_t timestamp; ///< Prediction timestamp [ms] uint64_t timestamp; ///< Prediction timestamp [ms]
uint32_t nPropagations; ///< Predictions from last received NAS state uint32_t nPropagations; ///< Predictions from last received NAS state
Eigen::Vector3f x_prop; ///< Position propagation state NED [m] NASState nas;
Eigen::Vector3f v_prop; ///< Speed propagation state NED [m]
Eigen::Vector4f q_prop; ///< Quaternion propagation (scalar last)
Eigen::Vector3f b_prop; ///< Gyroscope bias propagation
PropagatorState()
: timestamp(0), nPropagations(0), x_prop(0, 0, 0), v_prop(0, 0, 0),
q_prop(0, 0, 0, 1), b_prop(0, 0, 0)
{
}
PropagatorState(const PropagatorState& newState) PropagatorState() : timestamp(0), nPropagations(0), nas() {}
: PropagatorState(newState.timestamp, newState.nPropagations,
newState.x_prop, newState.v_prop, newState.q_prop,
newState.b_prop)
{
}
PropagatorState(uint64_t timestamp, uint32_t nPropagations,
Eigen::Vector3f x_prop, Eigen::Vector3f v_prop,
Eigen::Vector4f q_prop, Eigen::Vector3f b_prop)
: timestamp(timestamp), nPropagations(nPropagations), x_prop(x_prop),
v_prop(v_prop), q_prop(q_prop), b_prop(b_prop)
{
}
PropagatorState(uint64_t timestamp, uint32_t nPropagations, PropagatorState(uint64_t timestamp, uint32_t nPropagations,
NASState nasState) NASState nasState)
: timestamp(timestamp), nPropagations(nPropagations), : timestamp(timestamp), nPropagations(nPropagations), nas(nasState)
x_prop(nasState.n, nasState.e, nasState.d),
v_prop(nasState.vn, nasState.ve, nasState.vd),
q_prop(nasState.qx, nasState.qy, nasState.qz, nasState.qw),
b_prop(nasState.bx, nasState.by, nasState.bz)
{ {
} }
...@@ -85,19 +57,48 @@ struct PropagatorState ...@@ -85,19 +57,48 @@ struct PropagatorState
void print(std::ostream& os) const void print(std::ostream& os) const
{ {
os << timestamp << "," << nPropagations << "," << x_prop(0) << "," os << timestamp << "," << nPropagations << "," << nas.n << "," << nas.e
<< x_prop(1) << "," << x_prop(2) << "," << v_prop(0) << "," << "," << nas.d << "," << nas.vn << "," << nas.ve << "," << nas.vd
<< v_prop(1) << "," << v_prop(2) << "," << q_prop(0) << "," << "," << nas.qx << "," << nas.qy << "," << nas.qz << "," << nas.qw
<< q_prop(1) << "," << q_prop(2) << "," << q_prop(3) << "," << "," << nas.bx << "," << nas.by << "," << nas.bz << "\n";
<< b_prop(0) << "," << b_prop(1) << "," << b_prop(2) << "\n";
} }
NASState getNasState() const NASState getNasState() const { return nas; }
Eigen::Vector3f getXProp() { return Eigen::Vector3f(nas.n, nas.e, nas.d); }
void setXProp(Eigen::Vector3f xProp)
{
nas.n = xProp(0);
nas.e = xProp(1);
nas.d = xProp(2);
}
Eigen::Vector3f getVProp()
{
return Eigen::Vector3f(nas.vn, nas.ve, nas.vd);
}
void setVProp(Eigen::Vector3f vProp)
{
nas.vn = vProp(0);
nas.ve = vProp(1);
nas.vd = vProp(2);
}
Eigen::Vector4f getQProp()
{
return Eigen::Vector4f(nas.qx, nas.qy, nas.qz, nas.qw);
}
void setQProp(Eigen::Vector4f qProp)
{
nas.qx = qProp(0);
nas.qy = qProp(1);
nas.qz = qProp(2);
nas.qw = qProp(3);
}
Eigen::Vector3f getBProp() { return Eigen::Vector3f(nas.n, nas.e, nas.d); }
void setBProp(Eigen::Vector3f bProp)
{ {
Eigen::Matrix<float, 13, 1> nasState; nas.bx = bProp(0);
// cppcheck-suppress constStatement nas.by = bProp(1);
nasState << x_prop, v_prop, q_prop, b_prop; nas.bz = bProp(2);
return NASState(timestamp, nasState);
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment