Robowflex  v0.1
Making MoveIt Easy
robowflex::FetchRobot Class Reference

Convenience class that describes the default setup for Fetch. Will first attempt to load configuration and description from the robowflex_resources package. See https://github.com/KavrakiLab/robowflex_resources for this package. If this package is not available, then fetch_description / fetch_moveit_config packages will be used. More...

#include <fetch.h>

+ Inheritance diagram for robowflex::FetchRobot:

Public Member Functions

 FetchRobot ()
 Constructor. More...
 
bool initialize (bool addVirtual=true, bool use_low_limits=false)
 Initialize the robot with arm and arm_with_torso kinematics. More...
 
bool addCastersURDF (tinyxml2::XMLDocument &doc)
 Inserts the caster links if they don't exist. More...
 
void setBasePose (double x, double y, double theta)
 Sets the base pose of the Fetch robot (a virtual planar joint) More...
 
void pointHead (const Eigen::Vector3d &point)
 Points the Fetch's head to a point in the world frame. More...
 
void openGripper ()
 Opens the Fetch's gripper. More...
 
void closeGripper ()
 Closes the Fetch's gripper. More...
 
- Public Member Functions inherited from robowflex::Robot
 Robot (const std::string &name)
 Constructor. More...
 
 Robot (Robot const &)=delete
 
void operator= (Robot const &)=delete
 
bool initialize (const std::string &urdf_file)
 Initializes a robot from a kinematic description. A default semantic description is used. More...
 
bool initializeKinematics (const std::string &kinematics_file)
 Initialize a robot with a kinematics description. More...
 
bool initialize (const std::string &urdf_file, const std::string &srdf_file, const std::string &limits_file="", const std::string &kinematics_file="")
 Initializes a robot from a kinematic and semantic description. All files are loaded under the robot's namespace. More...
 
bool initializeFromYAML (const std::string &config_file)
 Initializes a robot from a YAML config which includes URDF (urdf) and optional the SRDF (srdf), joint limits (joint_limits), IK plugins (kinematics) and a default state (robot_state). All files are loaded under the robot's namespace. The names of the YAML keys are in parenthesis. More...
 
bool loadYAMLFile (const std::string &name, const std::string &file)
 Loads a YAML file into the robot's namespace under name. More...
 
bool loadYAMLFile (const std::string &name, const std::string &file, const PostProcessYAMLFunction &function)
 Loads a YAML file into the robot's namespace under name, with a post-process function. More...
 
std::string loadXMLFile (const std::string &file)
 Loads an XML or .xacro file into a string. More...
 
void setURDFPostProcessFunction (const PostProcessXMLFunction &function)
 Sets a post processing function for loading the URDF. More...
 
bool isLinkURDF (tinyxml2::XMLDocument &doc, const std::string &name)
 Checks if a node link exist with named name_link. More...
 
void setSRDFPostProcessFunction (const PostProcessXMLFunction &function)
 Sets a post processing function for loading the SRDF. More...
 
void setLimitsPostProcessFunction (const PostProcessYAMLFunction &function)
 Sets a post processing function for loading the joint limits file. More...
 
void setKinematicsPostProcessFunction (const PostProcessYAMLFunction &function)
 Sets a post processing function for loading the kinematics plugin file. More...
 
void setSRDFPostProcessAddPlanarJoint (const std::string &name)
 Adds a planar virtual joint through the SRDF to the loaded robot with name name. This joint will have three degrees of freedom: <name>/x, <name>/y, and <name>/theta. Will apply this joint between the world and the root frame. More...
 
void setSRDFPostProcessAddFloatingJoint (const std::string &name)
 Adds a planar virtual joint through the SRDF to the loaded robot with name name. This joint will have three degrees of freedom: <name>/x, <name>/y, and <name>/theta. Will apply this joint between the world and the root frame. More...
 
bool loadKinematics (const std::string &group, bool load_subgroups=true)
 Loads the kinematics plugin for a joint group and its subgroups. No kinematics are loaded by default. More...
 
