Tetrapod Project
waypoint_planner.cpp
Go to the documentation of this file.
2 
3 #include "drake/solvers/branch_and_bound.h"
4 
5 #include "drake/solvers/osqp_solver.h"
6 
7 #include <iostream>
8 DecVars_res waypoint_planner(Terrain &terrain, int n_points, double length_legs, double bbox_len, double wp_dist)
9 {
10  drake::solvers::MathematicalProgram prog;
11 
12  Eigen::Vector3d initial_center = terrain.getStoneByName("initial").getCenter();
13 
14  Eigen::Vector3d goal_center = terrain.getStoneByName("goal").getCenter();
15 
16  ROS_INFO("adding decision variables");
17  DecVars decision_variables = add_decision_variables(prog, terrain, n_points);
18 
19  ROS_INFO("setting initial and goal position");
20  set_initial_and_goal_position(prog, initial_center, goal_center, decision_variables);
21 
22  ROS_INFO("setting relative position limits");
23  relative_position_limits(prog, n_points, wp_dist, decision_variables);
24 
25  ROS_INFO("setting geometry limits");
26  geometry_limits(prog, n_points, length_legs, bbox_len, decision_variables);
27 
28  ROS_INFO("setting theta limits");
29  theta_limits(prog, n_points, decision_variables);
30 
31  ROS_INFO("one stone per foot");
32  one_stone_per_foot(prog, n_points, decision_variables);
33 
34  ROS_INFO("foot in stepping stone");
35  foot_in_stepping_stone(prog, terrain, n_points, decision_variables);
36 
37  ROS_INFO("minimize step length");
38  minimize_step_length(prog, n_points, decision_variables);
39 
40  ROS_INFO("minimize theta change");
41  minimize_theta_change(prog, n_points, decision_variables);
42 
43  ROS_INFO("bb");
44  drake::solvers::MixedIntegerBranchAndBound bb(prog, drake::solvers::OsqpSolver::id());
45 
46  /*auto constr = prog.GetAllLinearConstraints();
47 
48  for (auto el: constr) {
49  std::cout << el << std::endl;
50  }
51  std::cout << constr.size() << std::endl;*/
52  ROS_INFO("solve");
53  drake::solvers::SolutionResult result = bb.Solve();
54  ROS_INFO("done solving");
55  if (result != drake::solvers::kSolutionFound)
56  {
57  ROS_ERROR("Infeasible optimization problem.");
58  }
59 
60  DecVars_res decision_variables_opt;
61 
62  decision_variables_opt.position_front_left = bb.GetSolution(decision_variables.position_front_left);
63 
64  decision_variables_opt.position_front_right = bb.GetSolution(decision_variables.position_front_right);
65 
66  decision_variables_opt.position_rear_left = bb.GetSolution(decision_variables.position_rear_left);
67 
68  decision_variables_opt.position_rear_right = bb.GetSolution(decision_variables.position_rear_right);
69 
70  decision_variables_opt.stone_front_left = bb.GetSolution(decision_variables.stone_front_left);
71 
72  decision_variables_opt.stone_front_right = bb.GetSolution(decision_variables.stone_front_right);
73 
74  decision_variables_opt.stone_rear_left = bb.GetSolution(decision_variables.stone_rear_left);
75 
76  decision_variables_opt.stone_rear_right = bb.GetSolution(decision_variables.stone_rear_right);
77 
78  decision_variables_opt.theta = bb.GetSolution(decision_variables.theta);
79 
80  decision_variables_opt.bin_sin = bb.GetSolution(decision_variables.bin_sin);
81 
82  decision_variables_opt.bin_cos = bb.GetSolution(decision_variables.bin_cos);
83 
84  decision_variables_opt.lin_sin = bb.GetSolution(decision_variables.lin_sin);
85 
86  decision_variables_opt.lin_cos = bb.GetSolution(decision_variables.lin_cos);
87 
88  decision_variables_opt.cost = bb.GetOptimalCost();
89 
90  return decision_variables_opt;
91 }
const Eigen::Vector3d & getCenter() const
const SteppingStone & getStoneByName(std::string name) const
Definition: terrain.cpp:95
Eigen::Vector3d Vector3d
Definition: kinematics.h:49
void foot_in_stepping_stone(drake::solvers::MathematicalProgram &prog, Terrain &terrain, int n_steps, DecVars &decision_variables)
Definition: miqp_biped.cpp:167
void relative_position_limits(drake::solvers::MathematicalProgram &prog, int n_steps, double step_span, DecVars &decision_variables)
void set_initial_and_goal_position(drake::solvers::MathematicalProgram &prog, Terrain &terrain, DecVars &decision_variables)
Definition: miqp_biped.cpp:34
DecVars add_decision_variables(drake::solvers::MathematicalProgram &prog, Terrain &terrain, int n_steps)
Definition: miqp_biped.cpp:13
void minimize_step_length(drake::solvers::MathematicalProgram &prog, int n_steps, DecVars &decision_variables)
Definition: miqp_biped.cpp:218
void one_stone_per_foot(drake::solvers::MathematicalProgram &prog, int n_steps, DecVars &decision_variables)
Definition: miqp_biped.cpp:137
void theta_limits(drake::solvers::MathematicalProgram &prog, int n_steps, int n_legs, DecVars &decision_variables)
void geometry_limits(drake::solvers::MathematicalProgram &prog, int n_steps, int n_legs, double length_legs, Leg step_sequence[], Terrain &terrain, double bbox_len, DecVars &decision_variables)
void minimize_theta_change(drake::solvers::MathematicalProgram &prog, int n_points, DecVars &decision_variables)
Eigen::MatrixXd position_front_right
Definition: miqp_waypoint.h:60
Eigen::MatrixXd stone_front_left
Definition: miqp_waypoint.h:66
Eigen::MatrixXd position_front_left
Definition: miqp_waypoint.h:58
Eigen::MatrixXd position_rear_left
Definition: miqp_waypoint.h:62
Eigen::MatrixXd stone_rear_right
Definition: miqp_waypoint.h:72
Eigen::MatrixXd stone_rear_left
Definition: miqp_waypoint.h:70
Eigen::MatrixXd position_rear_right
Definition: miqp_waypoint.h:64
Eigen::MatrixXd stone_front_right
Definition: miqp_waypoint.h:68
MatrixXDecisionVariable stone_front_left
Definition: miqp_waypoint.h:36
MatrixXDecisionVariable bin_cos
Definition: miqp_waypoint.h:48
MatrixXDecisionVariable theta
Definition: miqp_waypoint.h:44
MatrixXDecisionVariable stone_front_right
Definition: miqp_waypoint.h:38
MatrixXDecisionVariable position_front_left
Definition: miqp_waypoint.h:28
MatrixXDecisionVariable position_front_right
Definition: miqp_waypoint.h:30
MatrixXDecisionVariable position_rear_right
Definition: miqp_waypoint.h:34
MatrixXDecisionVariable lin_cos
Definition: miqp_waypoint.h:52
MatrixXDecisionVariable stone_rear_right
Definition: miqp_waypoint.h:42
MatrixXDecisionVariable bin_sin
Definition: miqp_waypoint.h:46
MatrixXDecisionVariable lin_sin
Definition: miqp_waypoint.h:50
MatrixXDecisionVariable stone_rear_left
Definition: miqp_waypoint.h:40
MatrixXDecisionVariable position_rear_left
Definition: miqp_waypoint.h:32
DecVars_res waypoint_planner(Terrain &terrain, int n_points, double length_legs, double bbox_len, double wp_dist)