refact with reference

This commit is contained in:
Huang Zhenbiao 2024-09-18 13:18:02 +08:00
parent 85be4715ab
commit e390835458
13 changed files with 23 additions and 23 deletions

View File

@ -15,10 +15,10 @@ class FSMState {
public: public:
virtual ~FSMState() = default; virtual ~FSMState() = default;
FSMState(const FSMStateName &stateName, std::string stateNameString, CtrlComponent ctrlComp) FSMState(const FSMStateName &state_name, std::string state_name_string, CtrlComponent &ctrl_comp)
: state_name(stateName), : state_name(state_name),
state_name_string(std::move(stateNameString)), state_name_string(std::move(state_name_string)),
ctrl_comp_(std::move(ctrlComp)) { ctrl_comp_(ctrl_comp) {
} }
virtual void enter() = 0; virtual void enter() = 0;
@ -33,7 +33,7 @@ public:
std::string state_name_string; std::string state_name_string;
protected: protected:
CtrlComponent ctrl_comp_; CtrlComponent &ctrl_comp_;
}; };
#endif //FSMSTATE_H #endif //FSMSTATE_H

View File

@ -9,7 +9,7 @@
class StateBalanceTest final : public FSMState { class StateBalanceTest final : public FSMState {
public: public:
explicit StateBalanceTest(CtrlComponent ctrlComp); explicit StateBalanceTest(CtrlComponent &ctrlComp);
void enter() override; void enter() override;

View File

@ -9,7 +9,7 @@
class StateFixedDown final : public FSMState { class StateFixedDown final : public FSMState {
public: public:
explicit StateFixedDown(CtrlComponent ctrlComp); explicit StateFixedDown(CtrlComponent &ctrlComp);
void enter() override; void enter() override;

View File

@ -9,7 +9,7 @@
class StateFixedStand final : public FSMState { class StateFixedStand final : public FSMState {
public: public:
explicit StateFixedStand(CtrlComponent ctrlComp); explicit StateFixedStand(CtrlComponent &ctrlComp);
void enter() override; void enter() override;

View File

@ -9,7 +9,7 @@
class StateFreeStand final : public FSMState { class StateFreeStand final : public FSMState {
public: public:
explicit StateFreeStand(CtrlComponent ctrl_component); explicit StateFreeStand(CtrlComponent &ctrl_component);
void enter() override; void enter() override;

View File

@ -9,7 +9,7 @@
class StatePassive final : public FSMState { class StatePassive final : public FSMState {
public: public:
explicit StatePassive(CtrlComponent ctrlComp); explicit StatePassive(CtrlComponent &ctrlComp);
void enter() override; void enter() override;

View File

@ -10,7 +10,7 @@
class StateSwingTest final : public FSMState { class StateSwingTest final : public FSMState {
public: public:
explicit StateSwingTest(CtrlComponent ctrlComp); explicit StateSwingTest(CtrlComponent &ctrlComp);
void enter() override; void enter() override;

View File

@ -6,8 +6,8 @@
#include <unitree_guide_controller/common/mathTools.h> #include <unitree_guide_controller/common/mathTools.h>
StateBalanceTest::StateBalanceTest(CtrlComponent ctrlComp) : FSMState(FSMStateName::BALANCETEST, "balance test", StateBalanceTest::StateBalanceTest(CtrlComponent &ctrlComp) : FSMState(FSMStateName::BALANCETEST, "balance test",
std::move(ctrlComp)), ctrlComp),
estimator_(ctrlComp.estimator_.get()), estimator_(ctrlComp.estimator_.get()),
robot_model_(ctrlComp.robot_model_.get()), robot_model_(ctrlComp.robot_model_.get()),
balance_ctrl_(ctrlComp.balance_ctrl_.get()) { balance_ctrl_(ctrlComp.balance_ctrl_.get()) {

View File

@ -6,8 +6,8 @@
#include <cmath> #include <cmath>
StateFixedDown::StateFixedDown(CtrlComponent ctrlComp): FSMState( StateFixedDown::StateFixedDown(CtrlComponent &ctrlComp): FSMState(
FSMStateName::FIXEDDOWN, "fixed down", std::move(ctrlComp)) { FSMStateName::FIXEDDOWN, "fixed down", ctrlComp) {
duration_ = ctrl_comp_.frequency_ * 1.2; duration_ = ctrl_comp_.frequency_ * 1.2;
} }

View File

@ -6,8 +6,8 @@
#include <cmath> #include <cmath>
StateFixedStand::StateFixedStand(CtrlComponent ctrlComp): FSMState( StateFixedStand::StateFixedStand(CtrlComponent &ctrlComp): FSMState(
FSMStateName::FIXEDSTAND, "fixed stand", std::move(ctrlComp)) { FSMStateName::FIXEDSTAND, "fixed stand", ctrlComp) {
duration_ = ctrl_comp_.frequency_ * 1.2; duration_ = ctrl_comp_.frequency_ * 1.2;
} }

View File

@ -5,8 +5,8 @@
#include "unitree_guide_controller/FSM/StateFreeStand.h" #include "unitree_guide_controller/FSM/StateFreeStand.h"
#include "unitree_guide_controller/common/mathTools.h" #include "unitree_guide_controller/common/mathTools.h"
StateFreeStand::StateFreeStand(CtrlComponent ctrl_component) : FSMState(FSMStateName::FREESTAND, "free stand", StateFreeStand::StateFreeStand(CtrlComponent &ctrl_component) : FSMState(FSMStateName::FREESTAND, "free stand",
std::move(ctrl_component)) { ctrl_component) {
row_max_ = 20 * M_PI / 180; row_max_ = 20 * M_PI / 180;
row_min_ = -row_max_; row_min_ = -row_max_;
pitch_max_ = 15 * M_PI / 180; pitch_max_ = 15 * M_PI / 180;

View File

@ -7,8 +7,8 @@
#include <iostream> #include <iostream>
#include <utility> #include <utility>
StatePassive::StatePassive(CtrlComponent ctrlComp) : FSMState( StatePassive::StatePassive(CtrlComponent &ctrlComp) : FSMState(
FSMStateName::PASSIVE, "passive", std::move(ctrlComp)) { FSMStateName::PASSIVE, "passive", ctrlComp) {
} }
void StatePassive::enter() { void StatePassive::enter() {

View File

@ -6,8 +6,8 @@
#include "unitree_guide_controller/FSM/StateSwingTest.h" #include "unitree_guide_controller/FSM/StateSwingTest.h"
#include "unitree_guide_controller/common/mathTools.h" #include "unitree_guide_controller/common/mathTools.h"
StateSwingTest::StateSwingTest(CtrlComponent ctrlComp): FSMState( StateSwingTest::StateSwingTest(CtrlComponent &ctrlComp): FSMState(
FSMStateName::SWINGTEST, "swing test", std::move(ctrlComp)) { FSMStateName::SWINGTEST, "swing test", ctrlComp) {
_xMin = -0.15; _xMin = -0.15;
_xMax = 0.10; _xMax = 0.10;
_yMin = -0.15; _yMin = -0.15;