const std::stringgetModelName () const
 Get the robot's model name. More...
 
const std::stringgetName () const
 Get the robot's name. More...
 
const robot_model::RobotModelPtr & getModelConst () const
 Get a const reference to the loaded robot model. More...
 
robot_model::RobotModelPtr & getModel ()
 Get a reference to the loaded robot model. More...
 
urdf::ModelInterfaceConstSharedPtr getURDF () const
 Get the raw URDF Model. More...
 
const std::stringgetURDFString () const
 Get the raw URDF Model as a string. More...
 
srdf::ModelConstSharedPtr getSRDF () const
 Get the raw SRDF Model. More...
 
const std::stringgetSRDFString () const
 Get the raw SRDF Model as a string. More...
 
const IO::HandlergetHandlerConst () const
 Get the underlying IO handler used for this robot. More...
 
IO::HandlergetHandler ()
 Get the underlying IO handler used for this robot. More...
 
const robot_model::RobotStatePtr & getScratchStateConst () const
 Get a const reference to the scratch robot state. More...
 
robot_model::RobotStatePtr & getScratchState ()
 Get a reference to the scratch robot state. More...
 
robot_model::RobotStatePtr cloneScratchState () const
 Allocate a new robot state that is a clone of the current scratch state. More...
 
robot_model::RobotStatePtr allocState () const
 Allocate a new robot state. More...
 
void setState (const std::vector< double > &positions)
 Sets the scratch state from a vector of joint positions (all must be specified) More...
 
void setState (const std::map< std::string, double > &variable_map)
 Sets the scratch state from a map of joint name to position. More...
 
void setState (const std::vector< std::string > &variable_names, const std::vector< double > &variable_position)
 Sets the scratch state from a vector of joint names and their positions. More...
 
void setState (const sensor_msgs::JointState &state)
 Sets the scratch state from a joint state message. More...
 
void setState (const moveit_msgs::RobotState &state)
 Sets the scratch state from a robot state message. More...
 
void setStateFromYAMLFile (const std::string &file)
 Sets the scratch state from a robot state message saved to a YAML file. More...
 
void setGroupState (const std::string &name, const std::vector< double > &positions)
 Sets the group of the scratch state to a vector of joint positions. More...
 
std::vector< double > getState () const
 Gets the current joint positions of the scratch state. More...
 
moveit_msgs::RobotState getStateMsg () const
 Get the current scratch state as a message. More...
 
void setStateMsgGroupState (moveit_msgs::RobotState &state, const std::string &group, const std::vector< double > &positions) const
 Set the group state of a MoveIt RobotState message. More...
 
std::vector< std::stringgetJointNames () const
 Gets the names of joints of the robot. More...
 
bool hasJoint (const std::string &joint) const
 Checks if a joint exists in the robot. More...
 
const RobotPosegetLinkTF (const std::string &name) const
 Get the current pose of a link on the scratch state. More...
 
const RobotPose getRelativeLinkTF (const std::string &base, const std::string &target) const
 Get the current pose of a link target in the frame of base. More...
 
bool setFromIK (const IKQuery &query)
 Sets a group of the scratch state from an IK query. If the IK query fails the scratch state retains its initial value. More...
 
bool setFromIK (const IKQuery &query, robot_state::RobotState &state) const
 Sets a robot state from an IK query. If the IK query fails the scratch state retains its initial value. More...
 
bool validateIKQuery (const IKQuery &query, const robot_state::RobotState &state) const
 Validates that a state satisfies an IK query's request poses. More...
 
double distanceToIKQuery (const IKQuery &query, const robot_state::RobotState &state) const
 Returns the distance of the state to satisfying the IK query. More...
 
std::vector< std::stringgetSolverTipFrames (const std::string &group) const
 Get the tip frames for the IK solver for a given joint model group group. More...
 
std::string getSolverBaseFrame (const std::string &group) const
 Get the base frame for the IK solver given a joint model group group. More...
 
