Go to the documentation of this file.
30 #ifndef EXOTICA_CORE_KINEMATIC_TREE_H_
31 #define EXOTICA_CORE_KINEMATIC_TREE_H_
38 #include <moveit/robot_model/robot_model.h>
39 #include <tf/transform_datatypes.h>
40 #include <visualization_msgs/MarkerArray.h>
41 #include <Eigen/Eigen>
42 #include <kdl/jacobian.hpp>
43 #include <kdl/tree.hpp>
70 constexpr
double inf = std::numeric_limits<double>::infinity();
71 constexpr
double pi = M_PI;
86 KinematicFrameRequest(std::string _frame_A_link_name, KDL::Frame _frame_A_offset = KDL::Frame(), std::string _frame_B_link_name =
"", KDL::Frame _frame_B_offset = KDL::Frame());
97 std::vector<KinematicFrameRequest>
frames;
132 void Create(std::shared_ptr<KinematicResponse> solution);
135 Eigen::Map<Eigen::VectorXd>
X{
nullptr, 0};
136 Eigen::Map<ArrayFrame>
Phi{
nullptr, 0};
145 void Instantiate(
const std::string& joint_group, robot_model::RobotModelPtr model,
const std::string& name);
160 void SetFloatingBaseLimitsPosXYZEulerZYX(
const std::vector<double>& lower,
const std::vector<double>& upper,
const std::vector<double>& velocity,
const std::vector<double>& acceleration);
162 void SetPlanarBaseLimitsPosXYEulerZ(
const std::vector<double>& lower,
const std::vector<double>& upper,
const std::vector<double>& velocity,
const std::vector<double>& acceleration);
169 void PublishFrames(
const std::string& tf_prefix =
"exotica");
196 KDL::Frame
FK(std::shared_ptr<KinematicElement> element_A,
const KDL::Frame& offset_a, std::shared_ptr<KinematicElement> element_B,
const KDL::Frame& offset_b)
const;
197 KDL::Frame
FK(
const std::string& element_A,
const KDL::Frame& offset_a,
const std::string& element_B,
const KDL::Frame& offset_b)
const;
198 Eigen::MatrixXd
Jacobian(std::shared_ptr<KinematicElement> element_A,
const KDL::Frame& offset_a, std::shared_ptr<KinematicElement> element_B,
const KDL::Frame& offset_b)
const;
199 Eigen::MatrixXd
Jacobian(
const std::string& element_A,
const KDL::Frame& offset_a,
const std::string& element_B,
const KDL::Frame& offset_b)
const;
200 exotica::Hessian Hessian(std::shared_ptr<KinematicElement> element_A,
const KDL::Frame& offset_a, std::shared_ptr<KinematicElement> element_B,
const KDL::Frame& offset_b)
const;
201 exotica::Hessian Hessian(
const std::string& element_A,
const KDL::Frame& offset_a,
const std::string& element_B,
const KDL::Frame& offset_b)
const;
204 std::shared_ptr<KinematicElement>
AddElement(
const std::string& name,
const Eigen::Isometry3d& transform,
const std::string& parent =
"", shapes::ShapeConstPtr shape = shapes::ShapeConstPtr(
nullptr),
const KDL::RigidBodyInertia& inertia = KDL::RigidBodyInertia::Zero(),
const Eigen::Vector4d& color = Eigen::Vector4d(0.5, 0.5, 0.5, 1.0),
const std::vector<VisualElement>& visual = {},
bool is_controlled =
false);
205 std::shared_ptr<KinematicElement>
AddEnvironmentElement(
const std::string& name,
const Eigen::Isometry3d& transform,
const std::string& parent =
"", shapes::ShapeConstPtr shape = shapes::ShapeConstPtr(
nullptr),
const KDL::RigidBodyInertia& inertia = KDL::RigidBodyInertia::Zero(),
const Eigen::Vector4d& color = Eigen::Vector4d(0.5, 0.5, 0.5, 1.0),
const std::vector<VisualElement>& visual = {},
bool is_controlled =
false);
206 std::shared_ptr<KinematicElement>
AddElement(
const std::string& name,
const Eigen::Isometry3d& transform,
const std::string& parent,
const std::string& shape_resource_path, Eigen::Vector3d scale = Eigen::Vector3d::Ones(),
const KDL::RigidBodyInertia& inertia = KDL::RigidBodyInertia::Zero(),
const Eigen::Vector4d& color = Eigen::Vector4d(0.5, 0.5, 0.5, 1.0),
const std::vector<VisualElement>& visual = {},
bool is_controlled =
false);
208 void ChangeParent(
const std::string& name,
const std::string& parent,
const KDL::Frame& pose,
bool relative);
209 int IsControlled(std::shared_ptr<KinematicElement> joint);
219 std::vector<std::string>
GetKinematicChain(
const std::string& begin,
const std::string& end)
const;
231 const std::vector<std::weak_ptr<KinematicElement>>&
GetTree()
const {
return tree_; }
254 void BuildTree(
const KDL::Tree& RobotKinematics);
284 std::vector<std::weak_ptr<KinematicElement>>
tree_;
287 std::map<std::string, std::weak_ptr<KinematicElement>>
tree_map_;
289 std::shared_ptr<KinematicElement>
root_;
297 std::shared_ptr<KinematicResponse>
solution_ = std::make_shared<KinematicResponse>();
310 #endif // EXOTICA_CORE_KINEMATIC_TREE_H_
BaseType GetControlledBaseType() const
@ KIN_H
Definition: kinematic_tree.h:61
exotica::Hessian Hessian(std::shared_ptr< KinematicElement > element_A, const KDL::Frame &offset_a, std::shared_ptr< KinematicElement > element_B, const KDL::Frame &offset_b) const
std::shared_ptr< KinematicResponse > RequestFrames(const KinematicsRequest &request)
std::vector< KinematicFrameRequest > frames
Definition: kinematic_tree.h:97
void Update(Eigen::VectorXdRefConst x)
Eigen::Map< ArrayFrame > Phi
Definition: kinematic_tree.h:136
int num_controlled_joints_
Number of controlled joints in the joint group.
Definition: kinematic_tree.h:278
visualization_msgs::MarkerArray marker_array_msg_
Definition: kinematic_tree.h:305
bool DoesLinkWithNameExist(std::string name) const
Checks whether a link with this name exists in any of the trees.
ArrayFrame Phi
Definition: kinematic_tree.h:120
@ PLANAR
Definition: kinematic_tree.h:53
int IsControlledLink(const std::string &link_name)
std::shared_ptr< KinematicResponse > GetKinematicResponse()
Definition: kinematic_tree.h:250
Definition: uncopyable.h:35
std::vector< std::string > model_link_names_
Definition: kinematic_tree.h:295
std::random_device rd_
Definition: kinematic_tree.h:272
const std::string & GetRootFrameName() const
BaseType
Definition: kinematic_tree.h:49
KinematicRequestFlags flags
Definition: kinematic_tree.h:117
Eigen::VectorXd acceleration_limits_
Definition: kinematic_tree.h:267
void SetJointAccelerationLimits(Eigen::VectorXdRefConst acceleration_in)
const std::map< std::string, std::weak_ptr< KinematicElement > > & GetModelJointsMap() const
Definition: kinematic_tree.h:240
Eigen::MatrixXd Jacobian(std::shared_ptr< KinematicElement > element_A, const KDL::Frame &offset_a, std::shared_ptr< KinematicElement > element_B, const KDL::Frame &offset_b) const
std::vector< std::string > GetKinematicChainLinks(const std::string &begin, const std::string &end) const
GetKinematicChainLinks get the links between begin and end of kinematic chain.
ArrayJacobian jacobian
Definition: kinematic_tree.h:122
const Eigen::MatrixXd & GetJointLimits() const
Definition: kinematic_tree.h:154
int state_size_
Definition: kinematic_tree.h:280
Definition: kinematic_tree.h:83
std::vector< std::string > model_joints_names_
Definition: kinematic_tree.h:293
std::mt19937 generator_
Definition: kinematic_tree.h:273
KDL::Frame temp_A
Definition: kinematic_tree.h:107
std::vector< std::shared_ptr< KinematicElement > > model_tree_
Definition: kinematic_tree.h:285
@ KIN_J
Definition: kinematic_tree.h:59
std::string frame_A_link_name
Definition: kinematic_tree.h:87
void ChangeParent(const std::string &name, const std::string &parent, const KDL::Frame &pose, bool relative)
int GetNumControlledJoints() const
KDL::Frame frame_B_offset
Definition: kinematic_tree.h:90
std::map< std::string, std::weak_ptr< KinematicElement > > controlled_joints_map_
Definition: kinematic_tree.h:291
BaseType GetModelBaseType() const
const std::map< std::string, std::weak_ptr< KinematicElement > > & GetTreeMap() const
Definition: kinematic_tree.h:233
bool HasModelLink(const std::string &link) const
std::shared_ptr< KinematicElement > FindKinematicElementByName(const std::string &frame_name)
void SetKinematicResponse(std::shared_ptr< KinematicResponse > response_in)
Definition: kinematic_tree.h:249
bool debug_scene_changed_
Definition: kinematic_tree.h:304
std::shared_ptr< KinematicResponse > solution_
Definition: kinematic_tree.h:297
std::shared_ptr< KinematicElement > AddElement(const std::string &name, const Eigen::Isometry3d &transform, const std::string &parent="", shapes::ShapeConstPtr shape=shapes::ShapeConstPtr(nullptr), const KDL::RigidBodyInertia &inertia=KDL::RigidBodyInertia::Zero(), const Eigen::Vector4d &color=Eigen::Vector4d(0.5, 0.5, 0.5, 1.0), const std::vector< VisualElement > &visual={}, bool is_controlled=false)
Definition: cartpole_dynamics_solver.h:38
@ FLOATING
Definition: kinematic_tree.h:52
Eigen::Map< ArrayTwist > Phi_dot
Definition: kinematic_tree.h:137
Eigen::Array< Eigen::MatrixXd, Eigen::Dynamic, 1 > Hessian
Definition: conversions.h:154
const std::map< std::string, std::weak_ptr< KinematicElement > > & GetControlledJointsMap() const
Definition: kinematic_tree.h:239
constexpr double pi
Definition: kinematic_tree.h:71
std::string name_
Definition: kinematic_tree.h:306
const std::vector< std::string > & GetModelJointNames() const
Definition: kinematic_tree.h:181
std::map< std::string, double > GetModelStateMap() const
const std::map< std::string, std::weak_ptr< KinematicElement > > & GetCollisionTreeMap() const
Definition: kinematic_tree.h:234
std::map< std::string, std::weak_ptr< KinematicElement > > model_joints_map_
Definition: kinematic_tree.h:292
KDL::Frame frame_B_offset
Definition: kinematic_tree.h:105
const std::vector< std::string > & GetModelLinkNames() const
Definition: kinematic_tree.h:186
std::shared_ptr< KinematicElement > AddEnvironmentElement(const std::string &name, const Eigen::Isometry3d &transform, const std::string &parent="", shapes::ShapeConstPtr shape=shapes::ShapeConstPtr(nullptr), const KDL::RigidBodyInertia &inertia=KDL::RigidBodyInertia::Zero(), const Eigen::Vector4d &color=Eigen::Vector4d(0.5, 0.5, 0.5, 1.0), const std::vector< VisualElement > &visual={}, bool is_controlled=false)
void BuildTree(const KDL::Tree &RobotKinematics)
@ LIMIT_POSITION_UPPER
Definition: kinematic_tree.h:67
robot_model::RobotModelPtr GetRobotModel() const
@ KIN_FK
Definition: kinematic_tree.h:58
KinematicRequestFlags flags
Definition: kinematic_tree.h:96
KDL::Frame temp_AB
Definition: kinematic_tree.h:106
int num_joints_
Number of joints of the model (including floating/planar base, passive joints, and uncontrolled joint...
Definition: kinematic_tree.h:279
void ComputeH(KinematicFrame &frame, const KDL::Jacobian &jacobian, exotica::Hessian &hessian) const
BaseType model_base_type_
Definition: kinematic_tree.h:276
Definition: kinematic_tree.h:100
void SetJointLimitsLower(Eigen::VectorXdRefConst lower_in)
Eigen::Map< ArrayJacobian > jacobian
Definition: kinematic_tree.h:138
const typedef Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
Convenience wrapper for storing references to sub-matrices/vectors.
Definition: conversions.h:52
std::vector< tf::StampedTransform > debug_frames_
Definition: kinematic_tree.h:301
KinematicRequestFlags
Definition: kinematic_tree.h:56
std::vector< tf::StampedTransform > debug_tree_
Definition: kinematic_tree.h:300
bool debug
Definition: kinematic_tree.h:251
Eigen::VectorXd x
Definition: kinematic_tree.h:119
Eigen::Array< Eigen::Array< Eigen::MatrixXd, Eigen::Dynamic, 1 >, Eigen::Dynamic, 1 > ArrayHessian
Definition: conversions.h:155
constexpr double inf
Definition: kinematic_tree.h:70
std::vector< std::weak_ptr< KinematicElement > > controlled_joints_
Definition: kinematic_tree.h:290
std::vector< std::shared_ptr< KinematicElement > > environment_tree_
Definition: kinematic_tree.h:286
void ComputeJ(KinematicFrame &frame, KDL::Jacobian &jacobian) const
Eigen::VectorXd GetRandomControlledState()
Random state generation.
Eigen::VectorXd GetControlledState() const
int IsControlled(std::shared_ptr< KinematicElement > joint)
KinematicRequestFlags flags_
Definition: kinematic_tree.h:298
const Eigen::VectorXd & GetAccelerationLimits() const
Definition: kinematic_tree.h:165
const std::vector< std::string > & GetControlledLinkNames() const
Definition: kinematic_tree.h:176
Eigen::Map< ArrayHessian > hessian
Definition: kinematic_tree.h:139
std::map< std::string, std::weak_ptr< KinematicElement > > tree_map_
Definition: kinematic_tree.h:287
Eigen::VectorXd GetModelState() const
std::string root_joint_name_
Definition: kinematic_tree.h:283
void AddElementFromSegmentMapIterator(KDL::SegmentMap::const_iterator segment, std::shared_ptr< KinematicElement > parent)
@ KIN_FK_VEL
Definition: kinematic_tree.h:60
std::vector< std::string > controlled_joints_names_
Definition: kinematic_tree.h:294
KDL::Frame frame_A_offset
Definition: kinematic_tree.h:103
Definition: kinematic_tree.h:142
std::map< std::string, std::vector< double > > GetUsedJointLimits() const
std::weak_ptr< KinematicElement > frame_A
Definition: kinematic_tree.h:102
const std::vector< std::string > & GetControlledJointNames() const
Definition: kinematic_tree.h:171
const std::vector< std::shared_ptr< KinematicElement > > & GetModelTree() const
Definition: kinematic_tree.h:232
const Eigen::VectorXd & GetVelocityLimits() const
Definition: kinematic_tree.h:166
void SetJointVelocityLimits(Eigen::VectorXdRefConst velocity_in)
std::vector< std::string > GetKinematicChain(const std::string &begin, const std::string &end) const
GetKinematicChain get list of joints in a kinematic chain.
KDL::Frame temp_B
Definition: kinematic_tree.h:108
int length
Definition: kinematic_tree.h:134
std::weak_ptr< KinematicElement > frame_B
Definition: kinematic_tree.h:104
std::map< std::string, std::weak_ptr< KinematicElement > > collision_tree_map_
Definition: kinematic_tree.h:288
const bool & HasAccelerationLimits() const
Definition: kinematic_tree.h:164
void SetFloatingBaseLimitsPosXYZEulerZYX(const std::vector< double > &lower, const std::vector< double > &upper)
void Create(std::shared_ptr< KinematicResponse > solution)
std::vector< std::string > controlled_link_names_
Definition: kinematic_tree.h:296
BaseType controlled_base_type_
Definition: kinematic_tree.h:277
The KinematicResponse is the container to keep kinematic update data. The corresponding KinematicSolu...
Definition: kinematic_tree.h:113
KDL::Frame frame_A_offset
Definition: kinematic_tree.h:88
Definition: kinematic_tree.h:93
Eigen::Array< KDL::Jacobian, Eigen::Dynamic, 1 > ArrayJacobian
Definition: conversions.h:153
Eigen::Map< Eigen::VectorXd > X
Definition: kinematic_tree.h:135
ros::Publisher shapes_pub_
Definition: kinematic_tree.h:302
Eigen::VectorXd velocity_limits_
Definition: kinematic_tree.h:266
const std::vector< std::weak_ptr< KinematicElement > > & GetTree() const
Definition: kinematic_tree.h:231
KinematicRequestFlags operator|(KinematicRequestFlags a, KinematicRequestFlags b)
Definition: kinematic_tree.h:73
void SetSeed(const uint_fast32_t seed)
SetSeed sets the seed of the random generator for deterministic joint state sampling.
Definition: kinematic_tree.h:245
KinematicRequestFlags operator&(KinematicRequestFlags a, KinematicRequestFlags b)
Definition: kinematic_tree.h:78
void SetPlanarBaseLimitsPosXYEulerZ(const std::vector< double > &lower, const std::vector< double > &upper)
ros::Publisher octomap_pub_
Definition: kinematic_tree.h:303
@ FIXED
Definition: kinematic_tree.h:51
int start
Definition: kinematic_tree.h:133
std::vector< KinematicFrame > frame
Definition: kinematic_tree.h:118
@ LIMIT_POSITION_LOWER
Definition: kinematic_tree.h:66
Eigen::Array< KDL::Twist, Eigen::Dynamic, 1 > ArrayTwist
Definition: conversions.h:152
ArrayTwist Phi_dot
Definition: kinematic_tree.h:121
void SetModelState(Eigen::VectorXdRefConst x)
Eigen::VectorXd tree_state_
Definition: kinematic_tree.h:281
bool has_acceleration_limit_
Definition: kinematic_tree.h:268
JointLimitType
Definition: kinematic_tree.h:64
ArrayHessian hessian
Definition: kinematic_tree.h:123
std::vector< std::uniform_real_distribution< double > > random_state_distributions_
Definition: kinematic_tree.h:274
int GetNumModelJoints() const
void Instantiate(const std::string &joint_group, robot_model::RobotModelPtr model, const std::string &name)
const std::string & GetRootJointName() const
void PublishFrames(const std::string &tf_prefix="exotica")
const std::vector< std::weak_ptr< KinematicElement > > & GetControlledJoints() const
Definition: kinematic_tree.h:238
KDL::Frame FK(KinematicFrame &frame) const
void SetJointLimitsUpper(Eigen::VectorXdRefConst upper_in)
Eigen::VectorXd GetControlledLinkMass() const
std::vector< std::weak_ptr< KinematicElement > > tree_
Definition: kinematic_tree.h:284
std::shared_ptr< KinematicElement > root_
Definition: kinematic_tree.h:289
std::string frame_B_link_name
Definition: kinematic_tree.h:89
robot_model::RobotModelPtr model_
Definition: kinematic_tree.h:282
Eigen::Array< KDL::Frame, Eigen::Dynamic, 1 > ArrayFrame
Definition: conversions.h:151
The KinematicSolution is created from - and maps into - a KinematicResponse.
Definition: kinematic_tree.h:127
Eigen::MatrixXd joint_limits_
Definition: kinematic_tree.h:265
std::map< std::string, shapes::ShapeType > GetCollisionObjectTypes() const