Go2Py_SIM/locomotion/custom/include/Planner/Planner.hpp

128 lines
3.1 KiB
C++
Raw Normal View History

2024-02-16 07:43:43 +08:00
#pragma once
#include "kinodynamics.hpp"
#include <string>
#include "Planner/Gait.hpp"
#include "Planner/FootSwingTrajectory.h"
#include "utils.hpp"
#include "memory_types.hpp"
class Planner {
public:
Planner();
Planner(std::string name);
~Planner();
2024-03-12 08:55:41 +08:00
vec3 getRaibertHeuristic(const uint8_t& leg_id, const float& t_stance);
virtual Eigen::Vector3d getDesiredFootPosition(const uint8_t&, const float&);
virtual void setFeetTarget();
virtual void setBaseTarget();
virtual void setTarget();
2024-02-16 07:43:43 +08:00
2024-03-12 08:55:41 +08:00
void setRobot(Quadruped& robot) {
2024-02-16 07:43:43 +08:00
m_robot = robot;
2024-03-12 08:55:41 +08:00
initClass();
2024-02-16 07:43:43 +08:00
}
2024-03-12 08:55:41 +08:00
void setGait(Gait& gait) {
2024-02-16 07:43:43 +08:00
m_gait = gait;
}
void setPlannerDataPtr(QuadrupedPlannerData* pd) {
m_planner_data_ptr = pd;
}
void setEstimationDataPtr(QuadrupedEstimationData* est_ptr) {
m_estimation_data_ptr = est_ptr;
}
2024-03-12 08:55:41 +08:00
void setDesiredVelocity(const float& vx, const float& vy, const float& vyaw);
bool setTargetBasePosition(const vec3& target_pos, const float& target_yaw);
bool sleepToStance();
bool stanceToSleep();
void setStance();
2024-02-16 07:43:43 +08:00
2024-03-12 08:55:41 +08:00
virtual void step(const float& dt, const float& t_curr);
2024-02-16 07:43:43 +08:00
float m_t_curr = 0;
Gait m_gait;
bool m_check_safe_orientation = true;
bool m_check_desired_footholds = true;
2024-03-12 08:55:41 +08:00
void initClass();
2024-02-16 07:43:43 +08:00
void reset();
2024-03-12 08:55:41 +08:00
void startFromSleep(const bool& sleep_start);
2024-02-16 07:43:43 +08:00
protected:
Quadruped m_robot;
Eigen::Vector4d getScheduledContactProbability(const float &t, Gait &gait);
Eigen::Array4i m_cs_ref;
int4 m_cs_act;
Eigen::Vector4d p_cs_phi;
2024-03-12 08:55:41 +08:00
double m_v_cmd_x = 0.0;
double m_v_cmd_y = 0.0;
double m_v_cmd_z = 0.0;
double m_v_cmd_yaw = 0.0;
double m_a_max_x = 0.2;
double m_a_max_y = 0.2;
double m_a_max_z = 0.2;
double m_a_max_yaw = 1.0;
double max_vel_x = 1.0;
double max_vel_y = 1.0;
double max_vel_z = 1.0;
double max_vel_yaw = 3.0;
double m_loop_rate = 1000;
double m_dt = 0.001;
double m_yaw = 0;
// vec12 p_step_;
vec3 m_target_base_position;
double m_target_yaw;
2024-02-16 07:43:43 +08:00
vec4 m_Pc_act;
vec12 m_theta;
vec19 m_joint_state_act;
vec18 m_joint_vel_act;
vec19 m_ee_state_ref;
vec18 m_ee_vel_ref, m_ee_acc_ref;
2024-03-12 08:55:41 +08:00
vec12 m_p_takeoff_full;
2024-02-16 07:43:43 +08:00
private:
2024-03-12 08:55:41 +08:00
Eigen::VectorXd getHipPosition(const Eigen::VectorXd&);
2024-02-16 07:43:43 +08:00
void updateExpectedStanceFlag();
2024-03-12 08:55:41 +08:00
void updateTakeoffData();
2024-02-16 07:43:43 +08:00
void adjustStanceLegs();
double getTimeSinceStart();
QuadrupedPlannerData* m_planner_data_ptr;
QuadrupedEstimationData* m_estimation_data_ptr;
void updatePlannerData();
void updateEstimationData();
// bool CheckSafeOrientation();
// void CheckDesiredFootholds(Eigen::Vector3d&);
2024-03-12 08:55:41 +08:00
bool m_sleep_start = false;
2024-02-16 07:43:43 +08:00
std::string m_name;
std::chrono::time_point<std::chrono::high_resolution_clock> m_startTimePoint;
std::chrono::time_point<std::chrono::high_resolution_clock> m_currentTimePoint;
vec4 m_t_takeoff;
vec19 m_ee_state_init;
int4 m_expected_stance;
// reference foot trajectories
FootSwingTrajectory<float> ref_foot_traj[4];
};