30 #ifndef EXOTICA_CORE_KINEMATIC_TREE_H_ 31 #define EXOTICA_CORE_KINEMATIC_TREE_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();
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};
137 Eigen::Map<ArrayTwist> Phi_dot{
nullptr, 0};
138 Eigen::Map<ArrayJacobian> jacobian{
nullptr, 0};
139 Eigen::Map<ArrayHessian> hessian{
nullptr, 0};
145 void Instantiate(
const std::string& joint_group, robot_model::RobotModelPtr model,
const std::string& name);
146 const std::string& GetRootFrameName()
const;
147 const std::string& GetRootJointName()
const;
148 robot_model::RobotModelPtr GetRobotModel()
const;
150 BaseType GetControlledBaseType()
const;
151 std::shared_ptr<KinematicResponse> RequestFrames(
const KinematicsRequest& request);
153 void ResetJointLimits();
159 void SetFloatingBaseLimitsPosXYZEulerZYX(
const std::vector<double>& lower,
const std::vector<double>& upper);
160 void SetFloatingBaseLimitsPosXYZEulerZYX(
const std::vector<double>& lower,
const std::vector<double>& upper,
const std::vector<double>& velocity,
const std::vector<double>& acceleration);
161 void SetPlanarBaseLimitsPosXYEulerZ(
const std::vector<double>& lower,
const std::vector<double>& upper);
162 void SetPlanarBaseLimitsPosXYEulerZ(
const std::vector<double>& lower,
const std::vector<double>& upper,
const std::vector<double>& velocity,
const std::vector<double>& acceleration);
163 std::map<std::string, std::vector<double>> GetUsedJointLimits()
const;
167 int GetNumControlledJoints()
const;
168 int GetNumModelJoints()
const;
169 void PublishFrames(
const std::string& tf_prefix =
"exotica");
173 return controlled_joints_names_;
178 return controlled_link_names_;
183 return model_joints_names_;
188 return model_link_names_;
191 bool HasModelLink(
const std::string& link)
const;
193 Eigen::VectorXd GetControlledLinkMass()
const;
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;
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;
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);
210 int IsControlledLink(
const std::string& link_name);
212 Eigen::VectorXd GetModelState()
const;
213 std::map<std::string, double> GetModelStateMap()
const;
219 std::vector<std::string> GetKinematicChain(
const std::string& begin,
const std::string& end)
const;
225 std::vector<std::string> GetKinematicChainLinks(
const std::string& begin,
const std::string& end)
const;
228 void SetModelState(
const std::map<std::string, double>& x);
229 Eigen::VectorXd GetControlledState()
const;
231 const std::vector<std::weak_ptr<KinematicElement>>&
GetTree()
const {
return tree_; }
232 const std::vector<std::shared_ptr<KinematicElement>>&
GetModelTree()
const {
return model_tree_; }
233 const std::map<std::string, std::weak_ptr<KinematicElement>>&
GetTreeMap()
const {
return tree_map_; }
234 const std::map<std::string, std::weak_ptr<KinematicElement>>&
GetCollisionTreeMap()
const {
return collision_tree_map_; }
235 bool DoesLinkWithNameExist(std::string name)
const;
236 std::shared_ptr<KinematicElement> FindKinematicElementByName(
const std::string& frame_name);
238 const std::vector<std::weak_ptr<KinematicElement>>&
GetControlledJoints()
const {
return controlled_joints_; }
239 const std::map<std::string, std::weak_ptr<KinematicElement>>&
GetControlledJointsMap()
const {
return controlled_joints_map_; }
240 const std::map<std::string, std::weak_ptr<KinematicElement>>&
GetModelJointsMap()
const {
return model_joints_map_; }
241 std::map<std::string, shapes::ShapeType> GetCollisionObjectTypes()
const;
245 void SetSeed(
const uint_fast32_t seed) { generator_.seed(seed); }
247 Eigen::VectorXd GetRandomControlledState();
254 void BuildTree(
const KDL::Tree& RobotKinematics);
255 void AddElementFromSegmentMapIterator(KDL::SegmentMap::const_iterator segment, std::shared_ptr<KinematicElement> parent);
268 bool has_acceleration_limit_ =
false;
269 void UpdateJointLimits();
280 int state_size_ = -1;
283 std::string root_joint_name_ =
"";
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_ visualization_msgs::MarkerArray marker_array_msg_
const Eigen::VectorXd & GetAccelerationLimits() const
const std::vector< std::weak_ptr< KinematicElement > > & GetControlledJoints() const
std::vector< std::shared_ptr< KinematicElement > > environment_tree_
Eigen::Array< KDL::Twist, Eigen::Dynamic, 1 > ArrayTwist
std::vector< KinematicFrameRequest > frames
robot_model::RobotModelPtr model_
std::map< std::string, std::weak_ptr< KinematicElement > > tree_map_
const std::vector< std::string > & GetControlledLinkNames() const
std::weak_ptr< KinematicElement > frame_B
std::map< std::string, std::weak_ptr< KinematicElement > > collision_tree_map_
KDL::Frame frame_A_offset
std::string frame_A_link_name
const Eigen::MatrixXd & GetJointLimits() const
std::vector< std::string > controlled_joints_names_
const std::map< std::string, std::weak_ptr< KinematicElement > > & GetControlledJointsMap() const
std::vector< std::string > model_joints_names_
std::vector< std::shared_ptr< KinematicElement > > model_tree_
ros::Publisher octomap_pub_
const std::map< std::string, std::weak_ptr< KinematicElement > > & GetModelJointsMap() const
void SetSeed(const uint_fast32_t seed)
SetSeed sets the seed of the random generator for deterministic joint state sampling.
std::vector< std::uniform_real_distribution< double > > random_state_distributions_
const std::vector< std::string > & GetModelLinkNames() const
std::weak_ptr< KinematicElement > frame_A
const bool & HasAccelerationLimits() const
std::map< std::string, std::weak_ptr< KinematicElement > > controlled_joints_map_
void SetKinematicResponse(std::shared_ptr< KinematicResponse > response_in)
const std::vector< std::weak_ptr< KinematicElement > > & GetTree() const
const std::map< std::string, std::weak_ptr< KinematicElement > > & GetTreeMap() const
const Eigen::VectorXd & GetVelocityLimits() const
KinematicRequestFlags flags_
std::shared_ptr< KinematicElement > root_
std::map< std::string, std::weak_ptr< KinematicElement > > model_joints_map_
Eigen::Array< Eigen::MatrixXd, Eigen::Dynamic, 1 > Hessian
The KinematicSolution is created from - and maps into - a KinematicResponse.
const std::map< std::string, std::weak_ptr< KinematicElement > > & GetCollisionTreeMap() const
KDL::Frame frame_A_offset
const std::vector< std::string > & GetModelJointNames() const
Eigen::MatrixXd joint_limits_
Eigen::Array< Eigen::Array< Eigen::MatrixXd, Eigen::Dynamic, 1 >, Eigen::Dynamic, 1 > ArrayHessian
const std::vector< std::shared_ptr< KinematicElement > > & GetModelTree() const
Eigen::VectorXd acceleration_limits_
std::vector< std::weak_ptr< KinematicElement > > controlled_joints_
std::shared_ptr< KinematicResponse > GetKinematicResponse()
static RigidBodyInertia Zero()
const Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
Convenience wrapper for storing references to sub-matrices/vectors.
KDL::Frame frame_B_offset
std::vector< std::string > controlled_link_names_
KDL::Frame frame_B_offset
const std::vector< std::string > & GetControlledJointNames() const
Eigen::Array< KDL::Jacobian, Eigen::Dynamic, 1 > ArrayJacobian
std::vector< KinematicFrame > frame
Eigen::VectorXd velocity_limits_
std::string frame_B_link_name
KinematicRequestFlags operator&(KinematicRequestFlags a, KinematicRequestFlags b)
KinematicRequestFlags operator|(KinematicRequestFlags a, KinematicRequestFlags b)
Eigen::VectorXd tree_state_
bool debug_scene_changed_
The KinematicResponse is the container to keep kinematic update data. The corresponding KinematicSolu...
int num_joints_
Number of joints of the model (including floating/planar base, passive joints, and uncontrolled joint...
BaseType model_base_type_
std::vector< std::weak_ptr< KinematicElement > > tree_
ros::Publisher shapes_pub_
Eigen::Array< KDL::Frame, Eigen::Dynamic, 1 > ArrayFrame
std::vector< tf::StampedTransform > debug_frames_
std::vector< tf::StampedTransform > debug_tree_
int num_controlled_joints_
Number of controlled joints in the joint group.
std::vector< std::string > model_link_names_
std::shared_ptr< const Shape > ShapeConstPtr