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

Modify to suit with S2E-CORE Coding rule #77

Merged
merged 48 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
a9eebfb
Fix main file
200km Oct 6, 2023
c3d6727
Fix comment
200km Oct 6, 2023
4024e7c
Fix case
200km Oct 6, 2023
48b8f5b
Fix case.h to case.hpp
200km Oct 6, 2023
ad2e10c
Fix port_config.h to port_config.hpp
200km Oct 6, 2023
0cb5976
Fix components.h to components.hpp
200km Oct 6, 2023
ab42138
Modify aocs module components
200km Oct 6, 2023
5691a44
Fix satellite.h to satellite.hpp
200km Oct 6, 2023
96e9be1
Fix CRC
200km Oct 6, 2023
3992603
Fix cmd_size
200km Oct 6, 2023
06ed40f
Fix count for MainRoutine
200km Oct 6, 2023
65a9905
Fix clock_gen
200km Oct 6, 2023
aedf1bb
Fix format
200km Oct 6, 2023
2564a05
Fix INA260 class name
200km Oct 6, 2023
e43cc77
Fix INA260 enum class name
200km Oct 6, 2023
1758174
Fix STIM210 class name
200km Oct 6, 2023
60ee5ec
Fix RW0003 class name
200km Oct 6, 2023
13bebce
Fix i2c_addr
200km Oct 6, 2023
08578c9
Fix typo
200km Oct 6, 2023
a7ebd40
Fix typo
200km Oct 6, 2023
cfe4595
Fix local variables name in RW
200km Oct 6, 2023
3432567
Fix RM3100 class name
200km Oct 6, 2023
0632f9b
Fix mag_sensor
200km Oct 6, 2023
77e325a
Fix variables name
200km Oct 6, 2023
d8c28de
Fix ORM7600 class name
200km Oct 6, 2023
88e9b44
Fix ORM7600 variables name
200km Oct 6, 2023
df0b341
Fix typo
200km Oct 6, 2023
6542000
Fix ORM7600 function name
200km Oct 6, 2023
a68e799
Fix NanoSSOC class name
200km Oct 6, 2023
cc3e57e
Fix NanoSSOC variable name
200km Oct 6, 2023
7d15160
Fi nano ssoc file name
200km Oct 6, 2023
35aac9d
Fix MTQseiren class name
200km Oct 6, 2023
ba40150
Fix MTQseiren variables
200km Oct 6, 2023
e3d6b0d
Fix small
200km Oct 6, 2023
e6ce687
Fix MPU MAG class name
200km Oct 6, 2023
0e46cf1
Fix MPU MAG variables name
200km Oct 6, 2023
c562291
Fix MPU MAG file name
200km Oct 6, 2023
4188854
Fix MPU GYRO class name
200km Oct 6, 2023
1196bf8
Fix variables name
200km Oct 6, 2023
09f57c8
Fix variables name
200km Oct 6, 2023
0b65659
Fix mpu9250 gyro file name
200km Oct 6, 2023
946d3e0
Fix .h to .hpp
200km Oct 6, 2023
5fa61a5
Fix AOBC class name
200km Oct 6, 2023
b8ddd67
Fix ini file name
200km Oct 6, 2023
c5e1095
Fix ini file name
200km Oct 6, 2023
604e14f
Fix format
200km Oct 6, 2023
926a4cb
Fix small
200km Oct 6, 2023
fccb6a0
CI test
200km Oct 6, 2023
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
22 changes: 11 additions & 11 deletions data/initialize_files/satellite.ini
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ scenario_file_path = ../../data/initialize_files/scenario/scenario.ini