bool toYAMLFile (const std::string &file) const
 Dumps the current configuration of the robot as a YAML file. More...
 
bool dumpGeometry (const std::string &file) const
 Dumps the names of links and absolute paths to their visual mesh files to a YAML file. More...
 
bool dumpTransforms (const std::string &filename) const
 Dumps the tranforms of all links of a robot at its current state to a file. More...
 
bool dumpPathTransforms (const robot_trajectory::RobotTrajectory &path, const std::string &filename, double fps=30, double threshold=0.0) const
 Dumps the tranforms of all links of a robot through a robot trajectory to a file. More...
 
bool dumpToScene (const std::string &filename) const
 Dumps the current scratch configuration of the robot to a YAML file compatible with a scene. More...
 

Static Private Attributes

static const std::string DEFAULT_URDF {"package://fetch_description/robots/fetch.urdf"}
 Default URDF. More...
 
static const std::string DEFAULT_SRDF {"package://fetch_moveit_config/config/fetch.srdf"}
 Default SRDF. More...
 
static const std::string DEFAULT_LIMITS {"package://fetch_moveit_config/config/joint_limits.yaml"}
 Default Limits. More...
 
static const std::string DEFAULT_KINEMATICS {"package://fetch_moveit_config/config/kinematics.yaml"}
 Default kinematics. More...
 
static const std::string RESOURCE_URDF {"package://robowflex_resources/fetch/robots/fetch.urdf"}
 URDF from robowflex_resources. More...
 
static const std::string RESOURCE_SRDF {"package://robowflex_resources/fetch/config/fetch.srdf"}
 SRDF from robowflex_resources. More...
 
static const std::string RESOURCE_LIMITS {"package://robowflex_resources/fetch/config/joint_limits.yaml"}
 Limits from robowflex_resources. More...
 
static const std::string RESOURCE_LIMITS_LOW {"package://robowflex_resources/fetch/config/joint_limits_low.yaml"}
 Lower limits from robowflex_resources. More...
 
static const std::string RESOURCE_KINEMATICS {"package://robowflex_resources/fetch/config/kinematics.yaml"}
 kinematics from robowflex_resources More...
 

Additional Inherited Members

- Public Types inherited from robowflex::Robot
typedef std::function< bool(YAML::Node &)> PostProcessYAMLFunction
 A function that runs after loading a YAML file and can modify its contents. Returns true on success, false on failure. More...
 
typedef std::function< bool(tinyxml2::XMLDocument &)> PostProcessXMLFunction
 A function that runs after loading a XML file and can modify its contents. Returns true on success, false on failure. More...
 
- Static Public Attributes inherited from robowflex::Robot
static const std::string ROBOT_DESCRIPTION = "robot_description"
 Default robot description name. More...
 
static const std::string ROBOT_SEMANTIC = "_semantic"
 Default robot semantic description suffix. More...
 
static const std::string ROBOT_PLANNING = "_planning"
 Default robot planning description suffix. More...
 
static const std::string ROBOT_KINEMATICS = "_kinematics"
 Default robot kinematics description suffix. More...
 
- Protected Member Functions inherited from robowflex::Robot
bool loadURDFFile (const std::string &urdf_file)
 Loads the URDF file. More...
 
bool loadSRDFFile (const std::string &srdf_file)
 Loads the SRDF file. More...
 
void initializeInternal (bool namespaced=true)
 Initializes and loads the robot. Calls post-processing functions and creates scratch state. More...
 
void loadRobotModel (const std::string &description)
 Loads a robot model from the loaded information on the parameter server. More...
 
void updateXMLString (std::string &string, const PostProcessXMLFunction &function)
 Updates a loaded XML string based on an XML post-process function. Called after initial, unmodified robot is loaded. More...
 
- Protected Attributes inherited from robowflex::Robot
const std::string name_
 Robot name. More...
 
IO::Handler handler_
 IO handler (namespaced with name_) More...
 
