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