Skip to content

Commit

Permalink
Merge pull request #77 from ut-issl/feature/modify-coding-rule
Browse files Browse the repository at this point in the history
Modify to suit with S2E-CORE Coding rule
  • Loading branch information
200km authored Oct 11, 2023
2 parents 253b5b9 + fccb6a0 commit 429942b
Show file tree
Hide file tree
Showing 40 changed files with 767 additions and 768 deletions.
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

0 comments on commit 429942b

Please sign in to comment.