33 m_sensorLabel =
"WINDSONIC";
40 void CGillAnemometer::loadConfig_sensorSpecific(
44 #ifdef MRPT_OS_WINDOWS 45 com_port = configSource.
read_string(iniSection,
"COM_port_WIN",
"COM1",
true ) ;
47 com_port = configSource.
read_string(iniSection,
"COM_port_LIN",
"/dev/tty0",
true );
50 com_bauds = configSource.
read_int( iniSection,
"COM_baudRate",9600,
false );
52 pose_x = configSource.
read_float(iniSection,
"pose_x",0,
true);
53 pose_y = configSource.
read_float(iniSection,
"pose_y",0,
true);
54 pose_z = configSource.
read_float(iniSection,
"pose_z",0,
true);
55 pose_roll = configSource.
read_float(iniSection,
"pose_roll",0,
true);
56 pose_pitch = configSource.
read_float(iniSection,
"pose_pitch",0,
true);
57 pose_yaw = configSource.
read_float(iniSection,
"pose_yaw",0,
true);
64 bool CGillAnemometer::tryToOpenTheCOM()
69 if (m_verbose) cout <<
"[CGillAnemometer] Opening " << com_port <<
" @ " <<com_bauds << endl;
75 COM.setConfig( com_bauds, 0, 8, 1 );
77 COM.setTimeouts(50,1,100, 1,20);
84 catch (std::exception &e)
86 std::cerr <<
"[CGillAnemometer::tryToOpenTheCOM] Error opening or configuring the serial port:" << std::endl << e.what();
92 std::cerr <<
"[CGillAnemometer::tryToOpenTheCOM] Error opening or configuring the serial port." << std::endl;
101 void CGillAnemometer::doProcess()
104 if (!tryToOpenTheCOM())
107 printf(
"ERROR: No observation received from the Anemometer!\n");
112 bool have_reading =
false;
114 bool time_out =
false;
118 while (!have_reading)
128 wind_reading = COM.ReadString(500,&time_out);
131 cout <<
"[CGillAnemometer] " << com_port <<
" @ " <<com_bauds <<
" - measurement Timed-Out" << endl;
139 std::deque<std::string> list;
141 if (list.size() == 6)
144 int status = atoi(list.at(4).c_str());
152 obsPtr->speed = atof(s_speed.c_str());
153 else if (s_units ==
"K")
154 obsPtr->speed = atof(s_speed.c_str())*1000/3600;
157 printf(
"ERROR: WindSonic measurement units not supported: %s\n", s_units.c_str());
162 obsPtr->direction = atof(s_direction.c_str());
165 obsPtr->sensorLabel = m_sensorLabel;
167 obsPtr->sensorPoseOnRobot =
mrpt::poses::CPose3D(pose_x, pose_y, pose_z, pose_yaw, pose_pitch, pose_roll);
168 appendObservation(obsPtr);
171 printf(
"ERROR: WindSonic error code %u\n",
status);
173 else if (list.size() == 5)
176 int status = atoi(list.at(3).c_str());
184 obsPtr->speed = atof(s_speed.c_str());
185 else if (s_units ==
"K")
186 obsPtr->speed = atof(s_speed.c_str()) * 1000 / 3600;
189 printf(
"ERROR: WindSonic measurement units not supported: %s\n", s_units.c_str());
193 obsPtr->direction = 0.0;
196 obsPtr->sensorLabel = m_sensorLabel;
198 obsPtr->sensorPoseOnRobot =
mrpt::poses::CPose3D(pose_x, pose_y, pose_z, pose_yaw, pose_pitch, pose_roll);
199 appendObservation(obsPtr);
202 printf(
"ERROR: WindSonic error code %u\n",
status);
206 printf(
"ERROR: Windsonic reading incorrect format: %s [%u]\n", wind_reading.c_str(),
static_cast<unsigned int>(list.size()) );
210 catch (std::exception &e)
212 std::cerr <<
"[CGillAnemometer::doProcess] Error:" << std::endl << e.what();
216 std::cerr <<
"[CGillAnemometer::doProcess] Unknown Error" << std::endl;
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
static CObservationWindSensorPtr Create()
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
mrpt::system::TTimeStamp BASE_IMPEXP getCurrentTime()
Returns the current (UTC) system time.
#define THROW_EXCEPTION(msg)
Contains classes for various device interfaces.
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
This class allows loading and storing values and vectors of different types from a configuration text...
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
void BASE_IMPEXP sleep(int time_ms) MRPT_NO_THROWS
An OS-independent method for sending the current thread to "sleep" for a given period of time...
GLsizei const GLchar ** string
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
This class implements a driver for the Gill Windsonic Option 1 Anemometer The sensor is accessed via ...
void BASE_IMPEXP tokenize(const std::string &inString, const std::string &inDelimiters, std::deque< std::string > &outTokens, bool skipBlankTokens=true) MRPT_NO_THROWS
Tokenizes a string according to a set of delimiting characters.