5#include <OsqpEigen/OsqpEigen.h>
6#include <pinocchio/algorithm/crba.hpp>
7#include <pinocchio/algorithm/rnea.hpp>
8#include <pinocchio/multibody/data.hpp>
9#include <pinocchio/parsers/urdf.hpp>
10#include <state_representation/parameters/Parameter.hpp>
11#include <state_representation/parameters/ParameterInterface.hpp>
12#include <state_representation/space/Jacobian.hpp>
13#include <state_representation/space/joint/JointState.hpp>
14#include <state_representation/space/cartesian/CartesianState.hpp>
16using namespace std::chrono_literals;
37 double tolerance = 1e-3;
38 unsigned int max_number_of_iterations = 1000;
51 double proportional_gain = 1.0;
52 double linear_velocity_limit = 2.0;
53 double angular_velocity_limit = 2.0;
54 std::chrono::nanoseconds dt = 1000ns;
65 std::shared_ptr<state_representation::Parameter<std::string>> robot_name_;
66 std::shared_ptr<state_representation::Parameter<std::string>> urdf_path_;
67 std::vector<std::string> frames_;
68 pinocchio::Model robot_model_;
69 pinocchio::Data robot_data_;
70 OsqpEigen::Solver solver_;
71 Eigen::SparseMatrix<double> hessian_;
72 Eigen::VectorXd gradient_;
73 Eigen::SparseMatrix<double> constraint_matrix_;
74 Eigen::VectorXd lower_bound_constraints_;
75 Eigen::VectorXd upper_bound_constraints_;
85 bool init_qp_solver();
92 std::vector<unsigned int> get_frame_ids(
const std::vector<std::string>& frames);
99 unsigned int get_frame_id(
const std::string& frame);
108 unsigned int frame_id);
119 unsigned int frame_id);
128 const std::vector<unsigned int>& frame_ids);
137 unsigned int frame_id);
146 static bool in_range(
const Eigen::VectorXd& vector,
147 const Eigen::VectorXd& lower_limits,
148 const Eigen::VectorXd& upper_limits);
157 static Eigen::VectorXd clamp_in_range(
const Eigen::VectorXd& vector,
158 const Eigen::VectorXd& lower_limits,
159 const Eigen::VectorXd& upper_limits);
184 void check_inverse_velocity_arguments(
const std::vector<state_representation::CartesianTwist>& cartesian_twists,
186 const std::vector<std::string>& frames);
192 explicit Model(
const std::string& robot_name,
const std::string& urdf_path);
290 const std::string& frame =
"");
301 const std::string& frame =
"");
347 const std::vector<std::string>& frames);
356 const std::string& frame =
"");
368 const std::string& frame =
"");
382 const std::string& frame =
"");
391 const std::vector<std::string>& frames);
400 const std::string& frame =
"");
412 const std::vector<std::string>& frames);
426 const std::string& frame =
"");
441 const std::vector<std::string>& frames);
457 const std::string& frame =
"");
503 std::swap(model1.robot_name_, model2.robot_name_);
504 std::swap(model1.urdf_path_, model2.urdf_path_);
518 return this->robot_name_->get_value();
522 this->robot_name_->set_value(robot_name);
526 return this->urdf_path_->get_value();
530 return this->robot_model_.nq;
535 std::vector<std::string> joint_frames(this->robot_model_.names.begin() + 1, this->robot_model_.names.end());
540 return this->frames_.front();
544 return this->frames_;
548 return this->robot_model_.gravity.linear();
552 this->robot_model_.gravity.linear(gravity);
556 return this->robot_model_;
The Model class is a wrapper around pinocchio dynamic computation library with state_representation e...
unsigned int get_number_of_joints() const
Getter of the number of joints.
std::vector< state_representation::CartesianTwist > forward_velocity(const state_representation::JointState &joint_state, const std::vector< std::string > &frames)
Compute the forward velocity kinematics, i.e. the twist of certain frames from the joint states.
Model & operator=(const Model &Model)
Copy assignment operator that have to be defined due to the custom assignment operator.
Eigen::Vector3d get_gravity_vector() const
Getter of the gravity vector.
Eigen::MatrixXd compute_coriolis_matrix(const state_representation::JointState &joint_state)
Compute the Coriolis matrix from a given joint state.
state_representation::JointTorques compute_inertia_torques(const state_representation::JointState &joint_state)
Compute the Inertia torques, i.e the inertia matrix multiplied by the joint accelerations....
state_representation::JointVelocities inverse_velocity(const std::vector< state_representation::CartesianTwist > &cartesian_twists, const state_representation::JointPositions &joint_positions, const std::vector< std::string > &frames)
Compute the inverse velocity kinematics, i.e. joint velocities from the velocities of the frames in p...
const std::string & get_base_frame() const
Getter of the base frame of the robot.
state_representation::JointTorques compute_gravity_torques(const state_representation::JointPositions &joint_positions)
Compute the gravity torques.
void set_gravity_vector(const Eigen::Vector3d &gravity)
Setter of the gravity vector.
Eigen::MatrixXd compute_inertia_matrix(const state_representation::JointPositions &joint_positions)
Compute the Inertia matrix from a given joint positions.
friend void swap(Model &model1, Model &model2)
Swap the values of the two Model.
const std::string & get_urdf_path() const
Getter of the URDF path.
state_representation::JointPositions inverse_kinematics(const state_representation::CartesianPose &cartesian_pose, const InverseKinematicsParameters ¶meters=InverseKinematicsParameters(), const std::string &frame="")
Compute the inverse kinematics, i.e. joint positions from the pose of the end-effector in an iterativ...
std::vector< std::string > get_frames() const
Getter of the frames from the model.
void set_robot_name(const std::string &robot_name)
Setter of the robot name.
state_representation::JointTorques compute_coriolis_torques(const state_representation::JointState &joint_state)
Compute the Coriolis torques, i.e. the Coriolis matrix multiplied by the joint velocities and express...
void print_qp_problem()
Helper function to print the qp_problem (for debugging)
const pinocchio::Model & get_pinocchio_model() const
Getter of the pinocchio model.
const std::string & get_robot_name() const
Getter of the robot name.
std::vector< std::string > get_joint_frames() const
Getter of the joint frames from the model.
static bool create_urdf_from_string(const std::string &urdf_string, const std::string &desired_path)
Creates a URDF file with desired path and name from a string (possibly the robot description string f...
Class to define CartesianPose in cartesian space as 3D position and quaternion based orientation.
Class to define twist in cartesian space as 3D linear and angular velocity vectors.
Class to define a robot Jacobian matrix.
Class to define a positions of the joints.
Class to define a state in joint space.
Class to define torques of the joints.
Class to define velocities of the joints.
Robot kinematics and dynamics.
void swap(Model &model1, Model &model2)
parameters for the inverse kinematics function
parameters for the inverse velocity kinematics function