Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add distance sensor #15

Merged
merged 4 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion s2e-core
Submodule s2e-core updated 72 files
+4 −0 .github/labels.yml
+70 −8 .github/workflows/build.yml
+1 −1 .github/workflows/labeler.yml
+31 −0 .github/workflows/validate-scripts.yml
+2 −0 .gitignore
+25 −11 CMakeLists.txt
+4 −0 ExtLibraries/CMakeLists.txt
+11 −0 ExtLibraries/GeoPotential/CMakeLists.txt
+65,338 −0 ExtLibraries/GeoPotential/egm96_to360.ascii
+14 −0 ExtLibraries/README.md
+11 −5 ExtLibraries/cspice/CMakeLists.txt
+6 −2 ExtLibraries/cspice/install_step.cmake
+11 −3 ExtLibraries/nrlmsise00/CMakeLists.txt
+7 −0 README.md
+9 −4 common.cmake
+39 −0 data/SampleSat/gen_graph.sh
+11 −0 data/SampleSat/graph.toml
+4 −1 data/SampleSat/ini/SampleDisturbance.ini
+8 −14 data/SampleSat/ini/SampleGS.ini
+2 −2 data/SampleSat/ini/SampleSat.ini
+1 −0 data/SampleSat/ini/SampleSimBase.ini
+9 −0 renovate.json
+15 −0 scripts/Plot/Pipfile
+371 −0 scripts/Plot/Pipfile.lock
+15 −0 scripts/Plot/make_miller_projection_map.py
+92 −0 scripts/Plot/plot_gs_visibility.py
+66 −0 scripts/Plot/plot_satellite_orbit_on_miller.py
+2 −2 src/Component/CMakeLists.txt
+0 −54 src/Component/CommGS/ANT.cpp
+0 −42 src/Component/CommGS/ANT.h
+52 −0 src/Component/CommGS/Antenna.cpp
+49 −0 src/Component/CommGS/Antenna.hpp
+24 −61 src/Component/CommGS/GScalculator.cpp
+17 −26 src/Component/CommGS/GScalculator.h
+0 −5 src/Component/CommGS/InitAnt.hpp
+3 −3 src/Component/CommGS/InitAntenna.cpp
+5 −0 src/Component/CommGS/InitAntenna.hpp
+8 −3 src/Component/Mission/Telescope/Telescope.h
+1 −1 src/Disturbance/CMakeLists.txt
+16 −12 src/Disturbance/Disturbances.cpp
+2 −2 src/Disturbance/Disturbances.h
+0 −75 src/Disturbance/GGDist.cpp
+44 −0 src/Disturbance/GravityGradient.cpp
+11 −11 src/Disturbance/GravityGradient.hpp
+13 −2 src/Disturbance/InitDisturbance.cpp
+6 −2 src/Disturbance/InitDisturbance.hpp
+29 −2 src/Dynamics/Attitude/ControlledAttitude.cpp
+8 −4 src/Dynamics/Attitude/ControlledAttitude.h
+1 −2 src/Dynamics/Dynamics.cpp
+5 −0 src/Environment/Global/CelestialInformation.cpp
+3 −2 src/Environment/Global/CelestialInformation.h
+16 −6 src/Environment/Global/SimTime.cpp
+2 −0 src/Environment/Global/SimTime.h
+12 −0 src/Environment/Local/LocalCelestialInformation.cpp
+8 −4 src/Environment/Local/LocalCelestialInformation.h
+6 −0 src/Environment/Local/LocalEnvironment.cpp
+3 −9 src/Interface/InitInput/CMakeLists.txt
+49 −0 src/Interface/InitInput/IniAccess.cpp
+0 −134 src/Interface/InitInput/IniAccessUnix.cpp
+8 −0 src/Library/math/Quaternion.cpp
+3 −0 src/Library/math/Quaternion.hpp
+71 −23 src/RelativeInformation/RelativeInformation.cpp
+31 −11 src/RelativeInformation/RelativeInformation.h
+6 −0 src/Simulation/Case/SampleCase.cpp
+2 −0 src/Simulation/Case/SampleCase.h
+64 −7 src/Simulation/GroundStation/GroundStation.cpp
+22 −10 src/Simulation/GroundStation/GroundStation.h
+3 −3 src/Simulation/GroundStation/SampleGroundStation/SampleGS.cpp
+3 −5 src/Simulation/GroundStation/SampleGroundStation/SampleGS.h
+5 −5 src/Simulation/GroundStation/SampleGroundStation/SampleGSComponents.cpp
+7 −6 src/Simulation/GroundStation/SampleGroundStation/SampleGSComponents.h
+2 −2 src/Simulation/Spacecraft/Spacecraft.cpp
2 changes: 2 additions & 0 deletions s2e-ff/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ add_subdirectory(${S2E_CORE_DIR}/src/Simulation S2E_CORE/Simulation)

