Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include <std_msgs/String.h>
00003 #include <geometry_msgs/Vector3Stamped.h>
00004 #include <string>
00005 #include <vector>
00006
00007
00008
00009 ros::Publisher publisher;
00010 std::string tf_prefix;
00011
00012 void callback_val(const std_msgs::String::ConstPtr & msg) {
00013 std::vector<double> axis_data;
00014 std::string data=msg->data;
00015
00016 std::string value="";
00017 for(size_t i=0; i<data.length();++i){
00018 if(data[i] == ';'){
00019
00020 std::replace(value.begin(),value.end(), ',','.');
00021 axis_data.push_back(std::stof(value));
00022 value.clear();
00023 ++i;
00024 }
00025 value+=data[i];
00026 }
00027
00028 if(!value.empty()) axis_data.push_back(std::stof(value));
00029 if (axis_data.size() > 3){
00030 ROS_ERROR("HAL(VREP): Gyroscope received more than three values(axis) from vrep");
00031 axis_data.resize(3);
00032 }
00033
00034 geometry_msgs::Vector3Stamped msg_out;
00035 std_msgs::Header header;
00036 header.stamp = ros::Time::now();
00037 header.frame_id = tf_prefix + "/gyroSensors/sensor0";
00038
00039 msg_out.header = move(header);
00040 msg_out.vector.x=axis_data[0];
00041 msg_out.vector.y=axis_data[1];
00042 msg_out.vector.z=axis_data[2];
00043
00044 publisher.publish( move(msg_out));
00045 }
00046
00047 int main(int argc, char ** argv) {
00048
00049 ros::init(argc, argv, "gyroSensors");
00050
00051 ros::NodeHandle n("~");
00052
00053
00054
00055 int vrep_no = 0;
00056
00057 std::string tf_prefix_path;
00058 if (n.searchParam("tf_prefix", tf_prefix_path))
00059 {
00060 n.getParam(tf_prefix_path, tf_prefix);
00061 }
00062
00063 std::string vrep_index_path;
00064 if (n.searchParam("vrep_index", vrep_index_path))
00065 {
00066 n.getParam(vrep_index_path, vrep_no);
00067 }
00068
00069
00070 ros::Subscriber sub_val = n.subscribe("/vrep/i" + std::to_string(vrep_no) +
00071 "_Pioneer_p3dx_GyroSensor", 1000, callback_val);
00072
00073 publisher = n.advertise<geometry_msgs::Vector3Stamped>("sensor0/axis_data", 1000);
00074 ROS_INFO("HAL(VREP): Gyroscope node initialized");
00075
00076
00077 ros::spin();
00078 return 0;
00079 }