Robowflex  v0.1
Making MoveIt Easy
robowflex_dart/include/robowflex_dart/robot.h
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
3 #ifndef ROBOWFLEX_DART_ROBOT_
4 #define ROBOWFLEX_DART_ROBOT_
5 
6 #include <moveit/robot_state/conversions.h>
7 #include <moveit/robot_state/robot_state.h>
8 
9 #include <dart/dynamics/Skeleton.hpp>
10 #include <dart/collision/CollisionFilter.hpp>
11 #include <dart/simulation/World.hpp>
12 
14 
15 #include <robowflex_dart/io.h>
17 
18 namespace robowflex
19 {
20  /** \cond IGNORE */
23  /** \endcond */
24 
25  namespace darts
26  {
27  /** \cond IGNORE */
29  /** \endcond */
30 
31  /** \class robowflex::darts::TSRGoalPtr
32  \brief A shared pointer wrapper for robowflex::darts::TSRGoal. */
33 
34  /** \class robowflex::darts::TSRGoalConstPtr
35  \brief A const shared pointer wrapper for robowflex::darts::TSRGoal. */
36 
37  /** \brief A sampleable goal region for OMPL for a set of TSRs.
38  * Samples goals in a separate thread using a clone of the world.
39  */
40  class Robot : public Structure
41  {
42  public:
43  /** \brief A map of group name to member joints.
44  */
46 
47  /** \brief A map of group name to a map of state name to configurations.
48  */
50 
51  /** \name Constructors
52  \{ */
53 
54  /** \brief Construct an empty robot.
55  * \param[in] name Name of the robot.
56  */
57  Robot(const std::string &name);
58 
59  /** \brief Convert a robowflex::Robot into a Dart robot.
60  * \param[in] robot Robot to convert.
61  */
63 
64  /** \brief Convert a robowflex::Scene into a Dart robot.
65  * \param[in] name Name of the robot.
66  * \param[in] scene Scene to convert.
67  */
68  Robot(const std::string &name, const ScenePtr &scene);
69 
70  /** \brief Clone this robot with a new name.
71  * \param[in] newName Name for cloned robot.
72  * \return Cloned robot.
73  */
74  RobotPtr cloneRobot(const std::string &newName) const;
75 
76  /** \} */
77 
78  /** \name File Loading
79  \{ */
80 
81  /** \brief Load a URDF into this robot.
82  * \param[in] urdf URDF filename to load. Can be package URI.
83  * \return True on success, false on failure.
84  */
85  bool loadURDF(const std::string &urdf);
86 
87  /** \brief Load a SRDF into this robot.
88  * \param[in] srdf SRDF filename to load. Can be package URI.
89  * \return True on success, false on failure.
90  */
91  bool loadSRDF(const std::string &srdf);
92 
93  /** \} */
94 
95  /** \name State Operations
96  \{ */
97 
98  /** \brief Set the current state of this robot from a MoveIt message.
99  * \param[in] msg Message to set state to.
100  */
101  void setStateFromMoveItMsg(const moveit_msgs::RobotState &msg);
102 
103  /** \brief Set a MoveIt message from the current state of this robot.
104  * \param[out] msg Message to set.
105  */
106  void setMoveItMsgFromState(moveit_msgs::RobotState &msg) const;
107 
108  /** \brief Set the current state of this robot from a MoveIt robot state.
109  * \param[in] state MoveIt state to set state to.
110  */
111  void setStateFromMoveItState(const robot_state::RobotState &state);
112 
113  /** \brief Set a MoveIt robot state from the current state of this robot.
114  * \param[out] state MoveIt state to set state to.
115  */
116  void setMoveItStateFromState(robot_state::RobotState &state) const;
117 
118  /** \brief Set the state using a MoveIt Joint Group.
119  * \param[in] jmg Name of joint group.
120  * \param[in] joints Value of Joint Group to set.
121  */
122  void setStateFromMoveItJMG(const std::string &jmg, const std::vector<double> &joints);
123 
124  /** \brief Set the state using a MoveIt Joint Group.
125  * \param[in] jmg Name of joint group.
126  * \param[in] vec Value of Joint Group to set.
127  */
128  void setStateFromMoveItJMG(const std::string &jmg, const Eigen::Ref<const Eigen::VectorXd> &vec);
129 
130  /** \brief Set a MoveIt Joint Group state from the current state of the robot.
131  * \param[in] jmg Name of joint group.
132  * \param[out] joints Joint values to set.
133  */
134  void setMoveItJMGFromState(const std::string &jmg, std::vector<double> &joints) const;
135 
136  /** \brief Set a MoveIt Joint Group state from the current state of the robot.
137  * \param[in] jmg Name of joint group.
138  * \param[out] vec Joint values to set.
139  */
140  void setMoveItJMGFromState(const std::string &jmg, Eigen::Ref<Eigen::VectorXd> vec) const;
141 
142  /** \} */
143 
144  /** \name Group Operations
145  \{ */
146 
147  /** \brief Get the groups currently in the robot. A map of group name to a list of all joints in
148  * the group. \return The groups in the robot.
149  */
150  void setGroups(const GroupsMap &newGroups);
151 
152  /** \brief Get the groups currently in the robot. A map of group name to a list of all joints in
153  * the group. \return The groups in the robot.
154  */
155  const GroupsMap &getGroups() const;
156 
157  /** \brief Get the joint names in a group.
158  * \param[in] group Group to get joint names for.
159  * \return The list of joint names.
160  */
161  std::vector<std::string> &getGroupJointNames(const std::string &group);
162 
163  /** \brief Get the joint names in a group.
164  * \param[in] group Group to get joint names for.
165  * \return The list of joint names.
166  */
167  const std::vector<std::string> &getGroupJointNamesConst(const std::string &group) const;
168 
169  /** \brief Get the joints for a group.
170  * \param[in] group Group to get joint names for.
171  * \return The list of joints.
172  */
173  std::vector<dart::dynamics::Joint *> getGroupJoints(const std::string &group) const;
174 
175  /** \brief Get a joint in a group along with its index in the group.
176  * \param[in] group Group to search.
177  * \param[in] joint Joint to find in group.
178  * \return The index of the joint and the joint in the group. {0, nullptr} if it does not exist.
179  */
181  const std::string &joint) const;
182 
183  /** \brief Get the indices of joints corresponding to a group.
184  * \param[in] group Group to get indices for.
185  * \return The indices of the joints in a group.
186  */
187  const std::vector<std::size_t> &getGroupIndices(const std::string &group) const;
188 
189  /** \brief Checks if a group exists.
190  * \param[in] name Name of group to check.
191  * \return True if the group exists, false otherwise.
192  */
193  bool isGroup(const std::string &name) const;
194 
195  /** \brief Gets the number of DoFs controlled by a group.
196  * \param[in] group Group to get DoFs for.
197  * \return The number of DoFs in the group.
198  */
199  std::size_t getNumDofsGroup(const std::string &group) const;
200 
201  /** \brief Get the current state of the joints of a group.
202  * \param[in] group Group to get state for.
203  * \param[out] q Configuration of the group.
204  */
205  void getGroupState(const std::string &group, Eigen::Ref<Eigen::VectorXd> q) const;
206 
207  /** \brief Set the current state of the joints of a group.
208  * \param[in] group Group to set state for.
209  * \param[out] q Configuration to set the group.
210  */
211  void setGroupState(const std::string &group, const Eigen::Ref<const Eigen::VectorXd> &q);
212 
213  /** \} */
214 
215  /** \name Constructing Groups
216  \{ */
217 
218  /** \brief Add a joint to a group.
219  * \param[in] group Group to add joint to.
220  * \param[in] joint_name Joint name to add.
221  * \return True on success, false on failure.
222  */
223  bool addJointToGroup(const std::string &group, const std::string &joint_name);
224 
225  /** \brief Add a the parent joint of a link to a group.
226  * \param[in] group Group to add joint to.
227  * \param[in] link_name Link to add.
228  * \return True on success, false on failure.
229  */
230  bool addLinkToGroup(const std::string &group, const std::string &link_name);
231 
232  /** \brief Add all the joints between two frames in a chain to a group.
233  * \param[in] group Group to add joint to.
234  * \param[in] tip Tip of the chain.
235  * \param[in] base Base of the chain.
236  * \return True on success, false on failure.
237  */
238  bool addChainToGroup(const std::string &group, const std::string &tip, const std::string &base);
239 
240  /** \brief Add all the joints in another group to this group.
241  * \param[in] group Group to add \a other to.
242  * \param[in] other Other group to add.
243  * \return True on success, false on failure.
244  */
245  bool addGroupToGroup(const std::string &group, const std::string &other);
246 
247  /** \} */
248 
249  /** \name Named States
250  \{ */
251 
252  /** \brief Set the named states map.
253  * \param[in] states New named states map.
254  */
255  void setNamedGroupStates(const NamedStatesMap &states);
256 
257  /** \brief Get the named states map.
258  * \return The map of named states.
259  */
260  const NamedStatesMap &getNamedGroupStates() const;
261 
262  /** \brief Get all names for named states for a group.
263  * \param[in] group Group to get named states for.
264  * \return List of all named states.
265  */
266  std::vector<std::string> getNamedGroupStates(const std::string &group) const;
267 
268  /** \brief Get the configuration of a named group state.
269  * \param[in] group Group of the named state.
270  * \param[in] name Name of the state to get.
271  * \param[out] q Configuration to fill with named state.
272  * \return True if state exists, false if not.
273  */
274  bool getNamedGroupState(const std::string &group, const std::string &name,
275  Eigen::Ref<Eigen::VectorXd> q) const;
276 
277  /** \brief Set or create a named group state.
278  * \param[in] group Group of the named state.
279  * \param[in] name Name of the state to set.
280  * \param[out] q Configuration for the named state.
281  */
282  void setNamedGroupState(const std::string &group, const std::string &name,
283  const Eigen::Ref<const Eigen::VectorXd> &q);
284 
285  /** \} */
286 
287  private:
288  /** \brief Adds a name to the group.
289  * \param[in] group Group to add name to.
290  * \param[in] name Name to add to group.
291  * \return True on success, false on failure.
292  */
293  bool addNameToGroup(const std::string &group, const std::string &name);
294 
295  /** \brief Process the members of a group to generate the set of indices.
296  * \param[in] group Group to process.
297  */
298  void processGroup(const std::string &group);
299 
300  std::map<std::string, std::vector<std::string>> groups_; ///< Map of group names to joint names.
302  ///< names to map of
303  ///< named states.
305 
306  robowflex::RobotPtr robot_{nullptr}; ///< Robowflex robot.
307  };
308 
309  /** \brief Load a robot from a URDF and SRDF (i.e., a MoveIt enabled robot).
310  * \param[in] name Name of the robot.
311  * \param[in] urdf URDF URI.
312  * \param[in] srdf SRDF URI.
313  * \return The loaded robot.
314  */
315  RobotPtr loadMoveItRobot(const std::string &name, const std::string &urdf, const std::string &srdf);
316 
317  } // namespace darts
318 } // namespace robowflex
319 
320 #endif
#define ROBOWFLEX_CLASS_FORWARD(C)
Macro that forward declares a class and defines two shared ptrs types:
Definition: class_forward.h:16
A shared pointer wrapper for robowflex::Robot.
A shared pointer wrapper for robowflex::Scene.
A sampleable goal region for OMPL for a set of TSRs. Samples goals in a separate thread using a clone...
std::map< std::string, std::vector< std::size_t > > group_indices_
Indices of group joints.
std::map< std::string, std::map< std::string, Eigen::VectorXd > > group_states_
std::map< std::string, std::vector< std::string > > groups_
Map of group names to joint names.
Wrapper class for a dart::dynamics::Skeleton.
Definition: structure.h:53
Functions for loading and animating robots in Blender.
bool loadURDF(Robot &robot, const std::string &urdf)
Loads a URDF at urdf into a robot.
RobotPtr loadMoveItRobot(const std::string &name, const std::string &urdf, const std::string &srdf)
Load a robot from a URDF and SRDF (i.e., a MoveIt enabled robot).
Main namespace. Contains all library classes and functions.
Definition: scene.cpp:25
Functions for loading and animating scenes in Blender.