[COMPONENTS_FILE]
// AOCS
gyro_h_file = ../../data/initialize_files/components/stim210.ini
fine_gyro_sensor_file = ../../data/initialize_files/components/stim210.ini
gyro_l_file = ../../data/initialize_files/components/mpu9250.ini
magsensor_h_aobc_file = ../../data/initialize_files/components/rm3100_aobc.ini
magsensor_h_ext_file = ../../data/initialize_files/components/rm3100_external.ini
magsensor_l_file = ../../data/initialize_files/components/mpu9250.ini
ss_file = ../../data/initialize_files/components/nanossoc_d60.ini
stt_file = ../../data/initialize_files/components/sagitta.ini
gnssr_file = ../../data/initialize_files/components/oem7600.ini
rw_file = ../../data/initialize_files/components/rw0003.ini
mtq_file = ../../data/initialize_files/components/mtq_seiren.ini
fine_magnetometer_file = ../../data/initialize_files/components/rm3100_aobc.ini
external_fine_magnetometer_file = ../../data/initialize_files/components/rm3100_external.ini
coarse_magnetometer_file = ../../data/initialize_files/components/mpu9250.ini
sun_sensor_file = ../../data/initialize_files/components/nanossoc_d60.ini
star_sensor_file = ../../data/initialize_files/components/sagitta.ini
gnss_receiver_file = ../../data/initialize_files/components/oem7600.ini
reaction_wheel_file = ../../data/initialize_files/components/rw0003.ini
magnetorquer_file = ../../data/initialize_files/components/mtq_seiren.ini
thruster_file = ../../data/initialize_files/components/thruster.ini
// Electric Power System
power_controller_file = ../../data/initialize_files/components/power_controller.ini
Expand All @@ -132,8 +132,8 @@ stim210_hils_port_id = 4
stim210_baud_rate = 460800

//I2C
mpu9250_gyro_hils_port_id = 11
mpu9250_mag_hils_port_id = 12
mpu9250_gyro_sensor_hils_port_id = 11
mpu9250_magnetometer_hils_port_id = 12
rm3100_aobc_hils_port_id = 6
rm3100_ext_hils_port_id = 5
nanoSSOC_d60_idx_0_hils_port_id = 7
Expand Down
14 changes: 8 additions & 6 deletions src/component/aocs/aobc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@

#include <library/utilities/macros.hpp>

#include "../../simulation/spacecraft/aocs_module_components.h"
#include "../../simulation/spacecraft/aocs_module_components.hpp"

AOBC::AOBC(ClockGenerator *clock_gen, AocsModuleComponents *components) : Component(100, clock_gen), components_(components) { Initialize(); }
Aobc::Aobc(ClockGenerator *clock_generator, AocsModuleComponents *components) : Component(100, clock_generator), components_(components) {
Initialize();
}

AOBC::~AOBC() { delete components_; }
Aobc::~Aobc() { delete components_; }

void AOBC::Initialize() {}
void Aobc::Initialize() {}

