-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attitude Estimator Control Task (#91)
* attitude estimator only commit actually * add to main control loop * undefined ref error and fixes * estimator test * pass serializer test * fix include * pass teensy build * address some changes * change serializer bounds, pre const * add readablefields to constructor list * pan epoch, readable or internal T_T * piksi fix, but time assert wrong * fix const, but assertions still failing * change mag to vector * finally fix asserting statefields * pan epoch from psim
- Loading branch information
Showing
9 changed files
with
241 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "AttitudeEstimator.hpp" | ||
#include <gnc_constants.hpp> | ||
|
||
AttitudeEstimator::AttitudeEstimator(StateFieldRegistry ®istry, | ||
unsigned int offset) | ||
: TimedControlTask<void>(registry, offset), | ||
pan_epoch(gnc::constant::init_gps_week_number, | ||
gnc::constant::init_gps_time_of_week, | ||
gnc::constant::init_gps_nanoseconds), | ||
data(), | ||
state(), | ||
estimate(), | ||
q_body_eci_sr(), | ||
q_body_eci_f("attitude_estimator.q_body_eci", q_body_eci_sr), | ||
w_body_sr(-55, 55, 32*3), | ||
w_body_f("attitude_estimator.w_body", w_body_sr) | ||
{ | ||
|
||
piksi_time_fp = find_readable_field<gps_time_t>("piksi.time", __FILE__, __LINE__), | ||
pos_vec_ecef_fp = find_readable_field<d_vector_t>("piksi.pos", __FILE__, __LINE__), | ||
ssa_vec_rd_fp = find_readable_field<f_vector_t>("adcs_box.sun_vec", __FILE__, __LINE__), | ||
mag_vec_fp = find_readable_field<f_vector_t>("adcs_box.mag_vec", __FILE__, __LINE__), | ||
|
||
//assert inputs are found | ||
assert(piksi_time_fp); | ||
assert(pos_vec_ecef_fp); | ||
assert(ssa_vec_rd_fp); | ||
assert(mag_vec_fp); | ||
|
||
//Add outputs | ||
add_readable_field(q_body_eci_f); | ||
add_readable_field(w_body_f); | ||
} | ||
|
||
void AttitudeEstimator::execute(){ | ||
set_data(); | ||
gnc::estimate_attitude(state, data, estimate); | ||
set_estimate(); | ||
} | ||
|
||
void AttitudeEstimator::set_data(){ | ||
data.t = (double)(((unsigned long)(piksi_time_fp->get() - pan_epoch))/(1e9L)); | ||
|
||
data.r_ecef = lin::Vector3d({ | ||
pos_vec_ecef_fp->get()[0], | ||
pos_vec_ecef_fp->get()[1], | ||
pos_vec_ecef_fp->get()[2] | ||
}); | ||
|
||
data.b_body = lin::Vector3f({ | ||
mag_vec_fp->get()[0], | ||
mag_vec_fp->get()[1], | ||
mag_vec_fp->get()[2] | ||
}); | ||
|
||
data.s_body = lin::Vector3f({ | ||
ssa_vec_rd_fp->get()[0], | ||
ssa_vec_rd_fp->get()[1], | ||
ssa_vec_rd_fp->get()[2], | ||
}); | ||
|
||
} | ||
|
||
void AttitudeEstimator::set_estimate(){ | ||
|
||
f_quat_t q_temp; | ||
q_temp[0] = estimate.q_body_eci.operator()(0); | ||
q_temp[1] = estimate.q_body_eci.operator()(1); | ||
q_temp[2] = estimate.q_body_eci.operator()(2); | ||
q_temp[3] = estimate.q_body_eci.operator()(3); | ||
q_body_eci_f.set(q_temp); | ||
|
||
f_vector_t w_temp; | ||
w_temp[0] = estimate.w_body.operator()(0); | ||
w_temp[1] = estimate.w_body.operator()(1); | ||
w_temp[2] = estimate.w_body.operator()(2); | ||
w_body_f.set(w_temp); | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#ifndef ATTITUDE_ESTIMATOR_HPP_ | ||
#define ATTITUDE_ESTIMATOR_HPP_ | ||
|
||
#include <gnc_attitude_estimation.hpp> | ||
#include <TimedControlTask.hpp> | ||
|
||
/** | ||
* @brief Using raw sensor inputs, determine the attitude and angular state | ||
* of the spacecraft. | ||
*/ | ||
class AttitudeEstimator : public TimedControlTask<void> { | ||
public: | ||
/** | ||
* @brief Construct a new Attitude Estimator. | ||
* | ||
* @param registry | ||
*/ | ||
AttitudeEstimator(StateFieldRegistry& registry, unsigned int offset); | ||
|
||
/** | ||
* @brief Using raw sensor inputs, determine the attitude and angular state | ||
* of the spacecraft. | ||
*/ | ||
void execute() override; | ||
|
||
protected: | ||
|
||
/** | ||
* @brief Read data from field pointers and set the data object | ||
* | ||
*/ | ||
void set_data(); | ||
|
||
/** | ||
* @brief Set the estimate object from the outputs of the gnc estimate | ||
* | ||
*/ | ||
void set_estimate(); | ||
|
||
const gps_time_t pan_epoch; | ||
|
||
/** | ||
* @brief Inputs collected from Piksi and ADCSBoxMonitor. | ||
*/ | ||
//! Time from Piksi | ||
const ReadableStateField<gps_time_t>* piksi_time_fp; | ||
//! Position of this satellite, Vector of doubles | ||
const ReadableStateField<d_vector_t>* pos_vec_ecef_fp; | ||
//! Sun vector of this satellite, in the body frame. | ||
const ReadableStateField<f_vector_t>* ssa_vec_rd_fp; | ||
//! Magnetic field vector of this satellite in the body frame. | ||
const ReadableStateField<f_vector_t>* mag_vec_fp; | ||
|
||
//kyle's gnc structs | ||
gnc::AttitudeEstimatorData data; | ||
gnc::AttitudeEstimatorState state; | ||
gnc::AttitudeEstimate estimate; | ||
|
||
//AttitudeEstimate | ||
Serializer<f_quat_t> q_body_eci_sr; | ||
ReadableStateField<f_quat_t> q_body_eci_f; | ||
Serializer<f_vector_t> w_body_sr; | ||
ReadableStateField<f_vector_t> w_body_f; | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
test/test_fsw_attitude_estimator/test_attitude_estimator.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "../StateFieldRegistryMock.hpp" | ||
|
||
#include "../../src/FCCode/AttitudeEstimator.hpp" | ||
#include <unity.h> | ||
|
||
class TestFixture { | ||
public: | ||
StateFieldRegistryMock registry; | ||
|
||
// pointers to input statefields | ||
std::shared_ptr<ReadableStateField<gps_time_t>> piksi_time_fp; | ||
std::shared_ptr<ReadableStateField<d_vector_t>> pos_vec_ecef_fp; | ||
std::shared_ptr<ReadableStateField<f_vector_t>> ssa_vec_rd_fp; | ||
std::shared_ptr<ReadableStateField<f_vector_t>> mag_vec_fp; | ||
|
||
// pointers to output statefields for easy access | ||
ReadableStateField<f_quat_t>* q_body_eci_fp; | ||
ReadableStateField<f_vector_t>* w_body_fp; | ||
|
||
std::unique_ptr<AttitudeEstimator> attitude_estimator; | ||
|
||
// Create a TestFixture instance of AttitudeEstimator with pointers to statefields | ||
TestFixture() : registry(){ | ||
|
||
//create input statefields | ||
piksi_time_fp = registry.create_readable_field<gps_time_t>("piksi.time"); | ||
pos_vec_ecef_fp = registry.create_readable_vector_field<double>("piksi.pos",0.0L,1000000.0L,64*3); | ||
ssa_vec_rd_fp = registry.create_readable_vector_field<float>("adcs_box.sun_vec",-1.0,1.0,32*3), | ||
mag_vec_fp = registry.create_readable_vector_field<float>("adcs_box.mag_vec",-16e-4,16e4,32*3), | ||
|
||
attitude_estimator = std::make_unique<AttitudeEstimator>(registry, 0); | ||
|
||
// initialize pointers to statefields | ||
q_body_eci_fp = registry.find_readable_field_t<f_quat_t>("attitude_estimator.q_body_eci"); | ||
w_body_fp = registry.find_readable_field_t<f_vector_t>("attitude_estimator.w_body"); | ||
|
||
assert(q_body_eci_fp); | ||
assert(w_body_fp); | ||
|
||
} | ||
}; | ||
|
||
void test_task_initialization() | ||
{ | ||
TestFixture tf; | ||
} | ||
|
||
void test_execute(){ | ||
|
||
} | ||
|
||
int test_control_task() | ||
{ | ||
UNITY_BEGIN(); | ||
RUN_TEST(test_task_initialization); | ||
RUN_TEST(test_execute); | ||
return UNITY_END(); | ||
} | ||
|
||
#ifdef DESKTOP | ||
int main() | ||
{ | ||
return test_control_task(); | ||
} | ||
#else | ||
#include <Arduino.h> | ||
void setup() | ||
{ | ||
delay(2000); | ||
Serial.begin(9600); | ||
test_control_task(); | ||
} | ||
|
||
void loop() {} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters