generated from ut-issl/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #639 from ut-issl/feature/add_simple_flexible_stru…
…cture Add flexible structure model
- Loading branch information
Showing
13 changed files
with
573 additions
and
56 deletions.
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,75 @@ | ||
# | ||
# Plot Euler Angle of Cantilever Observer | ||
# | ||
# arg[1] : read_file_tag : time tag for default CSV output log file. ex. 220627_142946 | ||
# | ||
|
||
# | ||
# Import | ||
# | ||
# plots | ||
import matplotlib.pyplot as plt | ||
# local function | ||
from common import find_latest_log_tag | ||
from common import add_log_file_arguments | ||
from common import read_3d_vector_from_csv | ||
from common import read_scalar_from_csv | ||
# arguments | ||
import argparse | ||
|
||
# Arguments | ||
aparser = argparse.ArgumentParser() | ||
aparser = add_log_file_arguments(aparser) | ||
aparser.add_argument('--no-gui', action='store_true') | ||
args = aparser.parse_args() | ||
|
||
# | ||
# Read Arguments | ||
# | ||
# log file path | ||
path_to_logs = args.logs_dir | ||
|
||
read_file_tag = args.file_tag | ||
if read_file_tag == None: | ||
print("file tag does not found. use latest.") | ||
read_file_tag = find_latest_log_tag(path_to_logs) | ||
|
||
print("log: " + read_file_tag) | ||
|
||
# | ||
# CSV file name | ||
# | ||
read_file_name = path_to_logs + '/' + 'logs_' + read_file_tag + '/' + read_file_tag + '_default.csv' | ||
|
||
# | ||
# Data read and edit | ||
# | ||
# Read S2E CSV | ||
time = read_scalar_from_csv(read_file_name, 'elapsed_time[s]') | ||
|
||
euler_angle_cantilever_rad = read_3d_vector_from_csv(read_file_name, 'euler_angular_cantilever_c', 'rad') | ||
|
||
# | ||
# Plot | ||
# | ||
unit = ' rad' | ||
|
||
fig, axis = plt.subplots(3, 1, squeeze = False, tight_layout = True, sharex = True) | ||
axis[0, 0].plot(time[0][0:1200], euler_angle_cantilever_rad[0][0:1200], c="orange", label="TRUE-X") | ||
axis[0, 0].legend(loc = 'upper right') | ||
|
||
axis[1, 0].plot(time[0][0:1200], euler_angle_cantilever_rad[1][0:1200], c="green", label="TRUE-Y") | ||
axis[1, 0].legend(loc = 'upper right') | ||
|
||
axis[2, 0].plot(time[0][0:1200], euler_angle_cantilever_rad[2][0:1200], c="blue", label="TRUE-Z") | ||
axis[2, 0].legend(loc = 'upper right') | ||
|
||
fig.suptitle("Euler Angle Observer") | ||
fig.supylabel("Euler Angle [" + unit + "]") | ||
fig.supxlabel("Time [s]") | ||
|
||
# Data save | ||
if args.no_gui: | ||
plt.savefig(read_file_tag + "_angular_velocity_observer.png") # save last figure only | ||
else: | ||
plt.show() |
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
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
101 changes: 101 additions & 0 deletions
101
src/dynamics/attitude/attitude_with_cantilever_vibration.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,101 @@ | ||
/** | ||
* @file attitude_with_cantilever_vibration.cpp | ||
* @brief Class to calculate spacecraft attitude with cantilever vibration | ||
*/ | ||
#include "attitude_with_cantilever_vibration.hpp" | ||
|
||
#include <cassert> | ||
#include <logger/log_utility.hpp> | ||
#include <utilities/macros.hpp> | ||
|
||
AttitudeWithCantileverVibration::AttitudeWithCantileverVibration( | ||
const libra::Vector<3>& angular_velocity_b_rad_s, const libra::Quaternion& quaternion_i2b, const libra::Matrix<3, 3>& inertia_tensor_kgm2, | ||
const libra::Matrix<3, 3>& inertia_tensor_cantilever_kgm2, const double damping_ratio_cantilever, | ||
const double intrinsic_angular_velocity_cantilever_rad_s, const libra::Vector<3>& torque_b_Nm, const double propagation_step_s, | ||
const std::string& simulation_object_name) | ||
: Attitude(inertia_tensor_kgm2, simulation_object_name), | ||
numerical_integrator_(propagation_step_s, attitude_ode_, | ||
libra::numerical_integration::NumericalIntegrationMethod::kRk4) { //!< TODO: Set NumericalIntegrationMethod in *.ini file | ||
angular_velocity_b_rad_s_ = angular_velocity_b_rad_s; | ||
quaternion_i2b_ = quaternion_i2b; | ||
torque_b_Nm_ = torque_b_Nm; | ||
propagation_step_s_ = propagation_step_s; | ||
current_propagation_time_s_ = 0.0; | ||
angular_momentum_reaction_wheel_b_Nms_ = libra::Vector<3>(0.0); | ||
|
||
attitude_ode_.SetInertiaTensorCantilever_kgm2(inertia_tensor_cantilever_kgm2); | ||
attitude_ode_.SetPreviousInertiaTensor_kgm2(inertia_tensor_kgm2_); | ||
double attenuation_coefficient = 2 * damping_ratio_cantilever * intrinsic_angular_velocity_cantilever_rad_s; | ||
attitude_ode_.SetAttenuationCoefficient(attenuation_coefficient); | ||
double spring_coefficient = pow(intrinsic_angular_velocity_cantilever_rad_s, 2.0); | ||
attitude_ode_.SetSpringCoefficient(spring_coefficient); | ||
attitude_ode_.SetInverseInertiaTensor(CalcInverseMatrix(inertia_tensor_kgm2_)); | ||
libra::Matrix<3, 3> inverse_equivalent_inertia_tensor_cantilever = | ||
CalcInverseMatrix(inertia_tensor_kgm2_ - inertia_tensor_cantilever_kgm2) * inertia_tensor_kgm2_; | ||
attitude_ode_.SetInverseEquivalentInertiaTensorCantilever(inverse_equivalent_inertia_tensor_cantilever); | ||
attitude_ode_.SetTorque_b_Nm(torque_b_Nm_); | ||
attitude_ode_.SetAngularMomentumReactionWheel_b_Nms(angular_momentum_reaction_wheel_b_Nms_); | ||
|
||
CalcAngularMomentum(); | ||
} | ||
|
||
AttitudeWithCantileverVibration::~AttitudeWithCantileverVibration() {} | ||
|
||
std::string AttitudeWithCantileverVibration::GetLogHeader() const { | ||
std::string str_tmp = Attitude::GetLogHeader(); | ||
|
||
str_tmp += WriteVector("euler_angular_cantilever", "c", "rad", 3); | ||
str_tmp += WriteVector("angular_velocity_cantilever", "c", "rad/s", 3); | ||
|
||
return str_tmp; | ||
} | ||
|
||
std::string AttitudeWithCantileverVibration::GetLogValue() const { | ||
std::string str_tmp = Attitude::GetLogValue(); | ||
|
||
str_tmp += WriteVector(euler_angular_cantilever_rad_); | ||
str_tmp += WriteVector(angular_velocity_cantilever_rad_s_); | ||
|
||
return str_tmp; | ||
} | ||
|
||
void AttitudeWithCantileverVibration::SetParameters(const MonteCarloSimulationExecutor& mc_simulator) { | ||
Attitude::SetParameters(mc_simulator); | ||
GetInitializedMonteCarloParameterVector(mc_simulator, "angular_velocity_b_rad_s", angular_velocity_b_rad_s_); | ||
|
||
// TODO: Consider the following calculation is needed here? | ||
current_propagation_time_s_ = 0.0; | ||
angular_momentum_reaction_wheel_b_Nms_ = libra::Vector<3>(0.0); //!< TODO: Consider how to handle this variable | ||
CalcAngularMomentum(); | ||
} | ||
|
||
void AttitudeWithCantileverVibration::Propagate(const double end_time_s) { | ||
if (!is_calc_enabled_) return; | ||
|
||
libra::Matrix<3, 3> previous_inertia_tensor_kgm2 = attitude_ode_.GetPreviousInertiaTensor_kgm2(); | ||
assert(end_time_s - current_propagation_time_s_ > 1e-6); | ||
libra::Matrix<3, 3> dot_inertia_tensor = (1.0 / (end_time_s - current_propagation_time_s_)) * (inertia_tensor_kgm2_ - previous_inertia_tensor_kgm2); | ||
libra::Vector<3> torque_inertia_tensor_b_Nm = dot_inertia_tensor * angular_velocity_b_rad_s_; | ||
attitude_ode_.SetTorqueInertiaTensor_b_Nm(torque_inertia_tensor_b_Nm); | ||
attitude_ode_.SetInverseInertiaTensor(CalcInverseMatrix(inertia_tensor_kgm2_)); | ||
attitude_ode_.SetTorque_b_Nm(torque_b_Nm_); | ||
attitude_ode_.SetAngularMomentumReactionWheel_b_Nms(angular_momentum_reaction_wheel_b_Nms_); | ||
|
||
libra::Vector<13> state = attitude_ode_.SetStateFromPhysicalQuantities(angular_velocity_b_rad_s_, angular_velocity_cantilever_rad_s_, | ||
quaternion_i2b_, euler_angular_cantilever_rad_); | ||
numerical_integrator_.GetIntegrator()->SetState(propagation_step_s_, state); | ||
while (end_time_s - current_propagation_time_s_ - propagation_step_s_ > 1.0e-6) { | ||
numerical_integrator_.GetIntegrator()->Integrate(); | ||
current_propagation_time_s_ += propagation_step_s_; | ||
} | ||
numerical_integrator_.GetIntegrator()->SetState(end_time_s - current_propagation_time_s_, numerical_integrator_.GetIntegrator()->GetState()); | ||
numerical_integrator_.GetIntegrator()->Integrate(); | ||
attitude_ode_.SetPhysicalQuantitiesFromState(numerical_integrator_.GetIntegrator()->GetState(), angular_velocity_b_rad_s_, | ||
angular_velocity_cantilever_rad_s_, quaternion_i2b_, euler_angular_cantilever_rad_); | ||
quaternion_i2b_.Normalize(); | ||
|
||
// Update information | ||
current_propagation_time_s_ = end_time_s; | ||
attitude_ode_.SetPreviousInertiaTensor_kgm2(inertia_tensor_kgm2_); | ||
CalcAngularMomentum(); | ||
} |
Oops, something went wrong.