Robowflex  v0.1
Making MoveIt Easy
cob4.cpp
Go to the documentation of this file.
1 /* Author: Juan D. Hernandez */
2 
3 #include <cmath>
4 
7 #include <robowflex_library/io.h>
8 
9 using namespace robowflex;
10 
11 const std::string //
12  Cob4Robot::DEFAULT_URDF{"package://cob_hardware_config/robots/cob4-8/urdf/cob4-8.urdf.xacro"};
13 const std::string //
14  Cob4Robot::DEFAULT_SRDF{"package://cob_moveit_config/robots/cob4-8/moveit/config/cob4-8.srdf"};
15 const std::string //
16  Cob4Robot::DEFAULT_LIMITS{"package://cob_moveit_config/robots/cob4-8/moveit/config/joint_limits.yaml"};
17 const std::string //
18  Cob4Robot::DEFAULT_KINEMATICS{"package://cob_moveit_config/robots/cob4-8/moveit/config/kinematics.yaml"};
19 const std::string //
20  OMPL::Cob4OMPLPipelinePlanner::DEFAULT_CONFIG{"package://cob_moveit_config/robots/cob4-8/moveit/config/"
21  "ompl_planning.yaml"};
22 
23 const std::string Cob4Robot::RESOURCE_URDF{"package://robowflex_resources/cob/robots/cob4-8.urdf.xacro"};
24 const std::string Cob4Robot::RESOURCE_SRDF{"package://robowflex_resources/cob/config/cob4-8.srdf"};
25 const std::string Cob4Robot::RESOURCE_LIMITS{"package://robowflex_resources/cob/config/joint_limits.yaml"};
26 const std::string //
27  Cob4Robot::RESOURCE_KINEMATICS{"package://robowflex_resources/cob/config/kinematics.yaml"};
28 const std::string //
29  OMPL::Cob4OMPLPipelinePlanner::RESOURCE_CONFIG{"package://robowflex_resources/cob/config/"
30  "ompl_planning.yaml"};
31 
33 {
34 }
35 
37 {
38  bool success = false;
39 
40  // First attempt the `robowflex_resources` package, then attempt the "actual" resource files.
42  {
43  RBX_INFO("Initializing Cob4 with `cob4_{description, moveit_config}`");
45  }
46  else
47  {
48  RBX_INFO("Initializing Cob4 with `robowflex_resources`");
50  }
51 
52  loadKinematics("arm_left");
53  loadKinematics("arm_right");
54 
56 
57  return success;
58 }
59 
60 void Cob4Robot::pointHead(const Eigen::Vector3d &point)
61 {
62  const RobotPose point_pose = RobotPose(Eigen::Translation3d(point));
63  const RobotPose point_pan = getLinkTF("head_3_link").inverse() * point_pose;
64 
65  const double pan = atan2(point_pan.translation().y(), point_pan.translation().x());
66 
67  const std::map<std::string, double> angles = {{"head_1_joint", pan}};
68 
69  Robot::setState(angles);
70 }
71 
73 {
74  const std::map<std::string, double> angles = {{"gripper_left_finger_1_joint", -1.0},
75  {"gripper_left_finger_2_joint", 1.2},
76  {"gripper_right_finger_1_joint", -1.0},
77  {"gripper_right_finger_2_joint", 1.2}};
78 
79  Robot::setState(angles);
80 }
81 
83 {
84  const std::map<std::string, double> angles = {{"gripper_left_finger_1_joint", -1.0},
85  {"gripper_left_finger_2_joint", 1.2}};
86 
87  Robot::setState(angles);
88 }
89 
91 {
92  const std::map<std::string, double> angles = {{"gripper_right_finger_1_joint", -1.0},
93  {"gripper_right_finger_2_joint", 1.2}};
94 
95  Robot::setState(angles);
96 }
97 
99 {
100  const std::map<std::string, double> angles = {{"l_gripper_finger_joint", 0.0},
101  {"r_gripper_finger_joint", 0.0}};
102 
103  Robot::setState(angles);
104 }
105 
107 {
108  const std::map<std::string, double> angles = {{"gripper_left_finger_1_joint", 0.0},
109  {"gripper_left_finger_2_joint", 0.0}};
110 
111  Robot::setState(angles);
112 }
113 
115 {
116  const std::map<std::string, double> angles = {{"gripper_right_finger_1_joint", 0.0},
117  {"gripper_right_finger_2_joint", 0.0}};
118 
119  Robot::setState(angles);
120 }
121 
122 void Cob4Robot::setBasePose(double x, double y, double theta)
123 {
124  if (hasJoint("base_joint/x") && hasJoint("base_joint/y") && hasJoint("base_joint/theta"))
125  {
126  const std::map<std::string, double> pose = {
127  {"base_joint/x", x}, {"base_joint/y", y}, {"base_joint/theta", theta}};
128 
129  scratch_->setVariablePositions(pose);
130  scratch_->update();
131  }
132  else
133  RBX_WARN("base_joint does not exist, cannot move base! You need to set addVirtual to true");
134 }
135 
137  : OMPLPipelinePlanner(robot, name)
138 {
139 }
140 
142  const std::vector<std::string> &adapters)
143 {
144  if (IO::resolvePackage(RESOURCE_CONFIG).empty())
145  return OMPLPipelinePlanner::initialize(DEFAULT_CONFIG, settings, DEFAULT_PLUGIN, adapters);
146  else
147  return OMPLPipelinePlanner::initialize(RESOURCE_CONFIG, settings, DEFAULT_PLUGIN, adapters);
148 }
void closeLeftGripper()
Closes the Cob4's left gripper.
Definition: cob4.cpp:106
void closeGrippers()
Closes the Cob4's grippers.
Definition: cob4.cpp:98
bool initialize()
Initialize the robot with arm_left and arm_right kinematics.
Definition: cob4.cpp:36
void openLeftGripper()
Opens the Cob4's left gripper.
Definition: cob4.cpp:82
void openRightGripper()
Opens the Cob4's right gripper.
Definition: cob4.cpp:90
void setBasePose(double x, double y, double theta)
Sets the base pose of the Cob4 robot (a virtual planar joint)
Definition: cob4.cpp:122
static const std::string DEFAULT_LIMITS
Default Limits.
Definition: cob4.h:77
static const std::string DEFAULT_SRDF
Default SRDF.
Definition: cob4.h:76
static const std::string RESOURCE_URDF
URDF from robowflex_resources.
Definition: cob4.h:80
void openGrippers()
Opens the Cob4's grippers.
Definition: cob4.cpp:72
static const std::string RESOURCE_KINEMATICS
kinematics from robowflex_resources
Definition: cob4.h:83
void closeRightGripper()
Closes the Cob4's right gripper.
Definition: cob4.cpp:114
static const std::string DEFAULT_KINEMATICS
Default kinematics.
Definition: cob4.h:78
static const std::string RESOURCE_LIMITS
Limits from robowflex_resources.
Definition: cob4.h:82
Cob4Robot()
Constructor.
Definition: cob4.cpp:32
void pointHead(const Eigen::Vector3d &point)
Points the Cob4's head to a point in the world frame.
Definition: cob4.cpp:60
static const std::string DEFAULT_URDF
Default URDF.
Definition: cob4.h:75
static const std::string RESOURCE_SRDF
SRDF from robowflex_resources.
Definition: cob4.h:81
bool initialize(const Settings &settings=Settings(), const std::vector< std::string > &adapters=DEFAULT_ADAPTERS)
Initialize the planning context. All parameter provided are defaults.
Definition: cob4.cpp:141
static const std::string RESOURCE_CONFIG
Planning configuration from robowflex_resources.
Definition: cob4.h:119
Cob4OMPLPipelinePlanner(const RobotPtr &robot, const std::string &name="")
Constructor.
Definition: cob4.cpp:136
static const std::string DEFAULT_CONFIG
Default planning configuration.
Definition: cob4.h:118
A robowflex::PipelinePlanner that uses the MoveIt! default OMPL planning pipeline.
bool initialize(const std::string &config_file="", const Settings &settings=Settings(), const std::string &plugin=DEFAULT_PLUGIN, const std::vector< std::string > &adapters=DEFAULT_ADAPTERS)
Initialize planning pipeline. Loads OMPL planning plugin plugin with the planning adapters adapters....
Settings descriptor for settings provided by the default MoveIt! OMPL planning pipeline.
A shared pointer wrapper for robowflex::Robot.
Loads information about a robot and maintains information about a robot's state.
const RobotPose & getLinkTF(const std::string &name) const
Get the current pose of a link on the scratch state.
bool initialize(const std::string &urdf_file)
Initializes a robot from a kinematic description. A default semantic description is used.
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.
robot_state::RobotStatePtr scratch_
Scratch robot state.
void setState(const std::vector< double > &positions)
Sets the scratch state from a vector of joint positions (all must be specified)
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
#define RBX_INFO(fmt,...)
Output a info logging message.
Definition: log.h:118
Functions for loading and animating robots in Blender.
std::string resolvePackage(const std::string &path)
Resolves package:// URLs to their canonical form. The path does not need to exist,...
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