ShadowHandUtilityLibrary
shadow_utils.hpp
Go to the documentation of this file.
1 //
2 // Created by kganguly on 2/18/18.
3 //
4 #pragma once
5 
7 
14 std::ostream &operator<<(std::ostream &out, const geometry_msgs::Pose &pose);
15 
23 template <typename T>
24 std::ostream &operator<<(std::ostream &out, const std::vector<T> &joint_data) {
25  for (T i : joint_data) {
26  out << i << " ";
27  }
28  out << "\n";
29 
30  return out; // return std::ostream so we can chain calls to operator<<
31 };
32 
39 namespace shadow_utils {
45 
47 Eigen::Quaternionf ypr2quat(float y, float p, float r);
49 void quat2ypr(tf::Quaternion &q, double &r, double &p, double &y);
50 
52 template<typename F>
53 inline F deg2rad(F deg) { return deg * M_PI / 180.0; };
54 
56 template<typename F>
57 inline F rad2deg(F rad) { return rad * (180.0 / M_PI); };
58 
70  moveit_msgs::CollisionObject &collision_obj, std::string primitive_id,
71  shape_msgs::SolidPrimitive &primitive, geometry_msgs::Pose &obj_pose,
72  shadow_utils::SHAPE_PRIMITIVES primitive_type,
73  const std::vector<double> &primitive_dims);
74 
87  moveit_msgs::AttachedCollisionObject &attached_obj,
88  std::string primitive_id, shape_msgs::SolidPrimitive &primitive,
89  geometry_msgs::Pose &obj_pose,
90  shadow_utils::SHAPE_PRIMITIVES primitive_type,
91  const std::vector<double> &primitive_dims);
92 
99 void addCollisionObjectToScene(moveit_msgs::CollisionObject &collision_obj,
100  moveit_msgs::PlanningScene &planning_scene_msg,
101  ros::Publisher &planning_scene_diff_publisher);
102 
110  moveit_msgs::AttachedCollisionObject &attached_obj,
111  moveit_msgs::PlanningScene &planning_scene_msg,
112  ros::Publisher &planning_scene_diff_publisher);
113 
121 void moveCollisionObjectInScene(moveit_msgs::CollisionObject &collision_obj,
122  geometry_msgs::Pose &obj_pose,
123  moveit_msgs::PlanningScene &planning_scene_msg,
124  ros::Publisher &planning_scene_diff_publisher);
125 
132 void attachObjectToRobot(moveit_msgs::AttachedCollisionObject &attached_obj,
133  moveit_msgs::PlanningScene &planning_scene_msg,
134  ros::Publisher &planning_scene_diff_publisher);
135 
142 void detachObjectFromRobot(moveit_msgs::AttachedCollisionObject &attached_obj,
143  moveit_msgs::PlanningScene &planning_scene_msg,
144  ros::Publisher &planning_scene_diff_publisher);
145 
151  moveit::planning_interface::PlanningSceneInterface
152  &planning_scene_interface);
153 
160  moveit::planning_interface::PlanningSceneInterface
161  &planning_scene_interface,
162  std::string obj_id);
163 
174 void getPoseFromPositionYPR(geometry_msgs::Pose &pose, float x, float y,
175  float z, float yaw, float pitch, float roll);
176 
188 void getPoseFromPositionQuaternion(geometry_msgs::Pose &pose, float x, float y,
189  float z, float qx, float qy, float qz,
190  float qw);
191 
193 void getPoseFromPositionYPR(geometry_msgs::Pose &pose, float x, float y,
194  float z, tf::Vector3 &v);
195 
197 void getPoseFromPositionQuaternion(geometry_msgs::Pose &pose, float x, float y,
198  float z, tf::Quaternion &q);
199 
201 void getPoseFromPositionQuaternion(geometry_msgs::Pose &pose,
202  tf::StampedTransform &tf, tf::Quaternion &q);
203 
211 void getTfFromFrames(tf::TransformListener &listener, tf::StampedTransform &tf,
212  std::string parent_frame, std::string child_frame);
213 
220 std::string getControllerTopic(std::string &joint_name);
221 
229 std::vector<ros::Publisher>
230 createJointControllerPublishers(std::vector<std::string> &joint_names,
231  ros::NodeHandle &n);
232 
239 void broadcastTransformForGrasp(std::vector<double> xyzrpy,
240  const std::string frame_name);
241 
248 geometry_msgs::Pose getPoseBetweenFrames(const std::string parent_frame,
249  const std::string child_frame);
250 
264 moveit_msgs::RobotState computeJointsFromPose(
265  moveit::planning_interface::MoveGroupInterface &move_group_interface,
266  double timeout, int num_attempts, geometry_msgs::Pose &target_pose);
267 
275 void startTrajectoryController(ros::NodeHandle n, std::string controller_name);
276 
284 void stopTrajectoryController(ros::NodeHandle n, std::string controller_name);
285 }; // namespace shadow_utils
void removeCollisionObjectFromScene(moveit::planning_interface::PlanningSceneInterface &planning_scene_interface, std::string obj_id)
Remove some object from the scene.
Definition: shadow_utils.cpp:266
void createCollisionObjectFromPrimitive(moveit_msgs::CollisionObject &collision_obj, std::string primitive_id, shape_msgs::SolidPrimitive &primitive, geometry_msgs::Pose &obj_pose, shadow_utils::SHAPE_PRIMITIVES primitive_type, const std::vector< double > &primitive_dims)
Create collision object for the planning scene, used by MoveIt planning.
Definition: shadow_utils.cpp:93
std::string getControllerTopic(std::string &joint_name)
Get the name of the controller responsible for controlling the given joint name.
Definition: shadow_utils.cpp:292
std::vector< ros::Publisher > createJointControllerPublishers(std::vector< std::string > &joint_names, ros::NodeHandle &n)
Create a vector of publishers for each given joint name, using the ROS node handle.
Definition: shadow_utils.cpp:320
void detachObjectFromRobot(moveit_msgs::AttachedCollisionObject &attached_obj, moveit_msgs::PlanningScene &planning_scene_msg, ros::Publisher &planning_scene_diff_publisher)
Detach an attached collision object from the robot.
Definition: shadow_utils.cpp:236
void broadcastTransformForGrasp(std::vector< double > xyzrpy, const std::string frame_name)
Broadcasts a transform from the wrist to given frame, which can be used for planning targets for fing...
Definition: shadow_utils.cpp:365
void createAttachedObjectFromPrimitive(moveit_msgs::AttachedCollisionObject &attached_obj, std::string primitive_id, shape_msgs::SolidPrimitive &primitive, geometry_msgs::Pose &obj_pose, shadow_utils::SHAPE_PRIMITIVES primitive_type, const std::vector< double > &primitive_dims)
Create attached object for the planning scene, used by MoveIt planning when attaching object to robot...
Definition: shadow_utils.cpp:135
void quat2ypr(tf::Quaternion &q, double &r, double &p, double &y)
Conversion from Quaternion to YPR.
Definition: shadow_utils.cpp:23
SHAPE_PRIMITIVES
Primitive shapes used for RViz objects.
Definition: shadow_utils.hpp:44
moveit_msgs::RobotState computeJointsFromPose(moveit::planning_interface::MoveGroupInterface &move_group_interface, double timeout, int num_attempts, geometry_msgs::Pose &target_pose)
Creates a RobotState using the inverse kinematics solver, given a target pose. Uses a service call to...
Definition: shadow_utils.cpp:393
void getTfFromFrames(tf::TransformListener &listener, tf::StampedTransform &tf, std::string parent_frame, std::string child_frame)
Get TF from parent and child frames.
Definition: shadow_utils.cpp:276
void getPoseFromPositionQuaternion(geometry_msgs::Pose &pose, float x, float y, float z, float qx, float qy, float qz, float qw)
Generate ROS Pose from position and quaternion.
Definition: shadow_utils.cpp:29
void startTrajectoryController(ros::NodeHandle n, std::string controller_name)
Starts trajectory controller for arm or hand, using ControllerManager service call.
Definition: shadow_utils.cpp:438
F deg2rad(F deg)
Conversion from degree to radians.
Definition: shadow_utils.hpp:53
std::ostream & operator<<(std::ostream &out, const geometry_msgs::Pose &pose)
Print ROS Pose messages.
Definition: shadow_utils.cpp:7
Contains various utility functions for RViz visualization, conversions, transformations and robot con...
Definition: shadow_utils.hpp:31
void getPoseFromPositionYPR(geometry_msgs::Pose &pose, float x, float y, float z, float yaw, float pitch, float roll)
Generate ROS Pose from position and YPR.
Definition: shadow_utils.cpp:66
F rad2deg(F rad)
Conversion from radians to degrees.
Definition: shadow_utils.hpp:57
void moveCollisionObjectInScene(moveit_msgs::CollisionObject &collision_obj, geometry_msgs::Pose &obj_pose, moveit_msgs::PlanningScene &planning_scene_msg, ros::Publisher &planning_scene_diff_publisher)
Move an existing collision object in the planning scene.
Definition: shadow_utils.cpp:199
void removeAllObjectsFromScene(moveit::planning_interface::PlanningSceneInterface &planning_scene_interface)
Remove all objects from the scene.
Definition: shadow_utils.cpp:257
void attachObjectToRobot(moveit_msgs::AttachedCollisionObject &attached_obj, moveit_msgs::PlanningScene &planning_scene_msg, ros::Publisher &planning_scene_diff_publisher)
Attach a collision object to the robot.
Definition: shadow_utils.cpp:215
Eigen::Quaternionf ypr2quat(float y, float p, float r)
Conversion from YPR to Quaternion.
Definition: shadow_utils.cpp:16
void stopTrajectoryController(ros::NodeHandle n, std::string controller_name)
Stops trajectory controller for arm or hand, using ControllerManager service call.
Definition: shadow_utils.cpp:457
geometry_msgs::Pose getPoseBetweenFrames(const std::string parent_frame, const std::string child_frame)
Get the pose between two frames.
Definition: shadow_utils.cpp:340
void addCollisionObjectToScene(moveit_msgs::CollisionObject &collision_obj, moveit_msgs::PlanningScene &planning_scene_msg, ros::Publisher &planning_scene_diff_publisher)
Add a collision object to the planning scene.
Definition: shadow_utils.cpp:171
void addAttachedObjectToScene(moveit_msgs::AttachedCollisionObject &attached_obj, moveit_msgs::PlanningScene &planning_scene_msg, ros::Publisher &planning_scene_diff_publisher)
Add a collision object to the planning scene.
Definition: shadow_utils.cpp:185