00001 /****************************************************************************** 00002 * \file 00003 * 00004 * $Id:$ 00005 * 00006 * Copyright (C) Brno University of Technology 00007 * 00008 * This file is part of software developed by dcgm-robotics@FIT group. 00009 * 00010 * Author: Zdenek Materna (imaterna@fit.vutbr.cz) 00011 * Supervised by: Michal Spanel (spanel@fit.vutbr.cz) 00012 * Date: 5/4/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_assisted_arm_navigation_ui/state_vis.h" 00029 00030 using namespace srs_assisted_arm_navigation_ui; 00031 00032 StateVis::StateVis() { 00033 00034 // TODO show "Set goal position" at beginning and after first interaction "Position is ok" ??? 00035 00036 ros::NodeHandle nh; 00037 00038 color_def_.r = 0.0; 00039 color_def_.g = 1.0; 00040 color_def_.b = 0.0; 00041 color_def_.a = 0.6; 00042 00043 color_err_coll_.r = 1.0; 00044 color_err_coll_.g = 0.0; 00045 color_err_coll_.b = 0.0; 00046 color_err_coll_.a = 0.6; 00047 00048 color_err_out_.r = 0.6; 00049 color_err_out_.g = 0.0; 00050 color_err_out_.b = 0.0; 00051 color_err_out_.a = 0.6; 00052 00053 m_.header.frame_id = "/rviz_cam_add"; 00054 m_.header.stamp = ros::Time::now(); 00055 m_.ns = "state_vis"; 00056 m_.id = 0; 00057 m_.type = visualization_msgs::Marker::TEXT_VIEW_FACING; 00058 m_.action = visualization_msgs::Marker::ADD; 00059 m_.pose.position.x = 0.0; 00060 m_.pose.position.y = 0.0; 00061 m_.pose.position.z = 0.2; 00062 m_.pose.orientation.x = 0.0; 00063 m_.pose.orientation.y = 0.0; 00064 m_.pose.orientation.z = 0.0; 00065 m_.pose.orientation.w = 1.0; 00066 m_.scale.z = 0.07; // specifies the height of an uppercase "A". 00067 m_.color = color_def_; 00068 m_.text = ""; 00069 m_.lifetime = ros::Duration(1.0); 00070 00071 j_.header.frame_id = "/sdh_palm_link"; 00072 j_.header.stamp = ros::Time::now(); 00073 j_.ns = "state_vis"; 00074 j_.id = 1; 00075 j_.type = visualization_msgs::Marker::TEXT_VIEW_FACING; 00076 j_.action = visualization_msgs::Marker::ADD; 00077 j_.pose.position.x = 0.0; 00078 j_.pose.position.y = 0.0; 00079 j_.pose.position.z = 0.2; 00080 j_.pose.orientation.x = 0.0; 00081 j_.pose.orientation.y = 0.0; 00082 j_.pose.orientation.z = 0.0; 00083 j_.pose.orientation.w = 1.0; 00084 j_.scale.z = 0.07; // specifies the height of an uppercase "A". 00085 j_.color = color_err_out_; 00086 j_.text = "Joints out of limits!"; 00087 j_.lifetime = ros::Duration(1.0); 00088 00089 marker_pub_ = nh.advertise<visualization_msgs::MarkerArray>("/but_arm_manip/state_vis",1); 00090 00091 // add markers... 00092 /*visualization_msgs::MarkerArray arr; 00093 arr.markers = markers_; 00094 marker_pub_.publish(arr);*/ 00095 00096 // from now we will just modify markers... 00097 //markers_[0].action = visualization_msgs::Marker::MODIFY; 00098 00099 arm_nav_state_sub_ = nh.subscribe<srs_assisted_arm_navigation_msgs::AssistedArmNavigationState>("/but_arm_manip/state",1, &StateVis::stateCallback,this); 00100 00101 ROS_INFO("Assisted arm navigation visualization initialized."); 00102 00103 } 00104 00105 StateVis::~StateVis() { 00106 00107 00108 00109 } 00110 00111 00112 void StateVis::stateCallback(const srs_assisted_arm_navigation_msgs::AssistedArmNavigationState::ConstPtr& msg) { 00113 00114 ROS_INFO_ONCE("State callback received."); 00115 00116 if (marker_pub_.getNumSubscribers() == 0) return; 00117 00118 ROS_INFO_ONCE("We have some subscriber. Hooray!"); 00119 00120 visualization_msgs::MarkerArray arr; 00121 00122 00123 if (msg->joints_out_of_limits) { 00124 00125 j_.header.stamp = ros::Time::now(); 00126 j_.color = color_err_out_; 00127 arr.markers.push_back(j_); 00128 marker_pub_.publish(arr); 00129 return; 00130 } 00131 00132 00133 if (msg->planning_started) { 00134 00135 m_.header.stamp = ros::Time::now(); 00136 00137 m_.text = "Position is fine"; 00138 m_.color = color_def_; 00139 00140 if (!msg->position_reachable) { 00141 00142 m_.text = "Position can't be reached"; 00143 m_.color = color_err_out_; 00144 00145 } 00146 00147 if (msg->position_in_collision) { 00148 00149 m_.text = "Position is in collision"; 00150 m_.color = color_err_coll_; 00151 00152 } 00153 00154 arr.markers.push_back(m_); 00155 00156 } // if planning started 00157 00158 00159 marker_pub_.publish(arr); 00160 00161 00162 00163 00164 } 00165 00166 00167 int main( int argc, char** argv ) { 00168 00169 00170 ros::init(argc, argv, "state_vis"); 00171 00172 StateVis sv; 00173 ros::spin(); 00174 00175 } 00176