set(SOURCE_FILES
src/S2eFf.cpp
src/Components/AOCS/RelativeDistanceSensor.cpp
src/Components/AOCS/InitializeRelativeDistanceSensor.cpp
src/Simulation/Case/FfCase.cpp
src/Simulation/Spacecraft/FfSat.cpp
src/Simulation/Spacecraft/FfComponents.cpp
Expand Down
26 changes: 26 additions & 0 deletions s2e-ff/data/ini/Components/RelativeDistanceSensor.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[RelativeDistanceSensor]
target_sat_id = 1
reference_sat_id = 0

[ComponentBase]
// Prescaler with respect to the component update period
prescaler = 1

[SensorBase]
scale_factor_c(0) = 1;

// Constant bias noise [m]
constant_bias_c(0) = 10.0

// Standard deviation of normal random noise [m]
nromal_random_standard_deviation_c(0) = 1.0
suzuki-toshihir0 marked this conversation as resolved.
Show resolved Hide resolved

// Standard deviation for random walk noise [m]
random_walk_standard_deviation_c(0) = 0.0

// Limit of random walk noise [m]
random_walk_limit_c(0) = 0.0

// Range [m]
range_to_const = 1000000.0 // smaller than range_to_zero_m
range_to_zero = 10000000.0
1 change: 1 addition & 0 deletions s2e-ff/data/ini/FfSat.ini
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,4 @@ structure_file = ../../data/ini/FfSatStructure.ini

[COMPONENTS_FILE]
// Users can add the path for component initialize files here.
relative_distance_sensor_file = ../../data/ini/Components/RelativeDistanceSensor.ini
60 changes: 60 additions & 0 deletions s2e-ff/src/Components/AOCS/InitializeRelativeDistanceSensor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "InitializeRelativeDistanceSensor.hpp"

#include <Interface/InitInput/IniAccess.h>

RelativeDistanceSensor InitializeRelativeDistanceSensor(ClockGenerator* clock_gen, const std::string file_name,
const double compo_step_time_s, const RelativeInformation& rel_info) {
// General
IniAccess ini_file(file_name);

// CompoBase
int prescaler = ini_file.ReadInt("ComponentBase", "prescaler");
if (prescaler <= 1) prescaler = 1;

// SensorBase
SensorBase<1> sensor_base = ReadSensorBaseInformation<1>(file_name, compo_step_time_s * (double)(prescaler));

// RelativeDistanceSensor
char section[30] = "RelativeDistanceSensor";
int target_sat_id = ini_file.ReadInt(section, "target_sat_id");
int reference_sat_id = ini_file.ReadInt(section, "reference_sat_id");

RelativeDistanceSensor relative_distance_sensor(prescaler, clock_gen, sensor_base, target_sat_id, reference_sat_id, rel_info);

return relative_distance_sensor;
}

template <size_t N>
SensorBase<N> ReadSensorBaseInformation(const std::string file_name, const double step_width) {
suzuki-toshihir0 marked this conversation as resolved.
Show resolved Hide resolved
IniAccess ini_file(file_name);
char section[30] = "SensorBase";

libra::Vector<N * N> scale_factor_vector;
ini_file.ReadVector(section, "scale_factor_c", scale_factor_vector);
libra::Matrix<N, N> scale_factor_c;
for (size_t i = 0; i < N; i++) {
for (size_t j = 0; j < N; j++) {
scale_factor_c[i][j] = scale_factor_vector[i * N + j];
}
}

libra::Vector<N> constant_bias_c;
ini_file.ReadVector(section, "constant_bias_c", constant_bias_c);
Vector<N> nromal_random_standard_deviation_c;
ini_file.ReadVector(section, "nromal_random_standard_deviation_c", nromal_random_standard_deviation_c);
Vector<N> random_walk_standard_deviation_c;
ini_file.ReadVector(section, "random_walk_standard_deviation_c", random_walk_standard_deviation_c);
Vector<N> random_walk_limit_c;
ini_file.ReadVector(section, "random_walk_limit_c", random_walk_limit_c);

double range_to_const = ini_file.ReadDouble(section, "range_to_const");
Vector<N> range_to_const_c{range_to_const};
double range_to_zero = ini_file.ReadDouble(section, "range_to_zero");
Vector<N> range_to_zero_c{range_to_zero};

SensorBase<N> sensor_base(scale_factor_c, range_to_const_c, range_to_zero_c,
constant_bias_c, nromal_random_standard_deviation_c,
step_width, random_walk_standard_deviation_c, random_walk_limit_c);

return sensor_base;
}
10 changes: 10 additions & 0 deletions s2e-ff/src/Components/AOCS/InitializeRelativeDistanceSensor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include "./RelativeDistanceSensor.hpp"

RelativeDistanceSensor InitializeRelativeDistanceSensor(ClockGenerator* clock_gen, const std::string file_name,
const double compo_step_time_s, const RelativeInformation& rel_info);

// TODO:これをコアに移して全体で共有したい
suzuki-toshihir0 marked this conversation as resolved.
Show resolved Hide resolved
template <size_t N>
SensorBase<N> ReadSensorBaseInformation(const std::string file_name, const double step_width_s);
31 changes: 31 additions & 0 deletions s2e-ff/src/Components/AOCS/RelativeDistanceSensor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "RelativeDistanceSensor.hpp"

RelativeDistanceSensor::RelativeDistanceSensor(const int prescaler, ClockGenerator* clock_gen, SensorBase& sensor_base,
const int target_sat_id, const int reference_sat_id,
const RelativeInformation& rel_info)
: ComponentBase(prescaler, clock_gen), SensorBase(sensor_base),
target_sat_id_(target_sat_id), reference_sat_id_(reference_sat_id), rel_info_(rel_info) {}

RelativeDistanceSensor::~RelativeDistanceSensor() {}

void RelativeDistanceSensor::MainRoutine(int count) {
UNUSED(count);

measured_distance_bw_ref_target_m_[0] = rel_info_.GetRelativeDistance_m(target_sat_id_, reference_sat_id_);
measured_distance_bw_ref_target_m_ = Measure(measured_distance_bw_ref_target_m_); // Add Noise
}

std::string RelativeDistanceSensor::GetLogHeader() const {
std::string str_tmp = "";
str_tmp += WriteScalar("relative_distance_sensor_ref_to_target", "m");

return str_tmp;
}

std::string RelativeDistanceSensor::GetLogValue() const {
std::string str_tmp = "";

str_tmp += WriteScalar(measured_distance_bw_ref_target_m_[0]);

return str_tmp;
}
38 changes: 38 additions & 0 deletions s2e-ff/src/Components/AOCS/RelativeDistanceSensor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef RELATIVE_DISTANCE_SENSOR_H_
#define RELATIVE_DISTANCE_SENSOR_H_

#include <Interface/LogOutput/ILoggable.h>
#include <RelativeInformation/RelativeInformation.h>

#include <Component/Abstract/ComponentBase.h>
#include <Component/Abstract/SensorBase.h>

class RelativeDistanceSensor : public ComponentBase, public SensorBase<1>, public ILoggable {
public:
RelativeDistanceSensor(const int prescaler, ClockGenerator* clock_gen, SensorBase& sensor_base,
const int target_sat_id, const int reference_sat_id,
const RelativeInformation& rel_info);
~RelativeDistanceSensor();
// ComponentBase
void MainRoutine(int count) override;

// ILoggable
virtual std::string GetLogHeader() const;
virtual std::string GetLogValue() const;

// Getter
inline double GetMeasuredDistance_m() const { return measured_distance_bw_ref_target_m_[0]; }

// Setter
void SetTargetSatId(const int target_sat_id) { target_sat_id_ = target_sat_id; }

protected:
int target_sat_id_;
const int reference_sat_id_;

libra::Vector<1> measured_distance_bw_ref_target_m_{0.0};

const RelativeInformation& rel_info_;
};

#endif
4 changes: 4 additions & 0 deletions s2e-ff/src/Simulation/Case/FfCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ void FfCase::Initialize() {
for (auto& sc : satellites_) {
sc->LogSetup(*(sim_config_.main_logger_));
}
relative_information_.LogSetup(*(sim_config_.main_logger_));

// Write headers to the log
sim_config_.main_logger_->WriteHeaders();

Expand All @@ -40,6 +42,8 @@ void FfCase::Main() {
for (auto& sc : satellites_) {
sc->Update(&(glo_env_->GetSimTime()));
}
// Relative Information
relative_information_.Update();
// Debug output
if (glo_env_->GetSimTime().GetState().disp_output) {
std::cout << "Progresss: " << glo_env_->GetSimTime().GetProgressionRate() << "%\r";
Expand Down
20 changes: 14 additions & 6 deletions s2e-ff/src/Simulation/Spacecraft/FfComponents.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
#include "FfComponents.hpp"

#include <Interface/InitInput/IniAccess.h>
#include "../../Components/AOCS/InitializeRelativeDistanceSensor.hpp"

FfComponents::FfComponents(const Dynamics* dynamics, const Structure* structure, const LocalEnvironment* local_env, const GlobalEnvironment* glo_env,
const SimulationConfig* config, ClockGenerator* clock_gen)
: dynamics_(dynamics), structure_(structure), local_env_(local_env), glo_env_(glo_env), config_(config) {
const SimulationConfig* config, ClockGenerator* clock_gen, const RelativeInformation* rel_info)
: dynamics_(dynamics), structure_(structure), local_env_(local_env), glo_env_(glo_env), config_(config), rel_info_(rel_info) {

//General
IniAccess sat_file = IniAccess(config->sat_file_[0]);
double compo_step_sec = glo_env_->GetSimTime().GetCompoStepSec();

// Component Instantiation
obc_ = new OBC(clock_gen);

const std::string rel_dist_file = sat_file.ReadString("COMPONENTS_FILE", "relative_distance_sensor_file");
rel_dist_ = new RelativeDistanceSensor(InitializeRelativeDistanceSensor(clock_gen, rel_dist_file, compo_step_sec, *rel_info_));
}

FfComponents::~FfComponents() {
delete rel_dist_;
// OBC must be deleted the last since it has com ports
delete obc_;
}
Expand All @@ -25,7 +36,4 @@ Vector<3> FfComponents::GenerateTorque_Nm_b() {
return torque_Nm_b_;
}

void FfComponents::LogSetup(Logger& logger) {
// Users can set log output when they need component log
UNUSED(logger);
}
void FfComponents::LogSetup(Logger& logger) { logger.AddLoggable(rel_dist_); }
5 changes: 4 additions & 1 deletion s2e-ff/src/Simulation/Spacecraft/FfComponents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
#include "Vector.hpp"

// include for components
#include "../../Components/AOCS/RelativeDistanceSensor.hpp"
#include "OBC.h"

class FfComponents : public InstalledComponents {
public:
FfComponents(const Dynamics* dynamics, const Structure* structure, const LocalEnvironment* local_env, const GlobalEnvironment* glo_env,
const SimulationConfig* config, ClockGenerator* clock_gen);
const SimulationConfig* config, ClockGenerator* clock_gen, const RelativeInformation* rel_info);
~FfComponents();
libra::Vector<3> GenerateForce_N_b();
libra::Vector<3> GenerateTorque_Nm_b();
Expand All @@ -22,11 +23,13 @@ class FfComponents : public InstalledComponents {
private:
// Components
OBC* obc_;
RelativeDistanceSensor* rel_dist_;
suzuki-toshihir0 marked this conversation as resolved.
Show resolved Hide resolved

// References
const Dynamics* dynamics_;
const Structure* structure_;
const LocalEnvironment* local_env_;
const GlobalEnvironment* glo_env_;
const SimulationConfig* config_;
const RelativeInformation* rel_info_;
};
2 changes: 1 addition & 1 deletion s2e-ff/src/Simulation/Spacecraft/FfSat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

FfSat::FfSat(SimulationConfig* sim_config, const GlobalEnvironment* glo_env, RelativeInformation* relative_information, const int sat_id)
: Spacecraft(sim_config, glo_env, relative_information, sat_id) {
components_ = new FfComponents(dynamics_, structure_, local_env_, glo_env, sim_config, &clock_gen_);
components_ = new FfComponents(dynamics_, structure_, local_env_, glo_env, sim_config, &clock_gen_, relative_information);
}