Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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_msgs/GeneralIOState.h"
00032 #include "sr_ronex_utilities/sr_ronex_utilities.hpp"
00033
00034
00035
00039 class SrRonexFindGeneralIOModule
00040 {
00041 public:
00042 SrRonexFindGeneralIOModule() {}
00043 ~SrRonexFindGeneralIOModule() {}
00044
00045 public:
00053 bool get_path_( const short unsigned int& ronex_id_as_int, std::string& path )
00054 {
00055 std::string ronex_id = this->to_string_(ronex_id_as_int);
00056
00057
00058 ros::Rate loop_rate(10);
00059 std::string param;
00060 while ( ros::param::get("/ronex/devices/0/ronex_id", param ) == false )
00061 {
00062 ROS_INFO_STREAM( "Waiting for General I/O module to be loaded properly.\n" );
00063 loop_rate.sleep();
00064 }
00065
00066
00067
00068 int ronex_parameter_id = ronex::get_ronex_param_id(ronex_id);
00069 if ( ronex_parameter_id == -1 )
00070 {
00071 ROS_ERROR_STREAM( "Did not find the General I/O module with ronex_id " << ronex_id << ".\n" );
00072 return false;
00073 }
00074
00075
00076
00077
00078 std::string path_key = ronex::get_ronex_devices_string( ronex_parameter_id, std::string("path") );
00079 ros::param::get( path_key, path );
00080
00081 return true;
00082 }
00083
00084 private:
00091 std::string to_string_(int d)
00092 {
00093 return boost::lexical_cast<std::string>(d);
00094 }
00095 };
00096
00097
00098
00104 void generalIOState_callback(const sr_ronex_msgs::GeneralIOState::ConstPtr& msg)
00105 {
00106 const std::vector<short unsigned int> &analogue = msg->analogue;
00107 const size_t len = analogue.size();
00108 for (size_t k = 0; k < len; k++)
00109 ROS_INFO_STREAM( "analogue[" << k << "] = " << analogue[k] << "\n" );
00110 }
00111
00112
00113
00117 int main(int argc, char **argv)
00118 {
00119
00120 ros::init(argc, argv, "sr_ronex_read_analog_data");
00121
00122
00123 ros::NodeHandle n;
00124
00125
00126
00127
00128 short unsigned int ronex_id;
00129 std::cout << "Please enter the ronex id: ";
00130 std::cin >> ronex_id;
00131 std::string path;
00132 SrRonexFindGeneralIOModule findModule;
00133 if ( findModule.get_path_( ronex_id, path ) )
00134 {
00140
00141 std::string topic = path + "/state";
00142 ros::Subscriber sub = n.subscribe( topic.c_str(),
00143 1000,
00144 generalIOState_callback);
00145
00151 ros::spin();
00152 }
00153
00154 return 0;
00155 }
00156
00157