2024-09-10 22:30:30 +08:00
|
|
|
//
|
|
|
|
// Created by biao on 24-9-10.
|
|
|
|
//
|
|
|
|
|
2024-09-11 20:41:12 +08:00
|
|
|
#include <cmath>
|
|
|
|
#include <iostream>
|
2024-09-10 22:30:30 +08:00
|
|
|
#include <unitree_guide_controller/FSM/StateFixedStand.h>
|
|
|
|
|
|
|
|
StateFixedStand::StateFixedStand(CtrlComponent ctrlComp): FSMState(
|
|
|
|
FSMStateName::FIXEDSTAND, "fixed stand", std::move(ctrlComp)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void StateFixedStand::enter() {
|
2024-09-11 14:01:07 +08:00
|
|
|
for (int i = 0; i < 12; i++) {
|
2024-09-11 20:41:12 +08:00
|
|
|
start_pos_[i] = ctrlComp_.joint_position_state_interface_[i].get().get_value();
|
2024-09-11 14:01:07 +08:00
|
|
|
}
|
2024-09-10 22:30:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StateFixedStand::run() {
|
2024-09-11 20:41:12 +08:00
|
|
|
percent_ += 1 / duration_;
|
|
|
|
phase = std::tanh(percent_);
|
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
ctrlComp_.joint_position_command_interface_[i].get().set_value(
|
|
|
|
phase * target_pos_[i] + (1 - phase) * start_pos_[i]);
|
|
|
|
ctrlComp_.joint_velocity_command_interface_[i].get().set_value(0);
|
|
|
|
ctrlComp_.joint_effort_command_interface_[i].get().set_value(0);
|
|
|
|
ctrlComp_.joint_kp_command_interface_[i].get().set_value(
|
2024-09-12 20:04:20 +08:00
|
|
|
phase * 60.0 + (1 - phase) * 20.0);
|
|
|
|
ctrlComp_.joint_kd_command_interface_[i].get().set_value(3.5);
|
2024-09-11 20:41:12 +08:00
|
|
|
}
|
2024-09-10 22:30:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StateFixedStand::exit() {
|
2024-09-11 20:41:12 +08:00
|
|
|
percent_ = 0;
|
2024-09-10 22:30:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
FSMStateName StateFixedStand::checkChange() {
|
2024-09-12 20:04:20 +08:00
|
|
|
if (percent_ < 2) {
|
2024-09-11 20:41:12 +08:00
|
|
|
return FSMStateName::FIXEDSTAND;
|
|
|
|
}
|
2024-09-12 13:56:51 +08:00
|
|
|
switch (ctrlComp_.control_inputs_.get().command) {
|
|
|
|
case 1:
|
|
|
|
return FSMStateName::FIXEDDOWN;
|
|
|
|
case 8:
|
|
|
|
return FSMStateName::SWINGTEST;
|
|
|
|
default:
|
|
|
|
return FSMStateName::FIXEDSTAND;
|
2024-09-11 14:01:07 +08:00
|
|
|
}
|
2024-09-10 22:30:30 +08:00
|
|
|
}
|