void AOBC::MainRoutine(int count) {
UNUSED(count);
void Aobc::MainRoutine(const int time_count) {
UNUSED(time_count);
// Currently, this class is not used.
}
16 changes: 8 additions & 8 deletions src/component/aocs/aobc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
class AocsModuleComponents;

/**
* @class AOBC
* @class Aobc
* @brief Class to emulate AOBC
*/
class AOBC : public Component {
class Aobc : public Component {
public:
/**
* @fn AOBC
* @fn Aobc
* @brief Constructor
* @param [in] clock_gen: Clock generator
* @param [in] clock_generator: Clock generator
* @param [in] components: Components connected to the AOBC
*/
AOBC(ClockGenerator *clock_gen, AocsModuleComponents *components);
Aobc(ClockGenerator *clock_generator, AocsModuleComponents *components);
/**
* @fn ~AOBC
* @fn ~Aobc
* @brief Destructor
*/
~AOBC();
~Aobc();

/**
* @fn Initialize
Expand All @@ -43,7 +43,7 @@ class AOBC : public Component {
* @fn MainRoutine
* @brief Main routine for sensor observation
*/
void MainRoutine(int count);
void MainRoutine(const int time_count);
};

#endif // S2E_AOBC_COMPONENT_AOCS_AOBC_HPP_
20 changes: 10 additions & 10 deletions src/component/aocs/cube_wheel.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#include "cube_wheel.h"

CubeWheel::CubeWheel(RWModel rw_model, const int port_id, const unsigned char i2c_addr, OBC* obc)
: RWModel(rw_model), ObcI2cCommunicationBase(port_id, i2c_addr, obc) {
port_id_ = i2c_addr - 0x67; // port_idは1固定のため。
CubeWheel::CubeWheel(RWModel rw_model, const int port_id, const unsigned char i2c_address, OBC* obc)
: RWModel(rw_model), ObcI2cCommunicationBase(port_id, i2c_address, obc) {
port_id_ = i2c_address - 0x67; // port_idは1固定のため。

unsigned char data[] = {0x08};

if (i2c_addr == 0x68) {
if (i2c_address == 0x68) {
WriteRegister(0x80, data, 1);
data[0] = 0xd0;
WriteRegister(0x83, data, 1);
} else if (i2c_addr == 0x69) {
} else if (i2c_address == 0x69) {
WriteRegister(0x80, data, 1);
data[0] = 0xd2;
WriteRegister(0x83, data, 1);
} else if (i2c_addr == 0x6A) {
} else if (i2c_address == 0x6A) {
WriteRegister(0x80, data, 1);
data[0] = 0xd4;
WriteRegister(0x83, data, 1);
}
}

void CubeWheel::MainRoutine(int count) {
void CubeWheel::MainRoutine(const int time_count) {
// Control Modeの取得と処理
ReadRegister(kWriteCmdControlMode_, &control_mode_, 1);

Expand Down Expand Up @@ -58,11 +58,11 @@ void CubeWheel::MainRoutine(int count) {
if (commanded_speed_rpm < current_speed_rpm) {
sign = -1;
}
double speed_cmd_cycle_in_sec = 0.5;
double target_omega_dash = to_add_rad_s / speed_cmd_cycle_in_sec * sign;
double speed_command_cycle_in_sec = 0.5;
double target_angular_velocity_dash = to_add_rad_s / speed_command_cycle_in_sec * sign;

// 指令トルクをセット。
double torque_Nm = target_omega_dash * 0.00000211;
double torque_Nm = target_angular_velocity_dash * 0.00000211;
SetTargetTorqueRw(torque_Nm);

// dummy値を書き込む。次にspeed cmdを受信するまで処理をしないため。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

class CubeWheel : public RWModel, public ObcI2cCommunicationBase {
public:
CubeWheel(RWModel rw_model, const int port_id, const unsigned char i2c_addr, OBC* obc);
CubeWheel(RWModel rw_model, const int port_id, const unsigned char i2c_address, OBC* obc);

// Override: RWModel functions
void MainRoutine(int count) override;
void MainRoutine(const int time_count) override;
std::string GetLogHeader() const override;

private:
Expand All @@ -21,7 +21,7 @@ class CubeWheel : public RWModel, public ObcI2cCommunicationBase {
unsigned char encoder_state_ = 0;
unsigned char error_flag_ = 0;

double lsb2nT_ = 13.0;
double kLsb2nT_ = 13.0;
int port_id_ = 0;

// Write Command
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/**
* @file mpu9250_gyro.cpp
* @file mpu9250_gyro_sensor.cpp
* @brief Class to emulate gyro sensor in MPU9250 9 axis sensor
*/

#include "mpu9250_gyro.hpp"
#include "mpu9250_gyro_sensor.hpp"

#include <library/math/constants.hpp>
#include <library/utilities/macros.hpp>

MPU9250_GYRO::MPU9250_GYRO(GyroSensor gyro, const int sils_port_id, const unsigned int hils_port_id, const unsigned char i2c_addr,
OnBoardComputer *obc, HilsPortManager *hils_port_manager)
: GyroSensor(gyro), I2cTargetCommunicationWithObc(sils_port_id, hils_port_id, i2c_addr, obc, hils_port_manager) {
Mpu9250GyroSensor::Mpu9250GyroSensor(GyroSensor gyro, const int sils_port_id, const unsigned int hils_port_id, const unsigned char i2c_address,
OnBoardComputer *obc, HilsPortManager *hils_port_manager)
: GyroSensor(gyro), I2cTargetCommunicationWithObc(sils_port_id, hils_port_id, i2c_address, obc, hils_port_manager) {
unsigned char tmp = 0xff;
WriteRegister(kCmdGyroEnable_, &tmp, 1); // 初期値としてはGyro OFF

SetConvertCoefficients();
}

void MPU9250_GYRO::MainRoutine(int count) {
UNUSED(count);
void Mpu9250GyroSensor::MainRoutine(const int time_count) {
UNUSED(time_count);
// Read Registers
ReadCmdGyroEnable();
ReadCmdMagEnable();
Expand All @@ -31,78 +31,78 @@ void MPU9250_GYRO::MainRoutine(int count) {
WriteGyroTlm();
}

int cmd_size = ReceiveCommand();
if (cmd_size != 1) return; // length == 1 means setting of read register address
int command_size = ReceiveCommand();
if (command_size != 1) return; // length == 1 means setting of read register address
// これ以降はHILS用に事前にテレメトリを溜めておく
const int kTlmSize = 14;
StoreTelemetry(kStoredFrameSize, kTlmSize);
return;
}

void MPU9250_GYRO::ReadCmdGyroEnable() {
void Mpu9250GyroSensor::ReadCmdGyroEnable() {
unsigned char tmp = 0xff;
ReadRegister(kCmdGyroEnable_, &tmp, 1);
if (tmp == 0x00) is_gyro_on_ = true;

return;
}

void MPU9250_GYRO::ReadCmdMagEnable() {
void Mpu9250GyroSensor::ReadCmdMagEnable() {
unsigned char tmp[2] = {0xff, 0xff};
ReadCommand(tmp, 2);
if (tmp[0] != kCmdMagEnable_) return;

if (tmp[1] == 0x02) is_mag_on_ = true; // 0x02 means turn on mag
if (tmp[1] == 0x02) is_magnetometer_on_ = true; // 0x02 means turn on mag

return;
}

void MPU9250_GYRO::ReadCmdGyroLpf() {
void Mpu9250GyroSensor::ReadCmdGyroLpf() {
// TODO 6Uでの利用では固定値なので、中身の実装は優先度低
return;
}

void MPU9250_GYRO::ReadCmdGyroRange() {
void Mpu9250GyroSensor::ReadCmdGyroRange() {
// TODO 6Uでの利用では固定値なので、中身の実装は優先度低
return;
}

void MPU9250_GYRO::ReadCmdAccLpf() {
void Mpu9250GyroSensor::ReadCmdAccelerometerLpf() {
// TODO 6Uでの利用では固定値なので、中身の実装は優先度低
return;
}

void MPU9250_GYRO::ReadCmdAccRange() {
void Mpu9250GyroSensor::ReadCmdAccelerometerRange() {
// TODO 6Uでの利用では固定値なので、中身の実装は優先度低
return;
}

void MPU9250_GYRO::WriteGyroTlm() {
void Mpu9250GyroSensor::WriteGyroTlm() {
unsigned char tlm[kMpuTlmSize_] = {0, 0};
unsigned char reg_id = kRegObsGyro_;

// Acc
// Accelerometer
for (size_t i = 0; i < kGyroDimension; i++) {
Convert2Tlm(tlm, acc_c_G_[i] * acc_convert_G_to_raw_);
Convert2Tlm(tlm, accelerometer_c_G_[i] * accelerometer_convert_G_to_raw_);
WriteRegister(reg_id, tlm, kMpuTlmSize_);
reg_id += kMpuTlmSize_;
}
// Temperature
Convert2Tlm(tlm, (temperature_degC_ - temp_offset_degC_) * temp_convert_degC_to_raw_);
Convert2Tlm(tlm, (temperature_degC_ - temperature_offset_degC_) * temperature_convert_degC_to_raw_);
WriteRegister(reg_id, tlm, kMpuTlmSize_);
reg_id += kMpuTlmSize_;
// Gyro
for (size_t i = 0; i < kGyroDimension; i++) {
double omega_c_deg_s = angular_velocity_c_rad_s_[i] * libra::rad_to_deg;
Convert2Tlm(tlm, omega_c_deg_s * omega_convert_deg_s_to_raw_);
double angular_velocity_c_deg_s = angular_velocity_c_rad_s_[i] * libra::rad_to_deg;
Convert2Tlm(tlm, angular_velocity_c_deg_s * angular_velocity_convert_deg_s_to_raw_);
WriteRegister(reg_id, tlm, kMpuTlmSize_);
reg_id += kMpuTlmSize_;
}

return;
}

void MPU9250_GYRO::Convert2Tlm(unsigned char tlm[kMpuTlmSize_], const double value) {
void Mpu9250GyroSensor::Convert2Tlm(unsigned char tlm[kMpuTlmSize_], const double value) {
signed short tlm_s = (signed short)(value);

for (int i = 0; i < kMpuTlmSize_; i++) {
Expand All @@ -112,8 +112,8 @@ void MPU9250_GYRO::Convert2Tlm(unsigned char tlm[kMpuTlmSize_], const double val
return;
}

void MPU9250_GYRO::SetConvertCoefficients() {
omega_convert_deg_s_to_raw_ = raw_max_ / omega_max_deg_s_;
acc_convert_G_to_raw_ = raw_max_ / acc_max_G_;
void Mpu9250GyroSensor::SetConvertCoefficients() {
angular_velocity_convert_deg_s_to_raw_ = raw_max_ / angular_velocity_max_deg_s_;
accelerometer_convert_G_to_raw_ = raw_max_ / accelerometer_max_G_;
return;
}
Loading