std::string urdf_
 The URDF as a string. More...
 
std::string srdf_
 The SRDF as a string. More...
 
PostProcessXMLFunction urdf_function_
 URDF post-processing function. More...
 
PostProcessXMLFunction srdf_function_
 SRDF post-processing function. More...
 
PostProcessYAMLFunction limits_function_
 Limits YAML post-processing function. More...
 
PostProcessYAMLFunction kinematics_function_
 Kinematics plugin YAML post-processing function. More...
 
std::shared_ptr< robot_model_loader::RobotModelLoader > loader_
 Robot model loader. More...
 
robot_model::RobotModelPtr model_
 Loaded robot model. More...
 
std::map< std::string, robot_model::SolverAllocatorFnimap_
 Kinematic solver allocator map. More...
 
kinematics_plugin_loader::KinematicsPluginLoaderPtr kinematics_
 Kinematic plugin loader. More...
 
robot_state::RobotStatePtr scratch_
 Scratch robot state. More...
 

Detailed Description

Convenience class that describes the default setup for Fetch. Will first attempt to load configuration and description from the robowflex_resources package. See https://github.com/KavrakiLab/robowflex_resources for this package. If this package is not available, then fetch_description / fetch_moveit_config packages will be used.

Definition at line 26 of file fetch.h.

Constructor & Destructor Documentation

◆ FetchRobot()

FetchRobot::FetchRobot ( )

Constructor.

Definition at line 29 of file fetch.cpp.

29  : Robot("fetch")
30 {
31 }
Robot(const std::string &name)
Constructor.

Member Function Documentation

◆ addCastersURDF()

bool FetchRobot::addCastersURDF ( tinyxml2::XMLDocument &  doc)

Inserts the caster links if they don't exist.

Parameters
[in]docurdf description to be processed.
Returns
True on success.

Definition at line 65 of file fetch.cpp.

66 {
67  for (const auto &name : {"bl_caster", "br_caster", "fl_caster", "fr_caster"})
68  {
69  auto link_name = std::string(name) + "_link";
70  if (not isLinkURDF(doc, link_name))
71  {
72  tinyxml2::XMLElement *caster_link = doc.NewElement("link");
73  caster_link->SetAttribute("name", link_name.c_str());
74  doc.FirstChildElement("robot")->InsertFirstChild(caster_link);
75 
76  auto joint_name = std::string(name) + "_joint";
77  tinyxml2::XMLElement *caster_joint = doc.NewElement("joint");
78  caster_joint->SetAttribute("name", joint_name.c_str());
79  caster_joint->SetAttribute("type", "fixed");
80 
81  tinyxml2::XMLElement *parent = doc.NewElement("parent");
82  parent->SetAttribute("link", "base_link");
83  caster_joint->InsertFirstChild(parent);
84 
85  tinyxml2::XMLElement *child = doc.NewElement("child");
86  child->SetAttribute("link", link_name.c_str());
87  caster_joint->InsertFirstChild(child);
88 
89  doc.FirstChildElement("robot")->InsertFirstChild(caster_joint);
90  }
91  }
92 
93  return true;
94 }
bool isLinkURDF(tinyxml2::XMLDocument &doc, const std::string &name)
Checks if a node link exist with named name_link.

◆ closeGripper()

void FetchRobot::closeGripper ( )

Closes the Fetch's gripper.

Definition at line 119 of file fetch.cpp.

120 {
121  const std::map<std::string, double> angles = {{"l_gripper_finger_joint", 0.0},
122  {"r_gripper_finger_joint", 0.0}};
123 
124  Robot::setState(angles);
125 }
void setState(const std::vector< double > &positions)
Sets the scratch state from a vector of joint positions (all must be specified)

◆ initialize()

bool FetchRobot::initialize ( bool  addVirtual = true,
bool  use_low_limits = false 
)

Initialize the robot with arm and arm_with_torso kinematics.

