35 #include "ros/callback_queue.h"
38 #include "std_msgs/Int8MultiArray.h"
39 #include "std_msgs/Float64MultiArray.h"
40 #include "sensor_msgs/JointState.h"
45 #include <math_utils/Core>
54 #include <drake/common/symbolic.h>
55 #include <drake/solvers/mathematical_program.h>
56 #include <drake/solvers/solve.h>
57 #include <drake/solvers/osqp_solver.h>
58 #include <drake/solvers/equality_constrained_qp_solver.h>
59 #include <drake/solvers/clp_solver.h>
60 #include <drake/solvers/scs_solver.h>
61 #include <drake/solvers/snopt_solver.h>
117 const Eigen::Matrix<double, 3, 1> &_desired_base_vel,
118 const Eigen::Matrix<double, 3, 1> &_desired_base_acc,
119 const Eigen::Matrix<double, 3, 1> &_desired_base_ori,
120 const Eigen::Matrix<Eigen::Vector3d, 4, 1> &_desired_f_pos,
121 const Eigen::Matrix<Eigen::Vector3d, 4, 1> &_desired_f_vel,
122 const Eigen::Matrix<Eigen::Vector3d, 4, 1> &_desired_f_acc,
123 const Eigen::Matrix<Eigen::Vector3d, 4, 1> &_f_pos,
124 const Eigen::Matrix<Eigen::Vector3d, 4, 1> &_f_vel,
125 const Eigen::Matrix<double, 18, 1> &_q,
126 const Eigen::Matrix<double, 18, 1> &_u,
145 const std::vector<Task> &_tasks,
165 const Eigen::Matrix<Eigen::Matrix<double, Eigen::Dynamic, 1>, Eigen::Dynamic, 1> &_b,
188 public:
bool SolveQP(
const Eigen::MatrixXd &_Q,
189 const Eigen::VectorXd &_c,
190 const Eigen::MatrixXd &_E_ineq,
191 const Eigen::VectorXd &_f_ineq,
192 Eigen::VectorXd &_sol,
193 const SolverType &_solver = SolverType::UNSPECIFIED,
217 public:
bool SolveQP(
const Eigen::MatrixXd &_Q,
218 const Eigen::VectorXd &_c,
219 const Eigen::MatrixXd &_A,
220 const Eigen::VectorXd &_lb,
221 const Eigen::VectorXd &_ub,
222 Eigen::VectorXd &_sol,
223 const SolverType &_solver = SolverType::UNSPECIFIED,
249 public:
bool SolveQP(
const Eigen::MatrixXd &_Q,
250 const Eigen::VectorXd &_c,
251 const Eigen::MatrixXd &_E_eq,
252 const Eigen::VectorXd &_f_eq,
253 const Eigen::MatrixXd &_E_ineq,
254 const Eigen::VectorXd &_f_ineq,
255 Eigen::VectorXd &_sol,
256 const SolverType &_solver = SolverType::UNSPECIFIED,
263 public:
void PublishTorqueMsg(
const Eigen::Matrix<double, 12, 1> &_desired_tau);
269 public:
void OnGenCoordMsg(
const std_msgs::Float64MultiArrayConstPtr &_msg);
275 public:
void OnGenVelMsg(
const std_msgs::Float64MultiArrayConstPtr &_msg);
305 private: Eigen::Matrix<double, 18, 1>
genVel;
308 private: Eigen::Matrix<Eigen::Vector3d, 4, 1>
fPos;
311 private: Eigen::Matrix<Eigen::Vector3d, 4, 1>
fVel;
317 private: std::unique_ptr<ros::NodeHandle>
rosNode;
A class for hierarchical optimization control.
ros::Subscriber genVelSub
ROS Generalized Coordinates Subscriber.
std::thread rosProcessQueueThread
Thread running the rosProcessQueue.
std::unique_ptr< ros::NodeHandle > rosNode
Node used for ROS transport.
std::thread rosPublishQueueThread
Thread running the rosPublishQueue.
HierarchicalOptimizationControl()
Constructor.
Eigen::Matrix< double, 18, 1 > genCoord
Generalized Coordinates.
Kinematics kinematics
Kinematics.
bool SolveQP(const Eigen::MatrixXd &_Q, const Eigen::VectorXd &_c, const Eigen::MatrixXd &_E_ineq, const Eigen::VectorXd &_f_ineq, Eigen::VectorXd &_sol, const SolverType &_solver=SolverType::UNSPECIFIED, const int &_v=0)
The SolveQP function solves a (convex) quadratic program (QP) on the form:
void PublishTorqueMsg(const Eigen::Matrix< double, 12, 1 > &_desired_tau)
The PublishTorqueMsg function publishes a desired torque message to the ROS topic set by the joint st...
int contactState[4]
Contact State.
LegType
Leg type enumerator.
Eigen::Matrix< double, Eigen::Dynamic, 1 > HierarchicalQPOptimization(const int &_state_dim, const std::vector< Task > &_tasks, const SolverType &_solver=SolverType::OSQP, const int &_v=0)
The HierarchicalQPOptimization function finds the optimal solution for a set of tasks in a strictly p...
ros::CallbackQueue rosProcessQueue
ROS callbackque that helps process messages.
BodyType
Body type enumerator.
Eigen::Matrix< double, 18, 1 > genVel
Generalized Velocities.
void ProcessQueueThread()
The ProcessQueueThread function is a ROS helper function that processes messages.
void OnGenCoordMsg(const std_msgs::Float64MultiArrayConstPtr &_msg)
The OnGenCoordMsg function handles an incoming generalized coordinates message from ROS.
Eigen::Matrix< Eigen::Vector3d, 4, 1 > fVel
Foot-point velocities.
void InitRosQueueThreads()
The InitRosQueueThreads function is called to initialize the ROS Publish and Process Queue Threads.
Eigen::Matrix< double, 12, 1 > HierarchicalOptimization(const Eigen::Matrix< double, 3, 1 > &_desired_base_pos, const Eigen::Matrix< double, 3, 1 > &_desired_base_vel, const Eigen::Matrix< double, 3, 1 > &_desired_base_acc, const Eigen::Matrix< double, 3, 1 > &_desired_base_ori, const Eigen::Matrix< Eigen::Vector3d, 4, 1 > &_desired_f_pos, const Eigen::Matrix< Eigen::Vector3d, 4, 1 > &_desired_f_vel, const Eigen::Matrix< Eigen::Vector3d, 4, 1 > &_desired_f_acc, const Eigen::Matrix< Eigen::Vector3d, 4, 1 > &_f_pos, const Eigen::Matrix< Eigen::Vector3d, 4, 1 > &_f_vel, const Eigen::Matrix< double, 18, 1 > &_q, const Eigen::Matrix< double, 18, 1 > &_u, const int &_v=0)
The HierarchicalOptimization function finds the optimal joint torques for a desired motion plan....
void OnContactStateMsg(const std_msgs::Int8MultiArrayConstPtr &_msg)
The OnContactStateMsg function handles an incoming contact state message from ROS.
Eigen::Matrix< Eigen::Vector3d, 4, 1 > fPos
Foot-point positions.
void PublishQueueThread()
The PublishQueueThread function is a ROS helper function that publish state messages.
ros::Publisher jointStatePub
ROS Joint State Publisher.
Eigen::Matrix< double, Eigen::Dynamic, 1 > HierarchicalLeastSquareOptimization(const Eigen::Matrix< Eigen::MatrixXd, Eigen::Dynamic, 1 > &_A, const Eigen::Matrix< Eigen::Matrix< double, Eigen::Dynamic, 1 >, Eigen::Dynamic, 1 > &_b, const int &_v=0)
The HierarchicalLeastSquareOptimization function finds the optimal solution for a set of linear equal...
void InitRos()
The InitRos function is called to initialize ROS.
void OnGenVelMsg(const std_msgs::Float64MultiArrayConstPtr &_msg)
The OnGenVelMsg function handles an incoming generalized velocities message from ROS.
ros::Subscriber genCoordSub
ROS Generalized Coordinates Subscriber.
ros::CallbackQueue rosPublishQueue
ROS callbackque that helps publish messages.
virtual ~HierarchicalOptimizationControl()
Destructor.
ros::Publisher basePoseCmdPub
ROS Base Position Command Publisher.
SolverType
Drake Solver type enumerator.
ros::Subscriber contactStateSub
ROS Contact State Subscriber.
ros::Publisher baseTwistCmdPub
ROS Base Position Command Publisher.
A class for analytical Kinematics Solving.
bool has_eq_constraint
Bool indicating whether the task has a linear equality constraint.
Eigen::MatrixXd A_ineq
Linear inequality constraint matrix A.
Eigen::VectorXd b_ineq
Linear inequality constraint vector b.
Eigen::VectorXd b_eq
Linear equality constraint vector b.
bool has_ineq_constraint
Bool indicating whether the task has a linear inequality constraint.
Eigen::MatrixXd A_eq
Linear equality constraint matrix A.