clickable_positions_action_server.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * \file
00003  *
00004  * Copyright (C) Brno University of Technology
00005  *
00006  * This file is part of software developed by Robo@FIT group.
00007  *
00008  * Author: Tomas Lokaj (xlokaj03@stud.fit.vutbr.cz)
00009  * Supervised by: Michal Spanel (spanel@fit.vutbr.cz)
00010  * Date: 12/09/2012
00011  *
00012  * This file is free software: you can redistribute it and/or modify
00013  * it under the terms of the GNU Lesser General Public License as published by
00014  * the Free Software Foundation, either version 3 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This file is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU Lesser General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU Lesser General Public License
00023  * along with this file.  If not, see <http://www.gnu.org/licenses/>.
00024  */
00025 
00026 #include <ros/ros.h>
00027 #include <srs_interaction_primitives/ClickablePositionsAction.h>
00028 #include <srs_interaction_primitives/ClickablePositions.h>
00029 #include <srs_interaction_primitives/topics_list.h>
00030 #include <srs_interaction_primitives/services_list.h>
00031 #include <actionlib/server/simple_action_server.h>
00032 #include <map>
00033 
00034 class ClickablePositionsAction
00035 {
00036 public:
00037 
00038   ClickablePositionsAction(std::string name) :
00039       as_(nh_, name, false), action_name_(name)
00040   {
00041     //register the goal and feeback callbacks
00042     as_.registerGoalCallback(boost::bind(&ClickablePositionsAction::goalCB, this));
00043     as_.registerPreemptCallback(boost::bind(&ClickablePositionsAction::preemptCB, this));
00044     as_.start();
00045 
00046     clickable_positions_client_ = nh_.serviceClient<srs_interaction_primitives::ClickablePositions>(
00047         srs_interaction_primitives::ClickablePositions_SRV);
00048 
00049     ROS_INFO("Clickable Positions Action Server ready");
00050   }
00051 
00052   ~ClickablePositionsAction(void)
00053   {
00054   }
00055 
00056   void goalCB()
00057   {
00058     // accept the new goal
00059     ROS_INFO("New goal");
00060     goal_ = as_.acceptNewGoal();
00061 
00062     std::string topic_suffix = BUT_PositionClicked_TOPIC(goal_->topic_suffix);
00063     position_clicked_subscriber_ = nh_.subscribe(topic_suffix, 1, &ClickablePositionsAction::positionClickedCallback, this);
00064 
00065     srs_interaction_primitives::ClickablePositions srv;
00066     srv.request.color = goal_->color;
00067     srv.request.frame_id = goal_->frame_id;
00068     srv.request.positions = goal_->positions;
00069     srv.request.radius = goal_->radius;
00070     srv.request.topic_suffix = goal_->topic_suffix;
00071 
00072     ros::service::waitForService(srs_interaction_primitives::ClickablePositions_SRV);
00073 
00074     if (clickable_positions_client_.call(srv))
00075     {
00076 
00077     }
00078     else
00079     {
00080       ROS_ERROR("Clickable positions not added");
00081       as_.setAborted();
00082     }
00083 
00084   }
00085 
00086   void preemptCB()
00087   {
00088     ROS_INFO("%s: Preempted", action_name_.c_str());
00089     // set the action state to preempted
00090     as_.setPreempted();
00091   }
00092 
00093   void positionClickedCallback(const srs_interaction_primitives::PositionClickedPtr &update)
00094   {
00095     result_.clicked_position = update->position;
00096     as_.publishFeedback(feedback_);
00097   }
00098 
00099 protected:
00100   ros::NodeHandle nh_;
00101   ros::ServiceClient clickable_positions_client_;
00102   ros::Subscriber position_clicked_subscriber_;
00103   std::string action_name_;
00104   actionlib::SimpleActionServer<srs_interaction_primitives::ClickablePositionsAction> as_;
00105   srs_interaction_primitives::ClickablePositionsGoalConstPtr goal_;
00106   srs_interaction_primitives::ClickablePositionsFeedback feedback_;
00107   srs_interaction_primitives::ClickablePositionsResult result_;
00108 
00109 };
00110 
00111 int main(int argc, char** argv)
00112 {
00113   ros::init(argc, argv, "clickable_positions_action_server");
00114 
00115   ClickablePositionsAction clickable_positions("clickable_positions_server");
00116   ros::spin();
00117 
00118   return 0;
00119 }


srs_interaction_primitives
Author(s): Tomas Lokaj, Michal Spanel (spanel@fit.vutbr.cz)
autogenerated on Mon Oct 6 2014 07:55:11