38 #include <turtlebot_arm_object_manipulation/InteractiveManipAction.h> 45 #include <moveit_msgs/CollisionObject.h> 67 turtlebot_arm_object_manipulation::InteractiveManipFeedback
feedback_;
68 turtlebot_arm_object_manipulation::InteractiveManipResult
result_;
69 turtlebot_arm_object_manipulation::InteractiveManipGoalConstPtr
goal_;
77 nh_(
"~"), server_(
"move_objects"), as_(name, false), action_name_(name)
91 ROS_INFO(
"[interactive manip] Received goal! Adding markers for objects in the word other than the table");
97 ROS_WARN(
"[interactive manip] %s: Preempted", action_name_.c_str());
103 void feedbackCb(
const InteractiveMarkerFeedbackConstPtr &feedback)
107 ROS_INFO(
"[interactive manip] Got feedback but not active!");
110 switch (feedback->event_type)
112 case visualization_msgs::InteractiveMarkerFeedback::MOUSE_DOWN:
113 ROS_INFO_STREAM(
"[interactive manip] Staging '" << feedback->marker_name <<
"' at " << feedback->pose);
114 old_pose_ = feedback->pose;
117 case visualization_msgs::InteractiveMarkerFeedback::MOUSE_UP:
118 ROS_INFO_STREAM(
"[interactive manip] Now moving '" << feedback->marker_name <<
"' to " << feedback->pose);
119 moveObject(feedback->marker_name, feedback->header, old_pose_, feedback->pose);
126 void moveObject(
const std::string& marker_name,
const std_msgs::Header& poses_header,
127 const geometry_msgs::Pose& start_pose,
const geometry_msgs::Pose& end_pose)
129 result_.header = poses_header;
130 result_.obj_name = marker_name;
131 result_.pick_pose = start_pose;
132 result_.place_pose = end_pose;
148 std::map<std::string, moveit_msgs::CollisionObject> objects =
150 for (
const std::pair<std::string, moveit_msgs::CollisionObject>& obj: objects)
152 if (obj.first !=
"table")
154 addMarker(obj.second, active);
162 bool addMarker(
const moveit_msgs::CollisionObject& obj,
bool active)
164 InteractiveMarker marker;
165 marker.header = obj.header;
166 marker.name = obj.id;
169 if (obj.mesh_poses.size() > 0)
171 marker.pose = obj.mesh_poses[0];
172 if (obj.meshes.size() > 0)
177 marker.scale = obj_size.maxCoeff();
180 marker.pose.position.z += obj_size[2]/2.0;
184 ROS_ERROR(
"[interactive manip] Collision object has no meshes");
188 else if (obj.primitive_poses.size() > 0)
190 marker.pose = obj.primitive_poses[0];
191 if (obj.primitives.size() > 0)
198 ROS_ERROR(
"[interactive manip] Collision object has no primitives");
204 ROS_ERROR(
"[interactive manip] Collision object has no mesh/primitive poses");
208 InteractiveMarkerControl control;
209 control.orientation.w = 1;
210 control.orientation.x = 0;
211 control.orientation.y = 1;
212 control.orientation.z = 0;
213 control.interaction_mode = InteractiveMarkerControl::MOVE_PLANE;
216 marker.controls.push_back(control);
218 control.markers.push_back(
makeBox(marker, 0.5, 0.5, 0.5));
219 control.markers.push_back(makeLabel(marker, 0.5, 0.5, 0.5));
220 control.always_visible =
true;
221 marker.controls.push_back(control);
224 server_.
setCallback(marker.name, boost::bind(&InteractiveManipulationServer::feedbackCb,
this, _1));
226 ROS_INFO(
"[interactive manip] Added interactive marker for object '%s' at [%s] and scale [%f]",
227 marker.name.c_str(),
mtk::pose2str3D(marker.pose).c_str(), marker.scale);
233 Marker
makeBox(InteractiveMarker &msg,
float r,
float g,
float b)
237 m.type = Marker::CUBE;
238 m.scale.x = msg.scale + (msg.scale * 0.05);
239 m.scale.y = msg.scale + (msg.scale * 0.05);
240 m.scale.z = msg.scale + (msg.scale * 0.05);
250 Marker
makeLabel(InteractiveMarker &msg,
float r,
float g,
float b)
254 m.type = Marker::TEXT_VIEW_FACING;
264 m.pose.position.z = msg.scale/2.0 + 0.025;
273 int main(
int argc,
char** argv)
276 ros::init(argc, argv,
"object_interactive_manip_action_server");
boost::shared_ptr< const Goal > acceptNewGoal()
turtlebot_arm_object_manipulation::InteractiveManipGoalConstPtr goal_
turtlebot_arm_object_manipulation::InteractiveManipFeedback feedback_
void feedbackCb(const InteractiveMarkerFeedbackConstPtr &feedback)
Marker makeBox(InteractiveMarker &msg, float r, float g, float b)
moveit::planning_interface::PlanningSceneInterface planning_scene_interface_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
geometry_msgs::Pose old_pose_
InteractiveManipulationServer(const std::string name)
std::map< std::string, moveit_msgs::CollisionObject > getObjects(const std::vector< std::string > &object_ids=std::vector< std::string >())
std::string pose2str3D(const geometry_msgs::Pose &pose)
turtlebot_arm_object_manipulation::InteractiveManipResult result_
int main(int argc, char **argv)
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
ROSCPP_DECL void spin(Spinner &spinner)
Marker makeBox(InteractiveMarker &msg)
void setPreempted(const Result &result=Result(), const std::string &text=std::string(""))
Marker makeLabel(InteractiveMarker &msg, float r, float g, float b)
bool addMarker(const moveit_msgs::CollisionObject &obj, bool active)
void registerPreemptCallback(boost::function< void()> cb)
interactive_markers::InteractiveMarkerServer server_
void insert(const visualization_msgs::InteractiveMarker &int_marker)
#define ROS_INFO_STREAM(args)
std::vector< std::string > getKnownObjectNames(bool with_type=false)
bool setCallback(const std::string &name, FeedbackCallback feedback_cb, uint8_t feedback_type=DEFAULT_FEEDBACK_CB)
actionlib::SimpleActionServer< turtlebot_arm_object_manipulation::InteractiveManipAction > as_
void registerGoalCallback(boost::function< void()> cb)
Eigen::Vector3d computeShapeExtents(const ShapeMsg &shape_msg)
void moveObject(const std::string &marker_name, const std_msgs::Header &poses_header, const geometry_msgs::Pose &start_pose, const geometry_msgs::Pose &end_pose)