Parameters
[in]addVirtualflag to add virtual joint.
[in]use_low_limitsflag to use lower joint limits.
Returns
True on success, false on failure.

Definition at line 33 of file fetch.cpp.

34 {
35  if (addVirtual)
37 
38  setURDFPostProcessFunction([this](tinyxml2::XMLDocument &doc) { return addCastersURDF(doc); });
39 
40  bool success = false;
41  // First attempt the `robowflex_resources` package, then attempt the "actual" resource files.
43  {
44  RBX_INFO("Initializing Fetch with `fetch_{description, moveit_config}`");
46  }
47  else
48  {
49  RBX_INFO("Initializing Fetch with `robowflex_resources`");
50  if (use_low_limits)
51  success =
53  else
55  }
56 
57  loadKinematics("arm");
58  loadKinematics("arm_with_torso");
59 
61 
62  return success;
63 }
static const std::string RESOURCE_SRDF
SRDF from robowflex_resources.
Definition: fetch.h:73
static const std::string DEFAULT_URDF
Default URDF.
Definition: fetch.h:67
static const std::string DEFAULT_SRDF
Default SRDF.
Definition: fetch.h:68
void openGripper()
Opens the Fetch's gripper.
Definition: fetch.cpp:111
static const std::string RESOURCE_KINEMATICS
kinematics from robowflex_resources
Definition: fetch.h:76
static const std::string RESOURCE_URDF
URDF from robowflex_resources.
Definition: fetch.h:72
static const std::string RESOURCE_LIMITS_LOW
Lower limits from robowflex_resources.
Definition: fetch.h:75
static const std::string RESOURCE_LIMITS
Limits from robowflex_resources.
Definition: fetch.h:74
static const std::string DEFAULT_KINEMATICS
Default kinematics.
Definition: fetch.h:70
bool addCastersURDF(tinyxml2::XMLDocument &doc)
Inserts the caster links if they don't exist.
Definition: fetch.cpp:65
static const std::string DEFAULT_LIMITS
Default Limits.
Definition: fetch.h:69
void setURDFPostProcessFunction(const PostProcessXMLFunction &function)
Sets a post processing function for loading the URDF.
bool initialize(const std::string &urdf_file)
Initializes a robot from a kinematic description. A default semantic description is used.
void setSRDFPostProcessAddPlanarJoint(const std::string &name)
Adds a planar virtual joint through the SRDF to the loaded robot with name name. This joint will have...
bool loadKinematics(const std::string &group, bool load_subgroups=true)
Loads the kinematics plugin for a joint group and its subgroups. No kinematics are loaded by default.
T empty(T... args)
#define RBX_INFO(fmt,...)
Output a info logging message.
Definition: log.h:118
std::string resolvePackage(const std::string &path)
Resolves package:// URLs to their canonical form. The path does not need to exist,...

◆ openGripper()

void FetchRobot::openGripper ( )

Opens the Fetch's gripper.

Definition at line 111 of file fetch.cpp.

112 {
113  const std::map<std::string, double> angles = {{"l_gripper_finger_joint", 0.04},
114  {"r_gripper_finger_joint", 0.04}};
115 
116  Robot::setState(angles);
117 }

◆ pointHead()

void FetchRobot::pointHead ( const Eigen::Vector3d &  point)

Points the Fetch's head to a point in the world frame.

Parameters
[in]pointThe point to look at.

Definition at line 96 of file fetch.cpp.

97 {
98  const RobotPose point_pose = RobotPose(Eigen::Translation3d(point));
99  const RobotPose point_pan = getLinkTF("head_pan_link").inverse() * point_pose;
100  const RobotPose point_tilt = getLinkTF("head_tilt_link").inverse() * point_pose;
101 
102  const double pan = atan2(point_pan.translation().y(), point_pan.translation().x());
103  const double tilt = -atan2(point_tilt.translation().z(),
104  hypot(point_tilt.translation().x(), point_tilt.translation().y()));
105 
106  const std::map<std::string, double> angles = {{"head_pan_joint", pan}, {"head_tilt_joint", tilt}};
107 
108  Robot::setState(angles);
109 }
T atan2(T... args)
const RobotPose & getLinkTF(const std::string &name) const
Get the current pose of a link on the scratch state.
T hypot(T... args)
std::decay< decltype(std::declval< moveit::core::Transforms >().getTransform("")) >::type RobotPose
A pose (point in SE(3)) used in various functions. Defined from what MoveIt! uses.
Definition: adapter.h:24

