Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <stdlib.h>
00038 #include <stdio.h>
00039
00040 #include <string>
00041 #include <vector>
00042
00043 #include <ros/ros.h>
00044 #include <cereal_port/CerealPort.h>
00045 #include <lse_sensor_msgs/Anemometer.h>
00046
00047 ros::Publisher wind_pub;
00048 std::string frame_id;
00049
00050 void newDataCallback(std::string * data)
00051 {
00052 data->erase(data->size()-1, 1);
00053 data->erase(0, 1);
00054
00055
00056
00057 lse_sensor_msgs::Anemometer wind_msg;
00058 int direction;
00059 float speed;
00060
00061 int first_comma = data->find_first_of(",", 0);
00062 int second_comma = data->find_first_of(",", first_comma+1);
00063 if(second_comma-first_comma==1)
00064 {
00065 sscanf(data->c_str(), "Q,,%f,M,00,", &speed);
00066 direction = 0;
00067 }
00068 else
00069 {
00070 sscanf(data->c_str(), "Q,%d,%f,M,00,", &direction, &speed);
00071 if(direction>180) direction -= 360;
00072 }
00073
00074 wind_msg.header.stamp = ros::Time::now();
00075 wind_msg.header.frame_id = frame_id.c_str();
00076
00077 wind_msg.min_wind_speed = 0.05;
00078 wind_msg.max_wind_speed = 60.00;
00079
00080 wind_msg.wind_speed = speed;
00081 wind_msg.wind_direction = direction*0.0174532925;
00082
00083 wind_pub.publish(wind_msg);
00084 }
00085
00086 int main(int argc, char** argv)
00087 {
00088 ros::init(argc, argv, "windsonic_node");
00089 ros::NodeHandle n;
00090 ros::NodeHandle pn("~");
00091
00092 wind_pub = n.advertise<lse_sensor_msgs::Anemometer>("/wind", 10);
00093
00094 std::string port;
00095 int baudrate;
00096 pn.param<std::string>("port", port, "/dev/ttyUSB0");
00097 pn.param("baudrate", baudrate, 38400);
00098 pn.param<std::string>("frame_id", frame_id, "/base_anemometer");
00099
00100 ROS_INFO("%s", frame_id.c_str());
00101
00102 cereal::CerealPort serial_port;
00103
00104 try{ serial_port.open((char*)port.c_str(), baudrate); }
00105 catch(cereal::Exception& e)
00106 {
00107 ROS_FATAL("WindSonic -- Failed to open serial port!");
00108 ROS_BREAK();
00109 }
00110 ROS_INFO("WindoSonic -- Successfully connected to the WindSonic!");
00111
00112 if( !serial_port.startReadBetweenStream(boost::bind(&newDataCallback, _1), 0x02, 0x03) )
00113 {
00114 ROS_FATAL("WindSonic -- Failed to start streaming data!");
00115 ROS_BREAK();
00116 }
00117 ROS_INFO("Windsonic -- Starting to stream data...");
00118
00119 ros::spin();
00120
00121 return(0);
00122 }
00123
00124
00125