feat: add CSV_LOGGER && format

This commit is contained in:
fan-ziqi 2024-04-15 13:11:33 +08:00
parent e79596c1f1
commit 956072401f
1 changed files with 21 additions and 10 deletions

View File

@ -3,6 +3,7 @@
#define ROBOT_NAME "a1" #define ROBOT_NAME "a1"
// #define PLOT // #define PLOT
#define CSV_LOGGER
RL_Real rl_sar; RL_Real rl_sar;
@ -42,6 +43,10 @@ RL_Real::RL_Real() : safe(LeggedType::A1), udp(LOWLEVEL)
loop_plot = std::make_shared<LoopFunc>("loop_plot" , 0.002, boost::bind(&RL_Real::Plot, this)); loop_plot = std::make_shared<LoopFunc>("loop_plot" , 0.002, boost::bind(&RL_Real::Plot, this));
loop_plot->start(); loop_plot->start();
#endif #endif
#ifdef CSV_LOGGER
CSVInit(ROBOT_NAME);
#endif
} }
RL_Real::~RL_Real() RL_Real::~RL_Real()
@ -227,8 +232,14 @@ void RL_Real::RunModel()
output_torques = this->ComputeTorques(actions); output_torques = this->ComputeTorques(actions);
output_dof_pos = this->ComputePosition(actions); output_dof_pos = this->ComputePosition(actions);
#ifdef CSV_LOGGER
torch::Tensor tau_est = torch::tensor({{state.motorState[FL_0].tauEst, state.motorState[FL_1].tauEst, state.motorState[FL_2].tauEst,
state.motorState[FR_0].tauEst, state.motorState[FR_1].tauEst, state.motorState[FR_2].tauEst,
state.motorState[RL_0].tauEst, state.motorState[RL_1].tauEst, state.motorState[RL_2].tauEst,
state.motorState[RR_0].tauEst, state.motorState[RR_1].tauEst, state.motorState[RR_2].tauEst}});
CSVLogger(output_torques, tau_est, this->obs.dof_pos, output_dof_pos, this->obs.dof_vel);
#endif
} }
} }
torch::Tensor RL_Real::ComputeObservation() torch::Tensor RL_Real::ComputeObservation()