◆ setBasePose()

void FetchRobot::setBasePose ( double  x,
double  y,
double  theta 
)

Sets the base pose of the Fetch robot (a virtual planar joint)

Parameters
[in]xThe x position.
[in]yThe y position.
[in]thetaThe angle.

Definition at line 127 of file fetch.cpp.

128 {
129  if (hasJoint("base_joint/x") && hasJoint("base_joint/y") && hasJoint("base_joint/theta"))
130  {
131  const std::map<std::string, double> pose = {
132  {"base_joint/x", x}, {"base_joint/y", y}, {"base_joint/theta", theta}};
133 
134  scratch_->setVariablePositions(pose);
135  scratch_->update();
136  }
137  else
138  RBX_WARN("base_joint does not exist, cannot move base! You need to set addVirtual to true");
139 }
robot_state::RobotStatePtr scratch_
Scratch robot state.
bool hasJoint(const std::string &joint) const
Checks if a joint exists in the robot.
#define RBX_WARN(fmt,...)
Output a warning logging message.
Definition: log.h:110

Member Data Documentation

◆ DEFAULT_KINEMATICS

const std::string FetchRobot::DEFAULT_KINEMATICS {"package://fetch_moveit_config/config/kinematics.yaml"}
staticprivate

Default kinematics.

Definition at line 70 of file fetch.h.

◆ DEFAULT_LIMITS

const std::string FetchRobot::DEFAULT_LIMITS {"package://fetch_moveit_config/config/joint_limits.yaml"}
staticprivate

Default Limits.

Definition at line 69 of file fetch.h.

◆ DEFAULT_SRDF

const std::string FetchRobot::DEFAULT_SRDF {"package://fetch_moveit_config/config/fetch.srdf"}
staticprivate

Default SRDF.

Definition at line 68 of file fetch.h.

◆ DEFAULT_URDF

const std::string FetchRobot::DEFAULT_URDF {"package://fetch_description/robots/fetch.urdf"}
staticprivate

Default URDF.

Definition at line 67 of file fetch.h.

◆ RESOURCE_KINEMATICS

const std::string FetchRobot::RESOURCE_KINEMATICS {"package://robowflex_resources/fetch/config/kinematics.yaml"}
staticprivate

kinematics from robowflex_resources

Definition at line 76 of file fetch.h.

◆ RESOURCE_LIMITS

const std::string FetchRobot::RESOURCE_LIMITS {"package://robowflex_resources/fetch/config/joint_limits.yaml"}
staticprivate

Limits from robowflex_resources.

Definition at line 74 of file fetch.h.

◆ RESOURCE_LIMITS_LOW

const std::string FetchRobot::RESOURCE_LIMITS_LOW {"package://robowflex_resources/fetch/config/joint_limits_low.yaml"}
staticprivate

Lower limits from robowflex_resources.

Definition at line 75 of file fetch.h.

◆ RESOURCE_SRDF

const std::string FetchRobot::RESOURCE_SRDF {"package://robowflex_resources/fetch/config/fetch.srdf"}
staticprivate

SRDF from robowflex_resources.

Definition at line 73 of file fetch.h.

◆ RESOURCE_URDF

const std::string FetchRobot::RESOURCE_URDF {"package://robowflex_resources/fetch/robots/fetch.urdf"}
staticprivate

URDF from robowflex_resources.

Definition at line 72 of file fetch.h.


The documentation for this class was generated from the following files: