ofkt_state_solver.h
Go to the documentation of this file.
1 
31 #ifndef TESSERACT_STATE_SOLVER_OFKT_STATE_SOLVER_H
32 #define TESSERACT_STATE_SOLVER_OFKT_STATE_SOLVER_H
33 
36 #include <Eigen/Geometry>
37 #include <memory>
38 #include <string>
39 #include <shared_mutex>
41 
46 
47 namespace tesseract_scene_graph
48 {
57 {
58 public:
59  // LCOV_EXCL_START
60  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
61  // LCOV_EXCL_STOP
62 
63  using Ptr = std::shared_ptr<OFKTStateSolver>;
64  using ConstPtr = std::shared_ptr<const OFKTStateSolver>;
65  using UPtr = std::unique_ptr<OFKTStateSolver>;
66  using ConstUPtr = std::unique_ptr<const OFKTStateSolver>;
67 
68  OFKTStateSolver(const tesseract_scene_graph::SceneGraph& scene_graph, const std::string& prefix = "");
69  OFKTStateSolver(const std::string& root_name);
70  ~OFKTStateSolver() override = default;
71  OFKTStateSolver(const OFKTStateSolver& other);
73  OFKTStateSolver(OFKTStateSolver&&) = delete;
75 
76  void setRevision(int revision) override final;
77 
78  int getRevision() const override final;
79 
80  void setState(const Eigen::Ref<const Eigen::VectorXd>& joint_values,
81  const tesseract_common::TransformMap& floating_joint_values = {}) override final;
82  void setState(const std::unordered_map<std::string, double>& joint_values,
83  const tesseract_common::TransformMap& floating_joint_values = {}) override final;
84  void setState(const std::vector<std::string>& joint_names,
85  const Eigen::Ref<const Eigen::VectorXd>& joint_values,
86  const tesseract_common::TransformMap& floating_joint_values = {}) override final;
87  void setState(const tesseract_common::TransformMap& floating_joint_values) override final;
88 
89  SceneState getState(const Eigen::Ref<const Eigen::VectorXd>& joint_values,
90  const tesseract_common::TransformMap& floating_joint_values = {}) const override final;
91  SceneState getState(const std::unordered_map<std::string, double>& joint_values,
92  const tesseract_common::TransformMap& floating_joint_values = {}) const override final;
93  SceneState getState(const std::vector<std::string>& joint_names,
94  const Eigen::Ref<const Eigen::VectorXd>& joint_values,
95  const tesseract_common::TransformMap& floating_joint_values = {}) const override final;
96  SceneState getState(const tesseract_common::TransformMap& floating_joint_values) const override final;
97 
98  SceneState getState() const override final;
99 
100  SceneState getRandomState() const override final;
101 
102  Eigen::MatrixXd getJacobian(const Eigen::Ref<const Eigen::VectorXd>& joint_values,
103  const std::string& link_name,
104  const tesseract_common::TransformMap& floating_joint_values = {}) const override final;
105 
106  Eigen::MatrixXd getJacobian(const std::unordered_map<std::string, double>& joints_values,
107  const std::string& link_name,
108  const tesseract_common::TransformMap& floating_joint_values = {}) const override final;
109  Eigen::MatrixXd getJacobian(const std::vector<std::string>& joint_names,
110  const Eigen::Ref<const Eigen::VectorXd>& joint_values,
111  const std::string& link_name,
112  const tesseract_common::TransformMap& floating_joint_values = {}) const override final;
113 
114  std::vector<std::string> getJointNames() const override final;
115 
116  std::vector<std::string> getFloatingJointNames() const override final;
117 
118  std::vector<std::string> getActiveJointNames() const override final;
119 
120  std::string getBaseLinkName() const override final;
121 
122  std::vector<std::string> getLinkNames() const override final;
123 
124  std::vector<std::string> getActiveLinkNames() const override final;
125 
126  std::vector<std::string> getStaticLinkNames() const override final;
127 
128  bool isActiveLinkName(const std::string& link_name) const override final;
129 
130  bool hasLinkName(const std::string& link_name) const override final;
131 
132  tesseract_common::VectorIsometry3d getLinkTransforms() const override final;
133 
134  Eigen::Isometry3d getLinkTransform(const std::string& link_name) const override final;
135 
136  Eigen::Isometry3d getRelativeLinkTransform(const std::string& from_link_name,
137  const std::string& to_link_name) const override final;
138 
139  tesseract_common::KinematicLimits getLimits() const override final;
140 
141  bool addLink(const Link& link, const Joint& joint) override final;
142 
143  bool moveLink(const Joint& joint) override final;
144 
145  bool removeLink(const std::string& name) override final;
146 
147  bool replaceJoint(const Joint& joint) override final;
148 
149  bool removeJoint(const std::string& name) override final;
150 
151  bool moveJoint(const std::string& name, const std::string& parent_link) override final;
152 
153  bool changeJointOrigin(const std::string& name, const Eigen::Isometry3d& new_origin) override final;
154 
155  bool changeJointPositionLimits(const std::string& name, double lower, double upper) override final;
156 
157  bool changeJointVelocityLimits(const std::string& name, double limit) override final;
158 
159  bool changeJointAccelerationLimits(const std::string& name, double limit) override final;
160 
161  bool changeJointJerkLimits(const std::string& name, double limit) override final;
162 
163  bool insertSceneGraph(const SceneGraph& scene_graph,
164  const Joint& joint,
165  const std::string& prefix = "") override final;
166 
167  StateSolver::UPtr clone() const override final;
168 
169 private:
171  std::vector<std::string> joint_names_;
172  std::vector<std::string> active_joint_names_;
173  std::vector<std::string> floating_joint_names_;
174  std::vector<std::string> link_names_;
175  std::unordered_map<std::string, std::unique_ptr<OFKTNode>> nodes_;
176  std::unordered_map<std::string, OFKTNode*> link_map_;
177  tesseract_common::KinematicLimits limits_;
178  std::unique_ptr<OFKTNode> root_;
179  int revision_{ 0 };
182  mutable std::shared_mutex mutex_;
183 
184  bool initHelper(const tesseract_scene_graph::SceneGraph& scene_graph, const std::string& prefix);
185 
186  void clear();
187 
189  void loadActiveLinkNamesRecursive(std::vector<std::string>& active_link_names,
190  const OFKTNode* node,
191  bool active) const;
192 
194  void loadStaticLinkNamesRecursive(std::vector<std::string>& static_link_names, const OFKTNode* node) const;
195 
201  void update(OFKTNode* node, bool update_required);
202 
209  void
210  update(SceneState& state, const OFKTNode* node, const Eigen::Isometry3d& parent_world_tf, bool update_required) const;
211 
219  Eigen::MatrixXd calcJacobianHelper(const std::unordered_map<std::string, double>& joints,
220  const std::string& link_name,
221  const tesseract_common::TransformMap& floating_joint_values = {}) const;
222 
228  void cloneHelper(OFKTStateSolver& cloned, const OFKTNode* node) const;
229 
242  void addNode(const Joint& joint,
243  const std::string& joint_name,
244  const std::string& parent_link_name,
245  const std::string& child_link_name,
246  std::vector<std::shared_ptr<const JointLimits>>& new_joint_limits);
247 
256  void removeNode(OFKTNode* node,
257  std::vector<std::string>& removed_links,
258  std::vector<std::string>& removed_joints,
259  std::vector<std::string>& removed_active_joints,
260  std::vector<long>& removed_active_joints_indices);
261 
267  void moveLinkHelper(std::vector<std::shared_ptr<const JointLimits>>& new_joint_limits, const Joint& joint);
268 
274  void replaceJointHelper(std::vector<std::shared_ptr<const JointLimits>>& new_joint_limits, const Joint& joint);
275 
283  void removeJointHelper(const std::vector<std::string>& removed_links,
284  const std::vector<std::string>& removed_joints,
285  const std::vector<std::string>& removed_active_joints,
286  const std::vector<long>& removed_active_joints_indices);
287 
292  void addNewJointLimits(const std::vector<std::shared_ptr<const JointLimits>>& new_joint_limits);
293  friend struct ofkt_builder;
294 };
295 
296 } // namespace tesseract_scene_graph
297 
298 #endif // TESSERACT_STATE_SOLVER_OFKT_STATE_SOLVER_H
tesseract_scene_graph::OFKTStateSolver::changeJointOrigin
bool changeJointOrigin(const std::string &name, const Eigen::Isometry3d &new_origin) override final
Changes the "origin" transform of the joint and recomputes the associated edge.
Definition: ofkt_state_solver.cpp:718
VectorIsometry3d
AlignedVector< Eigen::Isometry3d > VectorIsometry3d
tesseract_common
tesseract_scene_graph::OFKTStateSolver::getActiveLinkNames
std::vector< std::string > getActiveLinkNames() const override final
Get the vector of active link names.
Definition: ofkt_state_solver.cpp:480
tesseract_scene_graph::OFKTStateSolver::joint_names_
std::vector< std::string > joint_names_
Definition: ofkt_state_solver.h:171
tesseract_scene_graph::OFKTStateSolver::getJointNames
std::vector< std::string > getJointNames() const override final
Get the vector of joint names.
Definition: ofkt_state_solver.cpp:450
tesseract_scene_graph::OFKTStateSolver::revision_
int revision_
Definition: ofkt_state_solver.h:179
mutable_state_solver.h
Tesseract Scene Graph Mutable State Solver Interface .
tesseract_scene_graph::OFKTStateSolver::update
void update(OFKTNode *node, bool update_required)
This update the local and world transforms.
Definition: ofkt_state_solver.cpp:903
tesseract_scene_graph::OFKTStateSolver::hasLinkName
bool hasLinkName(const std::string &link_name) const override final
Check if link name exists.
Definition: ofkt_state_solver.cpp:505
tesseract_scene_graph::OFKTStateSolver::getLimits
tesseract_common::KinematicLimits getLimits() const override final
Getter for kinematic limits.
Definition: ofkt_state_solver.cpp:532
tesseract_scene_graph::OFKTStateSolver::getActiveJointNames
std::vector< std::string > getActiveJointNames() const override final
Get the vector of joint names which align with the limits.
Definition: ofkt_state_solver.cpp:462
TransformMap
AlignedMap< std::string, Eigen::Isometry3d > TransformMap
tesseract_scene_graph::MutableStateSolver::ConstUPtr
std::unique_ptr< const MutableStateSolver > ConstUPtr
Definition: mutable_state_solver.h:42
tesseract_scene_graph::OFKTStateSolver::current_state_
SceneState current_state_
Definition: ofkt_state_solver.h:170
tesseract_scene_graph::OFKTStateSolver::removeLink
bool removeLink(const std::string &name) override final
Removes a link from the graph.
Definition: ofkt_state_solver.cpp:625
tesseract_scene_graph::OFKTStateSolver::insertSceneGraph
bool insertSceneGraph(const SceneGraph &scene_graph, const Joint &joint, const std::string &prefix="") override final
Merge a scene into the current solver.
Definition: ofkt_state_solver.cpp:809
tesseract_scene_graph::OFKTStateSolver::setState
void setState(const Eigen::Ref< const Eigen::VectorXd > &joint_values, const tesseract_common::TransformMap &floating_joint_values={}) override final
Set the current state of the solver.
Definition: ofkt_state_solver.cpp:218
tesseract_scene_graph::OFKTStateSolver::link_map_
std::unordered_map< std::string, OFKTNode * > link_map_
Definition: ofkt_state_solver.h:176
kinematic_limits.h
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
tesseract_scene_graph::OFKTStateSolver::~OFKTStateSolver
~OFKTStateSolver() override=default
tesseract_scene_graph::SceneGraph
tesseract_scene_graph::OFKTStateSolver::root_
std::unique_ptr< OFKTNode > root_
Definition: ofkt_state_solver.h:178
tesseract_scene_graph::OFKTStateSolver::operator=
OFKTStateSolver & operator=(const OFKTStateSolver &other)
Definition: ofkt_state_solver.cpp:170
tesseract_scene_graph::OFKTStateSolver::removeJoint
bool removeJoint(const std::string &name) override final
Removes a joint from the graph.
Definition: ofkt_state_solver.cpp:657
tesseract_scene_graph::StateSolver::StateSolver
StateSolver()=default
tesseract_scene_graph::OFKTStateSolver::changeJointJerkLimits
bool changeJointJerkLimits(const std::string &name, double limit) override final
Changes the jerk limits associated with a joint.
Definition: ofkt_state_solver.cpp:791
tesseract_scene_graph::OFKTStateSolver::initHelper
bool initHelper(const tesseract_scene_graph::SceneGraph &scene_graph, const std::string &prefix)
Definition: ofkt_state_solver.cpp:966
tesseract_scene_graph::SceneState
tesseract_scene_graph::OFKTStateSolver::clear
void clear()
Definition: ofkt_state_solver.cpp:203
tesseract_scene_graph::MutableStateSolver
A mutable state solver allows you to reconfigure the solver's links and joints.
Definition: mutable_state_solver.h:36
tesseract_scene_graph::OFKTStateSolver::getLinkNames
std::vector< std::string > getLinkNames() const override final
Get the vector of link names.
Definition: ofkt_state_solver.cpp:474
tesseract_scene_graph::OFKTStateSolver::UPtr
std::unique_ptr< OFKTStateSolver > UPtr
Definition: ofkt_state_solver.h:65
tesseract_scene_graph::OFKTStateSolver::removeNode
void removeNode(OFKTNode *node, std::vector< std::string > &removed_links, std::vector< std::string > &removed_joints, std::vector< std::string > &removed_active_joints, std::vector< long > &removed_active_joints_indices)
Remove a node and all of its children.
Definition: ofkt_state_solver.cpp:1249
tesseract_scene_graph::OFKTStateSolver::moveLinkHelper
void moveLinkHelper(std::vector< std::shared_ptr< const JointLimits >> &new_joint_limits, const Joint &joint)
This a helper function for moving a link.
Definition: ofkt_state_solver.cpp:1008
tesseract_scene_graph::OFKTStateSolver::mutex_
std::shared_mutex mutex_
The state solver can be accessed from multiple threads, need use mutex throughout.
Definition: ofkt_state_solver.h:182
tesseract_scene_graph::MutableStateSolver::UPtr
std::unique_ptr< MutableStateSolver > UPtr
Definition: mutable_state_solver.h:41
tesseract_scene_graph::OFKTStateSolver::changeJointAccelerationLimits
bool changeJointAccelerationLimits(const std::string &name, double limit) override final
Changes the acceleration limits associated with a joint.
Definition: ofkt_state_solver.cpp:773
tesseract_scene_graph::OFKTStateSolver::calcJacobianHelper
Eigen::MatrixXd calcJacobianHelper(const std::unordered_map< std::string, double > &joints, const std::string &link_name, const tesseract_common::TransformMap &floating_joint_values={}) const
Given a set of joint values calculate the jacobian for the provided link_name.
Definition: ofkt_state_solver.cpp:411
tesseract_scene_graph::OFKTStateSolver::addNewJointLimits
void addNewJointLimits(const std::vector< std::shared_ptr< const JointLimits >> &new_joint_limits)
appends the new joint limits
Definition: ofkt_state_solver.cpp:1281
tesseract_scene_graph::OFKTStateSolver::getRandomState
SceneState getRandomState() const override final
Get the random state of the environment.
Definition: ofkt_state_solver.cpp:356
tesseract_scene_graph::OFKTNode
The OFKT node is contains multiple trasformation which are described below.
Definition: ofkt_node.h:55
tesseract_scene_graph::OFKTStateSolver::addLink
bool addLink(const Link &link, const Joint &joint) override final
Adds a link/joint to the solver.
Definition: ofkt_state_solver.cpp:538
tesseract_scene_graph::OFKTStateSolver::getStaticLinkNames
std::vector< std::string > getStaticLinkNames() const override final
Get a vector of static link names in the environment.
Definition: ofkt_state_solver.cpp:489
tesseract_scene_graph::OFKTStateSolver::getBaseLinkName
std::string getBaseLinkName() const override final
Get the base link name.
Definition: ofkt_state_solver.cpp:468
tesseract_scene_graph::OFKTStateSolver
An implementation of the Optimized Forward Kinematic Tree as a stat solver.
Definition: ofkt_state_solver.h:56
tesseract_scene_graph::OFKTStateSolver::cloneHelper
void cloneHelper(OFKTStateSolver &cloned, const OFKTNode *node) const
A helper function used for cloning the OFKTStateSolver.
Definition: ofkt_state_solver.cpp:83
tesseract_scene_graph::OFKTStateSolver::limits_
tesseract_common::KinematicLimits limits_
Definition: ofkt_state_solver.h:177
tesseract_scene_graph::OFKTStateSolver::changeJointVelocityLimits
bool changeJointVelocityLimits(const std::string &name, double limit) override final
Changes the velocity limits associated with a joint.
Definition: ofkt_state_solver.cpp:755
tesseract_scene_graph::OFKTStateSolver::isActiveLinkName
bool isActiveLinkName(const std::string &link_name) const override final
Check if link is an active link.
Definition: ofkt_state_solver.cpp:498
tesseract_scene_graph::ofkt_builder
Every time a vertex is visited for the first time add a new node to the tree.
Definition: ofkt_state_solver.cpp:51
tesseract_scene_graph::MutableStateSolver::ConstPtr
std::shared_ptr< const MutableStateSolver > ConstPtr
Definition: mutable_state_solver.h:40
tesseract_scene_graph::OFKTStateSolver::addNode
void addNode(const Joint &joint, const std::string &joint_name, const std::string &parent_link_name, const std::string &child_link_name, std::vector< std::shared_ptr< const JointLimits >> &new_joint_limits)
Add a node to the tree.
Definition: ofkt_state_solver.cpp:1146
tesseract_scene_graph::Joint
tesseract_scene_graph::OFKTStateSolver::moveLink
bool moveLink(const Joint &joint) override final
Move a link.
Definition: ofkt_state_solver.cpp:599
tesseract_scene_graph::OFKTStateSolver::nodes_
std::unordered_map< std::string, std::unique_ptr< OFKTNode > > nodes_
Definition: ofkt_state_solver.h:175
tesseract_scene_graph::OFKTStateSolver::changeJointPositionLimits
bool changeJointPositionLimits(const std::string &name, double lower, double upper) override final
Changes the position limits associated with a joint.
Definition: ofkt_state_solver.cpp:737
tesseract_scene_graph::OFKTStateSolver::active_joint_names_
std::vector< std::string > active_joint_names_
Definition: ofkt_state_solver.h:172
TESSERACT_COMMON_IGNORE_WARNINGS_POP
#define TESSERACT_COMMON_IGNORE_WARNINGS_POP
scene_state.h
tesseract_scene_graph::OFKTStateSolver::getJacobian
Eigen::MatrixXd getJacobian(const Eigen::Ref< const Eigen::VectorXd > &joint_values, const std::string &link_name, const tesseract_common::TransformMap &floating_joint_values={}) const override final
Get the jacobian of the solver given the joint values.
Definition: ofkt_state_solver.cpp:362
tesseract_scene_graph::OFKTStateSolver::getRevision
int getRevision() const override final
Get the state solver revision number.
Definition: ofkt_state_solver.cpp:197
tesseract_scene_graph::OFKTStateSolver::loadStaticLinkNamesRecursive
void loadStaticLinkNamesRecursive(std::vector< std::string > &static_link_names, const OFKTNode *node) const
load the static link names
Definition: ofkt_state_solver.cpp:891
tesseract_scene_graph::OFKTStateSolver::link_names_
std::vector< std::string > link_names_
Definition: ofkt_state_solver.h:174
tesseract_scene_graph::OFKTStateSolver::OFKTStateSolver
OFKTStateSolver(const tesseract_scene_graph::SceneGraph &scene_graph, const std::string &prefix="")
Definition: ofkt_state_solver.cpp:155
tesseract_scene_graph::OFKTStateSolver::floating_joint_names_
std::vector< std::string > floating_joint_names_
Definition: ofkt_state_solver.h:173
tesseract_scene_graph::OFKTStateSolver::moveJoint
bool moveJoint(const std::string &name, const std::string &parent_link) override final
Move joint to new parent link.
Definition: ofkt_state_solver.cpp:689
ofkt_node.h
A implementation of the Optimized Forward Kinematic Tree Node.
tesseract_scene_graph::MutableStateSolver::Ptr
std::shared_ptr< MutableStateSolver > Ptr
Definition: mutable_state_solver.h:39
tesseract_scene_graph::OFKTStateSolver::replaceJoint
bool replaceJoint(const Joint &joint) override final
Replace and existing joint with the provided one.
Definition: ofkt_state_solver.cpp:565
macros.h
tesseract_scene_graph::OFKTStateSolver::getLinkTransforms
tesseract_common::VectorIsometry3d getLinkTransforms() const override final
Get all of the links transforms.
Definition: ofkt_state_solver.cpp:511
tesseract_scene_graph::OFKTStateSolver::setRevision
void setRevision(int revision) override final
Set the state solver revision number.
Definition: ofkt_state_solver.cpp:191
tesseract_scene_graph::OFKTStateSolver::loadActiveLinkNamesRecursive
void loadActiveLinkNamesRecursive(std::vector< std::string > &active_link_names, const OFKTNode *node, bool active) const
load the active link names
Definition: ofkt_state_solver.cpp:864
tesseract_scene_graph
tesseract_scene_graph::OFKTStateSolver::removeJointHelper
void removeJointHelper(const std::vector< std::string > &removed_links, const std::vector< std::string > &removed_joints, const std::vector< std::string > &removed_active_joints, const std::vector< long > &removed_active_joints_indices)
This will clean up member variables joint_names_ and limits_.
Definition: ofkt_state_solver.cpp:1075
tesseract_scene_graph::OFKTStateSolver::getRelativeLinkTransform
Eigen::Isometry3d getRelativeLinkTransform(const std::string &from_link_name, const std::string &to_link_name) const override final
Get transform between two links using the current state.
Definition: ofkt_state_solver.cpp:526
tesseract_scene_graph::OFKTStateSolver::getFloatingJointNames
std::vector< std::string > getFloatingJointNames() const override final
Get the vector of floating joint names.
Definition: ofkt_state_solver.cpp:456
tesseract_scene_graph::OFKTStateSolver::clone
StateSolver::UPtr clone() const override final
This should clone the object so it may be used in a multi threaded application where each thread woul...
Definition: ofkt_state_solver.cpp:185
tesseract_scene_graph::OFKTStateSolver::getState
SceneState getState() const override final
Get the current state of the scene.
Definition: ofkt_state_solver.cpp:350
tesseract_scene_graph::OFKTStateSolver::replaceJointHelper
void replaceJointHelper(std::vector< std::shared_ptr< const JointLimits >> &new_joint_limits, const Joint &joint)
This is a helper function for replacing a joint.
Definition: ofkt_state_solver.cpp:1053
tesseract_scene_graph::OFKTStateSolver::getLinkTransform
Eigen::Isometry3d getLinkTransform(const std::string &link_name) const override final
Get the transform corresponding to the link.
Definition: ofkt_state_solver.cpp:521


tesseract_state_solver
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:02:10