sr_ronex_parse_parameter_server.cpp
Go to the documentation of this file.
00001 /*
00002 * Copyright (c) 2013, Shadow Robot Company, All rights reserved.
00003 * 
00004 * This library is free software; you can redistribute it and/or
00005 * modify it under the terms of the GNU Lesser General Public
00006 * License as published by the Free Software Foundation; either
00007 * version 3.0 of the License, or (at your option) any later version.
00008 * 
00009 * This library is distributed in the hope that it will be useful,
00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00012 * Lesser General Public License for more details.
00013 * 
00014 * You should have received a copy of the GNU Lesser General Public
00015 * License along with this library.
00016 */
00017 
00024 //-------------------------------------------------------------------------------
00025 
00026 #include <string>
00027 #include <ros/ros.h>
00028 #include <ros/console.h>
00029 #include <boost/lexical_cast.hpp>
00030 
00031 #include "sr_ronex_utilities/sr_ronex_utilities.hpp"
00032 
00033 //-------------------------------------------------------------------------------
00034 
00041 class SrRonexParseParamExample
00042 {
00043 public:
00044   SrRonexParseParamExample() 
00045   {
00046     find_general_io_modules_();
00047   }
00048   
00049   ~SrRonexParseParamExample() {}
00050   
00051 private:
00052 
00059   void find_general_io_modules_(void)
00060   {
00061     // Wait until there's at least one General I/O module.
00062     ros::Rate loop_rate(10);
00063     std::string param;
00064     while ( ros::param::get("/ronex/devices/0/ronex_id", param ) == false )
00065     {
00066       ROS_INFO_STREAM( "Waiting for General I/O module to be loaded properly.\n" );
00067       loop_rate.sleep();
00068     }
00069     
00070     std::string empty_ronex_id("");
00071     int next_ronex_parameter_id = ronex::get_ronex_param_id(empty_ronex_id);
00072     
00073     // ronex_parameter_id contains the id on which the module is stored on the parameter server.
00074     for (int ronex_parameter_id = 0; 
00075          ronex_parameter_id < next_ronex_parameter_id;
00076          ronex_parameter_id++)
00077     {  
00078       // Retrieve the values of all parameters related to the current module.
00079       std::string product_id;
00080       std::string product_id_key = ronex::get_ronex_devices_string( ronex_parameter_id, std::string("product_id") );
00081       ros::param::get( product_id_key, product_id );
00082       
00083       std::string product_name;
00084       std::string product_name_key = ronex::get_ronex_devices_string( ronex_parameter_id, std::string("product_name") );
00085       ros::param::get( product_name_key, product_name );
00086 
00087       // Path looks like "/ronex/general_io/2", where 2 is a ronex_id.
00088       std::string path;
00089       std::string path_key = ronex::get_ronex_devices_string( ronex_parameter_id, std::string("path") );
00090       ros::param::get( path_key, path );
00091       
00092       std::string ronex_id;
00093       std::string ronex_id_key = ronex::get_ronex_devices_string( ronex_parameter_id, std::string("ronex_id") );
00094       ros::param::get( ronex_id_key, ronex_id );
00095 
00096       std::string serial;
00097       std::string serial_key = ronex::get_ronex_devices_string( ronex_parameter_id, std::string("serial") );
00098       ros::param::get( serial_key, serial );
00099       
00100       ROS_INFO_STREAM( "*** General I/O module " << ronex_parameter_id << " ***" );
00101       ROS_INFO_STREAM( "product_id   = " << product_id );
00102       ROS_INFO_STREAM( "product_name = " << product_name );
00103       ROS_INFO_STREAM( "ronex_id     = " << ronex_id );
00104       ROS_INFO_STREAM( "path         = " << path );
00105       ROS_INFO_STREAM( "serial       = " << serial );
00106     }
00107   }
00108   
00115   std::string to_string_(int d)
00116   {
00117     return boost::lexical_cast<std::string>(d);
00118   }
00119 };
00120 
00121 //-------------------------------------------------------------------------------
00122 
00123 int main(int argc, char **argv)
00124 {
00125   // Initialize ROS with a unique node name.
00126   ros::init(argc, argv, "sr_ronex_parse_parameter_server");
00127   
00128   // Create a handle to this process' node. 
00129   ros::NodeHandle n;
00130   
00131   // This class demonstrates how to access the General I/O module(s) 
00132   // listed in the parameter server. 
00133   SrRonexParseParamExample example;
00134   
00135   return 0;
00136 }
00137 
00138 //-------------------------------------------------------------------------------


sr_ronex_examples
Author(s): Ugo Cupcic, Toni Oliver, Mark Pitchless, Yi Li
autogenerated on Fri Aug 28 2015 13:12:34