Go to the documentation of this file.00001 #include <carl_interactive_manipulation/create_parking_spots.h>
00002
00006 int main(int argc, char** argv)
00007 {
00008 ros::init(argc,argv,"create_parking_spots");
00009
00010 CreateParkingSpots parkingSpots;
00011
00012 ros::spin();
00013
00014 return EXIT_SUCCESS;
00015 }
00016
00017 CreateParkingSpots::CreateParkingSpots() : client_("move_base",true),server_("parking_markers")
00018 {
00019 ROS_INFO("waiting for server...");
00020
00021 bool status = client_.waitForServer();
00022 if (!status){
00023 ROS_INFO("Couldn't connect in time...");
00024 }
00025 else
00026 {
00027
00028 ROS_INFO("connected to server");
00029
00030 urdf::Model ilab;
00031
00032
00033 if (!ilab.initParam("/ilab_description"))
00034 {
00035 ROS_INFO("couldn't find /ilab_description on param server.");
00036 }
00037 else
00038 {
00039
00040 std::map<std::string, boost::shared_ptr<urdf::Link> > links = ilab.links_;
00041 std::map<std::string, boost::shared_ptr<urdf::Link> >::iterator itr;
00042
00043
00044 for(itr = links.begin(); itr != links.end(); itr++)
00045 {
00046 std::string link_name = itr->first;
00047 if (isNavGoal(link_name))
00048 {
00049 visualization_msgs::InteractiveMarker marker = createParkingSpot(link_name);
00050 ROS_INFO("creating marker %s",link_name.c_str());
00051 server_.insert(marker,boost::bind(&CreateParkingSpots::onClick, this, _1));
00052 }
00053 }
00054
00055 ROS_INFO("creating clickable nav goals...");
00056
00057
00058 server_.applyChanges();
00059
00060 }
00061 }
00062 }
00063
00064 void CreateParkingSpots::onClick(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &f)
00065 {
00066 if (f->event_type == visualization_msgs::InteractiveMarkerFeedback::MOUSE_UP){
00067
00068
00069
00070 geometry_msgs::Pose new_pose = f->pose;
00071 new_pose.orientation.x = 0;
00072 new_pose.orientation.y = 0;
00073 new_pose.orientation.z = 1;
00074 new_pose.orientation.w = 1;
00075
00076
00077 geometry_msgs::PoseStamped target_pose;
00078 target_pose.header = f->header;
00079 target_pose.pose = new_pose;
00080
00081
00082 move_base_msgs::MoveBaseGoal goal;
00083 goal.target_pose = target_pose;
00084
00085
00086 client_.sendGoal(goal);
00087
00088 bool finished_before_timeout = client_.waitForResult();
00089
00090 if (finished_before_timeout)
00091 {
00092 ROS_INFO("finished successfully!");
00093 }
00094 else
00095 {
00096 ROS_INFO("timed out! goal not reached in 30 seconds");
00097 }
00098 }
00099 }
00100
00101 bool CreateParkingSpots::isNavGoal(std::string link_name)
00102 {
00103 std::string search_param = "nav_goal_link";
00104 return link_name.find(search_param,link_name.length()-search_param.length()) != std::string::npos;
00105 }
00106
00107 visualization_msgs::InteractiveMarker CreateParkingSpots::createParkingSpot(std::string frame_id)
00108 {
00109 visualization_msgs::InteractiveMarker int_marker;
00110 int_marker.header.frame_id = frame_id;
00111 int_marker.scale = 1;
00112 int_marker.name = frame_id + "_parking_spot";
00113
00114 visualization_msgs::InteractiveMarkerControl control;
00115 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00116 control.name = "button";
00117
00118 visualization_msgs::Marker box;
00119 box.type = visualization_msgs::Marker::CUBE;
00120 box.scale.x = 0.15;
00121 box.scale.y = 0.15;
00122 box.scale.z = 0.05;
00123 box.color.r = 0;
00124 box.color.g = 0.5;
00125 box.color.b = 0.25;
00126 box.color.a = 1;
00127
00128 control.markers.push_back(box);
00129 control.always_visible = true;
00130 int_marker.controls.push_back(control);
00131
00132 return int_marker;
00133 }