Tetrapod Project
robot_controller.h
Go to the documentation of this file.
1 #ifndef robot_controller_h
2 #define robot_controller_h
3 
6 
7 class RobotController : public Controller
8 {
9  public: enum SuperState {kIdle, kMoving};
10 
12 
13  public: enum SwingState {kStart, kRise, kHigh, kFall, kEnd};
14 
15  public: RobotController(int controller_freq, double gait_period);
16 
17  public: void UpdateGuidanceCommands();
18 
19  public: void UpdateNonGuidanceCommands();
20 
21  public: void UpdateStepDistances();
22 
23  public: bool UpdateGaitState();
24 
26  public: void UpdateFeetReferences();
27 
28  public: void UpdateFeetTrajectories();
29 
32 
35 
37  public: void SetFeetPositionsGoalPose();
38 
39  public: Eigen::Matrix<double, 3, 1> UpdateStanceFootPosition(Kinematics::LegType _leg_type, double _progress);
40 
41  public: Eigen::Matrix<double, 3, 1> UpdateSwingFootPosition(Kinematics::LegType _leg_type, double _progress);
42 
43  public: void UpdateSwingFootTrajectory(Kinematics::LegType _leg_type, double progress);
44 
46  private: SuperState super_state = SuperState::kIdle;
47 
49  private: MotionState motion_state = MotionState::kStancePreSwingFlRr;
50 
52  private: Eigen::Matrix<double, 3, 1> fl_goal_position;
53 
55  private: Eigen::Matrix<double, 3, 1> fr_goal_position;
56 
58  private: Eigen::Matrix<double, 3, 1> rl_goal_position;
59 
61  private: Eigen::Matrix<double, 3, 1> rr_goal_position;
62 
63  private: Eigen::Matrix<double, 12, 1> initial_feet_positions_pose_control;
64 
65  private: double hip_height = 0.35;
66 
67  private: double step_distance_x_linear = 0.0;
68 
69  private: double step_distance_y_linear = 0.0;
70 
71  private: double step_distance_x_rotational = 0.0;
72 
73  private: double step_distance_y_rotational = 0.0;
74 
75  private: double gait_duration = 0.0;
76 
77  private: double vel_x = 0.0;
78 
79  private: double vel_y = 0.0;
80 
81  private: double yaw_rate = 0.0;
82 
83  private: int iteration = 0;
84 
85  private: double max_step_height = 0.1;
86 
87  private: double stance_phase_duration_percentage = 0.1;
88 
89  private: double swing_rise_percentage = 0.3;
90 
91  private: double swing_period;
92 
93  private: double stance_period;
94 
95  private: int swing_iterations;
96 
97  private: int stance_iterations;
98 
99  private: int final_iteration;
100 
101  private: double fl_step_distance_x;
102 
103  private: double fl_step_distance_y;
104 
105  private: double fr_step_distance_x;
106 
107  private: double fr_step_distance_y;
108 
109  private: double rl_step_distance_x;
110 
111  private: double rl_step_distance_y;
112 
113  private: double rr_step_distance_x;
114 
115  private: double rr_step_distance_y;
116 
117  private: double _lin_vel_x_command;
118 
119  private: double _lin_vel_y_command;
120 
121  private: double _ang_vel_z_command;
122 
123  private: double _guidance_lin_vel_gain = 1.0;
124 
125  private: double _guidance_ang_vel_gain = 1.0;
126 
127  //private: std::vector<double> _lin_body_vel_x_history;
128 
129  //private: std::vector<double> _lin_body_vel_y_history;
130 
131  //private: std::vector<double> _ang_body_vel_z_history;
132 
133  //private: double _avg_lin_gait_vel_x;
134 
135  //private: double _avg_lin_gait_vel_y;
136 
137  //private: double _avg_ang_gait_vel_z;
138 
139  /*
140  Eigen::Matrix<double, 3, 1> fl_trajectory_x;
141 
142  Eigen::Matrix<double, 3, 1> fl_trajectory_y;
143 
144  Eigen::Matrix<double, 3, 1> fl_trajectory_z;
145 
146  Eigen::Matrix<double, 3, 1> fr_trajectory_x;
147 
148  Eigen::Matrix<double, 3, 1> fr_trajectory_y;
149 
150  Eigen::Matrix<double, 3, 1> fr_trajectory_z;
151 
152  Eigen::Matrix<double, 3, 1> rl_trajectory_x;
153 
154  Eigen::Matrix<double, 3, 1> rl_trajectory_y;
155 
156  Eigen::Matrix<double, 3, 1> rl_trajectory_z;
157 
158  Eigen::Matrix<double, 3, 1> rr_trajectory_x;
159 
160  Eigen::Matrix<double, 3, 1> rr_trajectory_y;
161 
162  Eigen::Matrix<double, 3, 1> rr_trajectory_z;
163  */
164 
165  public: void PrintParameters();
166 
167  public: void PrintFootPositions();
168 
169  public: void PrintVelCommands();
170 
171 };
172 
173 #endif
int controller_freq
Definition: controller.h:110
LegType
Leg type enumerator.
Definition: kinematics.h:56
double step_distance_x_linear
void SetFeetPositionsGoalPose()
A function that sets the goal positions as the targets to reach eventually.
double step_distance_y_linear
double swing_rise_percentage
void UpdateFeetReferences()
A function updating the foot positions of the robot in the hip frames.
double _guidance_lin_vel_gain
MotionState motion_state
A variable deciding which of the four motion states we are currently in.
Eigen::Matrix< double, 3, 1 > rl_goal_position
The rear left foot target position in the hip frame when using pose control.
void UpdateNonGuidanceCommands()
double stance_phase_duration_percentage
Eigen::Matrix< double, 3, 1 > UpdateSwingFootPosition(Kinematics::LegType _leg_type, double _progress)
Eigen::Matrix< double, 3, 1 > fr_goal_position
The front right foot target position in the hip frame when using pose control.
Eigen::Matrix< double, 3, 1 > UpdateStanceFootPosition(Kinematics::LegType _leg_type, double _progress)
Eigen::Matrix< double, 12, 1 > initial_feet_positions_pose_control
double _guidance_ang_vel_gain
void UpdateFeetReferencesGaitControl()
A gait controller updating the robot's foot positions to walk.
double step_distance_x_rotational
void UpdateFeetReferencesPoseControl()
A pose controller updating robot's foot positions to control its pose.
double step_distance_y_rotational
SuperState super_state
The main state of the robot deciding whether the robot is walking or not.
RobotController(int controller_freq, double gait_period)
void UpdateSwingFootTrajectory(Kinematics::LegType _leg_type, double progress)
Eigen::Matrix< double, 3, 1 > rr_goal_position
The rear right foot target position in the hip frame when using pose control.
Eigen::Matrix< double, 3, 1 > fl_goal_position
The front left foot target position in the hip frame when using pose control.