Robowflex  v0.1
Making MoveIt Easy
baxter_multi_target.cpp
Go to the documentation of this file.
1 /* Author: Constantinos Chamzas */
2 
3 // Robowflex
8 
9 using namespace robowflex;
10 
11 /* \file baxter_multi_target.cpp
12  * A script that demonstrates the multi-target IK query functionality with a
13  * baxter robot. The robowflex_resouces package needs to be available, see
14  * https://github.com/KavrakiLab/robowflex_resources. You should run RViz and
15  * have a RobotState visualization display enabled set to look at
16  * /robowflex/robot_description, and robowflex/state. Also a MarkerArray should
17  * be added to visualize the target IK poses.
18  */
19 
20 static const std::string BOTH_ARMS = "both_arms";
21 static const std::string LEFT_ARM = "left_arm";
22 static const std::string LEFT_EE = "left_gripper_base";
23 static const std::string RIGHT_EE = "right_gripper_base";
24 
25 int main(int argc, char **argv)
26 {
27  // Startup ROS
28  ROS ros(argc, argv);
29 
30  // Create a Baxter robot.
31  auto baxter = std::make_shared<Robot>("baxter");
32  baxter->initializeFromYAML("package://robowflex_resources/baxter.yml");
33  baxter->loadKinematics(BOTH_ARMS);
34 
35  // Visualize the Baxter robot
36  IO::RVIZHelper rviz(baxter);
37  rviz.visualizeCurrentState();
38  RBX_INFO("Default robot state is visualized. Press enter to continue...");
39  std::cin.ignore();
40 
41  // EE offset that makes the arm point upwards.
42  const auto &ee_offset = TF::createPoseXYZ(0, 0, -1.3, constants::pi, 0, 0);
43 
44  // Use IK to shift robot arm over by desired amount.
45  const RobotPose &goal_pose_left = baxter->getLinkTF(LEFT_EE) * ee_offset;
46  const RobotPose &goal_pose_right = baxter->getLinkTF(RIGHT_EE) * ee_offset;
47 
48  // Visualizing the target poses.
49  rviz.addTransformMarker("pose_right", "map", goal_pose_right);
50  rviz.addTransformMarker("pose_left", "map", goal_pose_left);
51  rviz.updateMarkers();
52  RBX_INFO("Target IK poses are visualized. Press enter to continue...");
53  std::cin.ignore();
54 
55  Robot::IKQuery query(BOTH_ARMS, {goal_pose_left, goal_pose_right}, {LEFT_EE, RIGHT_EE});
56 
57  if (not baxter->setFromIK(query))
58  {
59  RBX_ERROR("IK query failed!");
60  return 1;
61  }
62 
63  // Visualize resulting state.
64  rviz.visualizeCurrentState();
65 
66  RBX_INFO("Robot IK solution visualized, Press enter to continue...");
67  std::cin.ignore();
68 
69  query = Robot::IKQuery(LEFT_ARM, goal_pose_left);
70  if (not baxter->setFromIK(query))
71  {
72  RBX_ERROR("Single IK query failed!");
73  return 1;
74  }
75 
76  // Visualize resulting state.
77  rviz.visualizeCurrentState();
78 
79  RBX_INFO("Robot left arm IK(ee:default) is visualized. Press enter to continue ...");
80  std::cin.ignore();
81 
82  query = Robot::IKQuery(LEFT_ARM, {goal_pose_left}, {LEFT_EE});
83  query.options.return_approximate_solution = true; // Enable approximate IK solutions.
84  query.validate = true; // Use to verify approximate solutions are within tolerance.
85  query.valid_distance = 0.05; // Tuned distance threshold that is appropriate for query.
86 
87  if (not baxter->setFromIK(query))
88  {
89  RBX_ERROR("Single Approximate IK query failed!");
90  return 1;
91  }
92 
93  // Visualize resulting state.
94  rviz.visualizeCurrentState();
95  RBX_INFO("Robot left arm IK(ee:left_gripper_base) is visualized. Press enter to exit...");
96  std::cin.ignore();
97 
98  return 0;
99 }
int main(int argc, char **argv)
static const std::string LEFT_EE
static const std::string LEFT_ARM
static const std::string BOTH_ARMS
static const std::string RIGHT_EE
RVIZ visualization helper. See Live Visualization with RViz for more information.
Definition: visualization.h:38
void updateMarkers()
Displays the managed list of markers. Keeps track of whether markers have already been displayed and ...
void visualizeCurrentState()
Visualize the current state of the robot.
void addTransformMarker(const std::string &name, const std::string &base_frame, const RobotPose &pose, double scale=1)
Add a transform marker to the managed list of markers. Displayed after an updateMarkers() call.
RAII-pattern for starting up ROS.
Definition: util.h:52
#define RBX_ERROR(fmt,...)
Output a error logging message.
Definition: log.h:102
#define RBX_INFO(fmt,...)
Output a info logging message.
Definition: log.h:118
RobotPose createPoseXYZ(double x, double y, double z)
Creates a robot pose from a linear component and zero orientation.
Definition: tf.cpp:14
static const double pi
Definition: constants.h:21
Main namespace. Contains all library classes and functions.
Definition: scene.cpp:25
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
Robot IK Query options. IK queries in Robowflex consist of: a) A position specified by some geometric...
kinematics::KinematicsQueryOptions options
Other query options.