Quad-SDK
Loading...
Searching...
No Matches
local_planner.h
1#ifndef LOCAL_PLANNER_H
2#define LOCAL_PLANNER_H
3
4#include <gtest/gtest_prod.h>
5#include <local_planner/local_footstep_planner.h>
6#include <local_planner/local_planner_modes.h>
7#include <math.h>
8#include <nmpc_controller/nmpc_controller.h>
9#include <quad_msgs/GRFArray.h>
10#include <quad_msgs/MultiFootPlanDiscrete.h>
11#include <quad_msgs/RobotPlan.h>
12#include <quad_msgs/RobotState.h>
13#include <quad_utils/quad_kd.h>
14#include <quad_utils/ros_utils.h>
15#include <ros/ros.h>
16#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
17
19
23 public:
29 LocalPlanner(ros::NodeHandle nh);
30
35 void spin();
36
37 private:
38 FRIEND_TEST(LocalPlannerTest, noInputCase);
39
44
49
54 void terrainMapCallback(const grid_map_msgs::GridMap::ConstPtr &msg);
55
60 void robotPlanCallback(const quad_msgs::RobotPlan::ConstPtr &msg);
61
67 void robotStateCallback(const quad_msgs::RobotState::ConstPtr &msg);
68
74 void cmdVelCallback(const geometry_msgs::Twist::ConstPtr &msg);
75
80 void getReference();
81
86 bool computeLocalPlan();
87
91 void publishLocalPlan();
92
94 std::string robot_name_;
95
97 ros::Subscriber terrain_map_sub_;
98
100 ros::Subscriber body_plan_sub_;
101
103 ros::Subscriber robot_state_sub_;
104
106 ros::Subscriber cmd_vel_sub_;
107
109 ros::Publisher local_plan_pub_;
110
113
116
118 std::string map_frame_;
119
121 ros::NodeHandle nh_;
122
125
127 grid_map::GridMap terrain_grid_;
128
131
133 std::shared_ptr<NMPCController> local_body_planner_nonlinear_;
134
136 std::shared_ptr<LocalFootstepPlanner> local_footstep_planner_;
137
139 quad_msgs::RobotPlan::ConstPtr body_plan_msg_;
140
142 quad_msgs::RobotState::ConstPtr robot_state_msg_;
143
145 quad_msgs::MultiFootState past_footholds_msg_;
146
149
151 Eigen::VectorXd current_state_;
152
153 // Current positions of each foot
154 Eigen::VectorXd current_foot_positions_world_;
155
156 // Current velocities of each foot
157 Eigen::VectorXd current_foot_velocities_world_;
158
159 // Current positions of each foot
160 Eigen::VectorXd current_foot_positions_body_;
161
164
166 double dt_;
167
170
173
175 const double filter_smoothing_constant_ = 0.5;
176
178 int N_;
179
182
184 const int Nx_ = 12;
185
187 const int Nu_ = 13;
188
190 const int num_feet_ = 4;
191
193 const int num_joints_per_leg_ = 3;
194
197 Eigen::MatrixXd body_plan_;
198
201 Eigen::MatrixXd ref_body_plan_;
202
204 Eigen::VectorXd ref_ground_height_;
205
207 Eigen::VectorXi ref_primitive_plan_;
208
211 Eigen::MatrixXd grf_plan_;
212
214 std::vector<std::vector<bool>> contact_schedule_;
215
217 Eigen::MatrixXd foot_positions_world_;
218
220 Eigen::MatrixXd foot_velocities_world_;
221
224
226 Eigen::MatrixXd foot_positions_body_;
227
229 Eigen::MatrixXd foot_plan_discrete_;
230
232 std::shared_ptr<quad_utils::QuadKD> quadKD_;
233
235 Eigen::VectorXd cmd_vel_;
236
239
242
244 double z_des_;
245
248
251
254
257
260
262 Eigen::Vector3d stand_pose_;
263
266
269
272
275
278
281
284};
285
286#endif // LOCAL_PLANNER_H
A terrain map class built for fast and efficient sampling.
Definition fast_terrain_map.h:16
Local Body Planner library.
Definition local_planner.h:22
double stand_pos_error_threshold_
Position error threshold (from foot centroid) to enter stand mode.
Definition local_planner.h:283
Eigen::MatrixXd grf_plan_
Definition local_planner.h:211
ros::Time current_state_timestamp_
Timestamp of the state estimate.
Definition local_planner.h:148
Eigen::MatrixXd foot_plan_discrete_
Matrix of foot contact locations (number of contacts x num_legs_)
Definition local_planner.h:229
void robotStateCallback(const quad_msgs::RobotState::ConstPtr &msg)
Callback function to handle new state estimates.
Definition local_planner.cpp:188
ros::Publisher foot_plan_discrete_pub_
ROS publisher for discrete foot plan.
Definition local_planner.h:112
ros::Subscriber robot_state_sub_
ROS Subscriber for incoming states.
Definition local_planner.h:103
std::shared_ptr< quad_utils::QuadKD > quadKD_
QuadKD class.
Definition local_planner.h:232
Eigen::MatrixXd foot_positions_body_
Matrix of continuous foot positions in body frame.
Definition local_planner.h:226
bool use_twist_input_
Boolean for using twist input instead of a global body plan.
Definition local_planner.h:259
Eigen::VectorXd cmd_vel_
Twist input.
Definition local_planner.h:235
std::string map_frame_
Define map frame.
Definition local_planner.h:118
ros::Time initial_timestamp_
Initial timestamp for contact cycling.
Definition local_planner.h:253
int N_
Standard MPC horizon length.
Definition local_planner.h:178
int control_mode_
Control mode.
Definition local_planner.h:274
const int Nu_
Number of controls.
Definition local_planner.h:187
void initLocalBodyPlanner()
Initialize the local body planner.
Definition local_planner.cpp:111
Eigen::VectorXd ref_ground_height_
Vector of ground height along reference trajectory.
Definition local_planner.h:204
ros::Subscriber terrain_map_sub_
ROS subscriber for incoming terrain_map.
Definition local_planner.h:97
void getReference()
Function to compute reference trajectory from twist command or global plan.
Definition local_planner.cpp:212
Eigen::VectorXd current_state_
Current state (ground truth or estimate)
Definition local_planner.h:151
Eigen::VectorXi ref_primitive_plan_
Vector of primitive along reference trajectory.
Definition local_planner.h:207
double cmd_vel_filter_const_
Commanded velocity filter constant.
Definition local_planner.h:238
std::string robot_name_
Robot type: A1 or Spirit.
Definition local_planner.h:94
void initLocalFootstepPlanner()
Initialize the local footstep planner.
Definition local_planner.cpp:124
int N_current_
Current MPC horizon length.
Definition local_planner.h:181
double update_rate_
Update rate for sending and receiving data;.
Definition local_planner.h:130
FastTerrainMap terrain_
Struct for terrain map data.
Definition local_planner.h:124
void spin()
Primary work function in class, called in node file for this component.
Definition local_planner.cpp:576
Eigen::MatrixXd foot_velocities_world_
Matrix of continuous foot velocities in world frame.
Definition local_planner.h:220
bool computeLocalPlan()
Function to compute the local plan.
Definition local_planner.cpp:431
ros::Subscriber body_plan_sub_
ROS subscriber for incoming body plans.
Definition local_planner.h:100
ros::Subscriber cmd_vel_sub_
Subscriber for twist input messages.
Definition local_planner.h:106
bool first_plan_
Foot initialization flag when using twist input without a global body plan.
Definition local_planner.h:256
const int Nx_
Number of states.
Definition local_planner.h:184
double stand_cmd_vel_threshold_
Commanded velocity threshold to enter stand mode.
Definition local_planner.h:280
const double filter_smoothing_constant_
Exponential filter smoothing constant (higher updates slower)
Definition local_planner.h:175
void publishLocalPlan()
Function to publish the local plan.
Definition local_planner.cpp:502
void robotPlanCallback(const quad_msgs::RobotPlan::ConstPtr &msg)
Callback function to handle new plans.
Definition local_planner.cpp:183
quad_msgs::MultiFootState past_footholds_msg_
Past foothold locations.
Definition local_planner.h:145
ros::Time last_cmd_vel_msg_time_
Time of the most recent cmd_vel data.
Definition local_planner.h:247
void cmdVelCallback(const geometry_msgs::Twist::ConstPtr &msg)
Callback function to handle new desired twist data when using twist input.
Definition local_planner.cpp:196
double dt_
local planner timestep (seconds)
Definition local_planner.h:166
double toe_radius_
Toe radius.
Definition local_planner.h:271
int current_plan_index_
Current index in the global plan.
Definition local_planner.h:163
ros::NodeHandle nh_
Nodehandle to pub to and sub from.
Definition local_planner.h:121
Eigen::MatrixXd ref_body_plan_
Definition local_planner.h:201
std::vector< std::vector< bool > > contact_schedule_
Contact schedule.
Definition local_planner.h:214
double last_cmd_vel_msg_time_max_
Threshold for waiting for twist cmd_vel data.
Definition local_planner.h:250
grid_map::GridMap terrain_grid_
GridMap for terrain map data.
Definition local_planner.h:127
Eigen::Vector3d stand_pose_
Vector for stand pose (x, y, yaw)
Definition local_planner.h:262
double compute_time_
Computation time in computeLocalPlan.
Definition local_planner.h:169
ros::Publisher foot_plan_continuous_pub_
ROS publisher for continuous foot plan.
Definition local_planner.h:115
int plan_index_diff_
Difference in plan index from last solve.
Definition local_planner.h:268
Eigen::MatrixXd foot_positions_world_
Matrix of continuous foot positions in world frame.
Definition local_planner.h:217
double first_element_duration_
Time duration to the next plan index.
Definition local_planner.h:265
const int num_joints_per_leg_
Number of joints per leg.
Definition local_planner.h:193
ros::Publisher local_plan_pub_
ROS publisher for local plan output.
Definition local_planner.h:109
double cmd_vel_scale_
Scale for twist cmd_vel.
Definition local_planner.h:241
quad_msgs::RobotState::ConstPtr robot_state_msg_
Most recent robot state.
Definition local_planner.h:142
double stand_vel_threshold_
Velocity threshold to enter stand mode.
Definition local_planner.h:277
const int num_feet_
Number of legs.
Definition local_planner.h:190
std::shared_ptr< LocalFootstepPlanner > local_footstep_planner_
Local Footstep Planner object.
Definition local_planner.h:136
quad_msgs::RobotPlan::ConstPtr body_plan_msg_
Most recent robot plan.
Definition local_planner.h:139
std::shared_ptr< NMPCController > local_body_planner_nonlinear_
Local Body Planner object.
Definition local_planner.h:133
double z_des_
Nominal robot height.
Definition local_planner.h:244
Eigen::MatrixXd foot_accelerations_world_
Matrix of continuous foot accelerations in world frame.
Definition local_planner.h:223
double mean_compute_time_
Average computation time in computeLocalPlan.
Definition local_planner.h:172
void terrainMapCallback(const grid_map_msgs::GridMap::ConstPtr &msg)
Callback function to handle new terrain map data.
Definition local_planner.cpp:173
Eigen::MatrixXd body_plan_
Definition local_planner.h:197