Go to the documentation of this file.00001 #include <jsk_interactive_marker/interactive_marker_utils.h>
00002 #include <boost/filesystem/operations.hpp>
00003 #include <iostream>
00004 #include <stdlib.h>
00005 #include <ros/package.h>
00006
00007 using namespace boost;
00008 using namespace boost::filesystem;
00009
00010
00011 visualization_msgs::InteractiveMarker makeFingerControlMarker(const char *name, geometry_msgs::PoseStamped ps){
00012 visualization_msgs::InteractiveMarker int_marker;
00013 int_marker.name = name;
00014 int_marker.header = ps.header;
00015 int_marker.pose = ps.pose;
00016 int_marker.scale = 0.5;
00017
00018 visualization_msgs::InteractiveMarkerControl control;
00019
00020
00021 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00022 control.orientation.w = 1;
00023 control.orientation.x = 0;
00024 control.orientation.y = 0;
00025 control.orientation.z = 1;
00026
00027 int_marker.controls.push_back(control);
00028
00029 return int_marker;
00030
00031 }
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 visualization_msgs::InteractiveMarker makeSandiaHandInteractiveMarker(geometry_msgs::PoseStamped ps, std::string hand, int finger, int link){
00096 visualization_msgs::InteractiveMarker int_marker;
00097 int_marker.header = ps.header;
00098 int_marker.pose = ps.pose;
00099
00100
00101 visualization_msgs::InteractiveMarkerControl control;
00102 std::stringstream ss;
00103
00104 ss << hand << "_f" << finger << "_" << link;
00105
00106 int_marker.name = ss.str() + "Marker";
00107 int_marker.header.frame_id = ss.str();
00108
00109 std::string frame_id = "utorso";
00110 int_marker.header.frame_id = frame_id;
00111 std::cout << ss.str() << std::endl;
00112
00113
00114 switch(link){
00115 case 0:
00116 control.markers.push_back(makeSandiaFinger0Marker(frame_id));
00117 break;
00118 case 1:
00119 control.markers.push_back(makeSandiaFinger1Marker(frame_id));
00120 break;
00121 case 2:
00122 control.markers.push_back(makeSandiaFinger2Marker(frame_id));
00123 break;
00124 default:
00125 break;
00126 }
00127 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00128 int_marker.controls.push_back(control);
00129
00130 return int_marker;
00131 }
00132
00133
00134
00135 visualization_msgs::Marker makeSandiaFinger0Marker(std::string frame_id){
00136 visualization_msgs::Marker marker;
00137 marker.header.frame_id = frame_id;
00138
00139 marker.type = visualization_msgs::Marker::CYLINDER;
00140 marker.action = visualization_msgs::Marker::ADD;
00141 marker.pose.position.x = 0;
00142 marker.pose.position.y = 0;
00143 marker.pose.position.z = 0.003;
00144 marker.pose.orientation.x = 0.0;
00145 marker.pose.orientation.y = 0.0;
00146 marker.pose.orientation.z = 0.0;
00147 marker.pose.orientation.w = 1.0;
00148 marker.scale.x = 0.03;
00149 marker.scale.y = 0.03;
00150 marker.scale.z = 0.023;
00151 marker.color.a = 1.0;
00152 marker.color.r = 0.0;
00153 marker.color.g = 1.0;
00154 marker.color.b = 0.0;
00155
00156 return marker;
00157 }
00158
00159 visualization_msgs::Marker makeSandiaFinger1Marker(std::string frame_id){
00160 visualization_msgs::Marker marker;
00161 marker.header.frame_id = frame_id;
00162 marker.type = visualization_msgs::Marker::CYLINDER;
00163 marker.action = visualization_msgs::Marker::ADD;
00164 marker.pose.position.x = 0.024;
00165 marker.pose.position.y = 0;
00166 marker.pose.position.z = 0;
00167 marker.pose.orientation.x = 0.0;
00168 marker.pose.orientation.y = 1.0;
00169 marker.pose.orientation.z = 0.0;
00170 marker.pose.orientation.w = 1.0;
00171 marker.scale.x = 0.02;
00172 marker.scale.y = 0.02;
00173 marker.scale.z = 0.067;
00174 marker.color.a = 1.0;
00175 marker.color.r = 0.0;
00176 marker.color.g = 1.0;
00177 marker.color.b = 0.0;
00178
00179 return marker;
00180 }
00181
00182 visualization_msgs::Marker makeSandiaFinger2Marker(std::string frame_id){
00183 visualization_msgs::Marker marker;
00184 marker.header.frame_id = frame_id;
00185 marker.type = visualization_msgs::Marker::CYLINDER;
00186 marker.action = visualization_msgs::Marker::ADD;
00187 marker.pose.position.x = 0.024;
00188 marker.pose.position.y = 0;
00189 marker.pose.position.z = 0;
00190 marker.pose.orientation.x = 0.0;
00191 marker.pose.orientation.y = 1.0;
00192 marker.pose.orientation.z = 0.0;
00193 marker.pose.orientation.w = 1.0;
00194 marker.scale.x = 0.018;
00195 marker.scale.y = 0.018;
00196 marker.scale.z = 0.057;
00197 marker.color.a = 1.0;
00198 marker.color.r = 0.0;
00199 marker.color.g = 1.0;
00200 marker.color.b = 0.0;
00201
00202 return marker;
00203 }
00204
00205 std::string getRosPathFromModelPath(std::string path){
00206 return getRosPathFromFullPath(getFullPathFromModelPath(path));
00207 }
00208
00209 std::string getRosPathFromFullPath(std::string path){
00210 std::string ros_package_path = "";
00211 FILE* fp;
00212 char buf[1000000];
00213
00214
00215 if ((fp = popen("echo $ROS_PACKAGE_PATH", "r")) == NULL) {
00216 std::cout << "popen error" << std::endl;
00217 }
00218 while (fgets(buf, sizeof(buf), fp) != NULL) {
00219 ros_package_path += buf;
00220 }
00221 pclose(fp);
00222
00223 ros::package::V_string all_package;
00224 ros::package::getAll(all_package);
00225
00226 if( path.find("file://", 0) == 0 ){
00227 path.erase(0,7);
00228 size_t current = 0, found;
00229 while((found = path.find_first_of("/", current)) != std::string::npos){
00230 std::string search_path = std::string(path, current, found - current);
00231 current = found + 1;
00232 std::string package_path;
00233 if( ros::package::getPath(search_path) != ""){
00234 return "package://" + search_path + path.erase(0, current-1);
00235 }
00236 }
00237 }
00238
00239 return path;
00240 }
00241
00242 std::string getFullPathFromModelPath(std::string path){
00243 std::string gazebo_model_path="";
00244
00245 FILE* fp;
00246 char buf[1000000];
00247
00248
00249 if ((fp = popen("echo $GAZEBO_MODEL_PATH", "r")) == NULL) {
00250 std::cout << "popen error" << std::endl;
00251 }
00252 while (fgets(buf, sizeof(buf), fp) != NULL) {
00253 gazebo_model_path += buf;
00254 }
00255 pclose(fp);
00256 if( path.find("model://", 0) == 0 ){
00257 path.erase(0,8);
00258
00259
00260 size_t current = 0, found;
00261 while((found = gazebo_model_path.find_first_of(":", current)) != std::string::npos){
00262 std::string search_path = std::string(gazebo_model_path, current, found - current);
00263 current = found + 1;
00264 recursive_directory_iterator iter = recursive_directory_iterator(search_path);
00265 recursive_directory_iterator end = recursive_directory_iterator();
00266 for (; iter != end; ++iter) {
00267 if (is_regular_file(*iter)) {
00268 int locate = iter->path().string().find( path, 0 );
00269 if( locate != std::string::npos){
00270
00271 return "file://" + iter->path().string();
00272 }
00273 }
00274 }
00275 }
00276 }
00277 return path;
00278 }
00279
00280
00281 std::string getFilePathFromRosPath( std::string rospath){
00282 std::string path = rospath;
00283 if (path.find("package://") == 0){
00284 path.erase(0, strlen("package://"));
00285 size_t pos = path.find("/");
00286 if (pos == std::string::npos){
00287 std::cout << "Could not parse package:// format" <<std::endl;
00288 return "";
00289 }
00290 std::string package = path.substr(0, pos);
00291 path.erase(0, pos);
00292 std::string package_path = ros::package::getPath(package);
00293 if (package_path.empty())
00294 {
00295 std::cout << "Package [" + package + "] does not exist" << std::endl;
00296 }
00297
00298 path = package_path + path;
00299 }
00300 return path;
00301 }
00302
00303 geometry_msgs::Pose getPose( XmlRpc::XmlRpcValue val){
00304 geometry_msgs::Pose p;
00305 XmlRpc::XmlRpcValue pos = val["position"];
00306 p.position.x = getXmlValue(pos["x"]);
00307 p.position.y = getXmlValue(pos["y"]);
00308 p.position.z = getXmlValue(pos["z"]);
00309
00310 XmlRpc::XmlRpcValue ori = val["orientation"];
00311 p.orientation.x = getXmlValue(ori["x"]);
00312 p.orientation.y = getXmlValue(ori["y"]);
00313 p.orientation.z = getXmlValue(ori["z"]);
00314 p.orientation.w = getXmlValue(ori["w"]);
00315
00316 return p;
00317 }
00318
00319 double getXmlValue( XmlRpc::XmlRpcValue val ){
00320 switch(val.getType()){
00321 case XmlRpc::XmlRpcValue::TypeInt:
00322 return (double)((int)val);
00323 case XmlRpc::XmlRpcValue::TypeDouble:
00324 return (double)val;
00325 default:
00326 return 0;
00327 }
00328 }
00329
00330