update_publisher.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * \file
00003  *
00004  * $Id: UpdatePublisher.cpp 676 2012-04-19 18:32:07Z xlokaj03 $
00005  *
00006  * Copyright (C) Brno University of Technology
00007  *
00008  * This file is part of software developed by Robo@FIT group.
00009  *
00010  * Author: Tomas Lokaj (xlokaj03@stud.fit.vutbr.cz)
00011  * Supervised by: Michal Spanel (spanel@fit.vutbr.cz)
00012  * Date: 21/2/2012
00013  * 
00014  * This file is free software: you can redistribute it and/or modify
00015  * it under the terms of the GNU Lesser General Public License as published by
00016  * the Free Software Foundation, either version 3 of the License, or
00017  * (at your option) any later version.
00018  * 
00019  * This file is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU Lesser General Public License for more details.
00023  * 
00024  * You should have received a copy of the GNU Lesser General Public License
00025  * along with this file.  If not, see <http://www.gnu.org/licenses/>.
00026  */
00027 
00028 #include <srs_interaction_primitives/update_publisher.h>
00029 
00030 using namespace std;
00031 using namespace interactive_markers;
00032 using namespace visualization_msgs;
00033 using namespace geometry_msgs;
00034 using namespace std_msgs;
00035 
00036 
00037 namespace srs_interaction_primitives
00038 {
00039 
00040 UpdatePublisher::UpdatePublisher(std::string name, int type)
00041 {
00042   im_name_ = name;
00043   im_type_ = type;
00044 
00045   poseChangedPublisher_ = nh_.advertise<srs_interaction_primitives::PoseChanged> (BUT_PoseChanged_TOPIC(im_name_),
00046                                                                                   BUFFER_SIZE);
00047   scaleChangedPublisher_ = nh_.advertise<srs_interaction_primitives::ScaleChanged> (BUT_ScaleChanged_TOPIC(im_name_),
00048                                                                                     BUFFER_SIZE);
00049   menuClickedPublisher_ = nh_.advertise<srs_interaction_primitives::MenuClicked> (BUT_MenuClicked_TOPIC(im_name_),
00050                                                                                   BUFFER_SIZE);
00051 
00052   switch (im_type_)
00053   {
00054     case srs_interaction_primitives::PrimitiveType::BILLBOARD:
00055       movementChangedPublisher_
00056           = nh_.advertise<srs_interaction_primitives::MovementChanged> (BUT_MovementChanged_TOPIC(im_name_),
00057                                                                         BUFFER_SIZE);
00058       break;
00059     case srs_interaction_primitives::PrimitiveType::PLANE:
00060       tagChangedPublisher_ = nh_.advertise<srs_interaction_primitives::TagChanged> (BUT_TagChanged_TOPIC(im_name_),
00061                                                                                     BUFFER_SIZE);
00062       break;
00063     case srs_interaction_primitives::PrimitiveType::OBJECT:
00064       moveArmToPreGraspPublisher_
00065           = nh_.advertise<srs_interaction_primitives::MoveArmToPreGrasp> (BUT_MoveArmToPreGrasp_TOPIC(im_name_),
00066                                                                           BUFFER_SIZE);
00067       break;
00068   }
00069 }
00070 
00071 std::string UpdatePublisher::getUpdateTopic(int update_type)
00072 {
00073   std::string topic;
00074   switch (update_type)
00075   {
00076     case UPDATE_SCALE:
00077       topic = scaleChangedPublisher_.getTopic();
00078       break;
00079     case UPDATE_POSE:
00080       topic = poseChangedPublisher_.getTopic();
00081       break;
00082     case MENU_CLICKED:
00083       topic = menuClickedPublisher_.getTopic();
00084       break;
00085     case MOVEMENT_CHANGED:
00086       topic = movementChangedPublisher_.getTopic();
00087       break;
00088     case TAG_CHANGED:
00089       topic = tagChangedPublisher_.getTopic();
00090       break;
00091     case MOVE_ARM_TO_PREGRASP:
00092       topic = moveArmToPreGraspPublisher_.getTopic();
00093     default:
00094       topic = "";
00095       break;
00096   }
00097 
00098   if (topic == "")
00099     ROS_WARN("No update topic of type %d for marker of type %d!", update_type, im_type_);
00100   return topic;
00101 }
00102 
00103 void UpdatePublisher::publishScaleChanged(geometry_msgs::Vector3 new_scale, geometry_msgs::Vector3 scale_change)
00104 {
00105   srs_interaction_primitives::ScaleChanged scaleChangedMsg;
00106   scaleChangedMsg.marker_name = im_name_;
00107   scaleChangedMsg.new_scale = new_scale;
00108   scaleChangedMsg.scale_change = scale_change;
00109   scaleChangedPublisher_.publish(scaleChangedMsg);
00110 }
00111 
00112 void UpdatePublisher::publishPoseChanged(geometry_msgs::Pose new_pose, geometry_msgs::Pose pose_change)
00113 {
00114   srs_interaction_primitives::PoseChanged poseChangedMsg;
00115   poseChangedMsg.marker_name = im_name_;
00116   poseChangedMsg.new_pose = new_pose;
00117   poseChangedMsg.pose_change = pose_change;
00118   poseChangedPublisher_.publish(poseChangedMsg);
00119 }
00120 
00121 void UpdatePublisher::publishMenuClicked(std::string title, interactive_markers::MenuHandler::CheckState state)
00122 {
00123   srs_interaction_primitives::MenuClicked menuClickedMsg;
00124   menuClickedMsg.marker_name = im_name_;
00125   menuClickedMsg.menu_title = title;
00126   menuClickedMsg.state = state;
00127   menuClickedPublisher_.publish(menuClickedMsg);
00128 }
00129 
00130 void UpdatePublisher::publishMovementChanged(geometry_msgs::Quaternion new_direction,
00131                                              geometry_msgs::Quaternion direction_change, float new_velocity,
00132                                              float velocity_change)
00133 {
00134   srs_interaction_primitives::MovementChanged movementChangedMsg;
00135   movementChangedMsg.marker_name = im_name_;
00136   movementChangedMsg.new_direction = new_direction;
00137   movementChangedMsg.direction_change = direction_change;
00138   movementChangedMsg.new_velocity = new_velocity;
00139   movementChangedMsg.velocity_change = velocity_change;
00140   movementChangedPublisher_.publish(movementChangedMsg);
00141 }
00142 
00143 void UpdatePublisher::publishTagChanged(std::string new_tag)
00144 {
00145   srs_interaction_primitives::TagChanged tagChangedMsg;
00146   tagChangedMsg.marker_name = im_name_;
00147   tagChangedMsg.new_tag = new_tag;
00148   tagChangedPublisher_.publish(tagChangedMsg);
00149 }
00150 
00151 void UpdatePublisher::publishMoveArmToPreGrasp(int pos_id)
00152 {
00153   srs_interaction_primitives::MoveArmToPreGrasp msg;
00154   msg.marker_name = im_name_;
00155   msg.pos_id = pos_id;
00156   moveArmToPreGraspPublisher_.publish(msg);
00157 }
00158 
00159 }


srs_interaction_primitives
Author(s): Tomas Lokaj, Michal Spanel (spanel@fit.vutbr.cz)
autogenerated on Sun Jan 5 2014 11:47:47