32 void CGillAnemometer::loadConfig_sensorSpecific(
34 const std::string& iniSection)
38 configSource.
read_string(iniSection,
"COM_port_WIN",
"COM1",
true);
41 configSource.
read_string(iniSection,
"COM_port_LIN",
"/dev/tty0",
true);
44 com_bauds = configSource.
read_int(iniSection,
"COM_baudRate", 9600,
false);
46 pose_x = configSource.
read_float(iniSection,
"pose_x", 0,
true);
47 pose_y = configSource.
read_float(iniSection,
"pose_y", 0,
true);
48 pose_z = configSource.
read_float(iniSection,
"pose_z", 0,
true);
49 pose_roll = configSource.
read_float(iniSection,
"pose_roll", 0,
true);
50 pose_pitch = configSource.
read_float(iniSection,
"pose_pitch", 0,
true);
51 pose_yaw = configSource.
read_float(iniSection,
"pose_yaw", 0,
true);
57 bool CGillAnemometer::tryToOpenTheCOM()
59 if (COM.isOpen())
return true;
62 cout <<
"[CGillAnemometer] Opening " << com_port <<
" @ " << com_bauds
68 COM.setConfig(com_bauds, 0, 8, 1);
69 COM.setTimeouts(50, 1, 100, 1, 20);
74 catch (
const std::exception& e)
76 std::cerr <<
"[CGillAnemometer::tryToOpenTheCOM] Error opening or " 77 "configuring the serial port:" 85 std::cerr <<
"[CGillAnemometer::tryToOpenTheCOM] Error opening or " 86 "configuring the serial port." 96 void CGillAnemometer::doProcess()
99 if (!tryToOpenTheCOM())
102 printf(
"ERROR: No observation received from the Anemometer!\n");
108 bool have_reading =
false;
109 std::string wind_reading;
110 bool time_out =
false;
114 while (!have_reading)
124 wind_reading = COM.ReadString(500, &time_out);
127 cout <<
"[CGillAnemometer] " << com_port <<
" @ " << com_bauds
128 <<
" - measurement Timed-Out" << endl;
129 std::this_thread::sleep_for(10ms);
136 std::deque<std::string> list;
138 if (list.size() == 6)
141 int status = atoi(list.at(4).c_str());
145 std::string s_units = list.at(3);
147 std::string s_speed = list.at(2);
149 obsPtr->speed = atof(s_speed.c_str());
150 else if (s_units ==
"K")
151 obsPtr->speed = atof(s_speed.c_str()) * 1000 / 3600;
155 "ERROR: WindSonic measurement units not supported: " 161 std::string s_direction = list.at(1);
162 obsPtr->direction = atof(s_direction.c_str());
165 obsPtr->sensorLabel = m_sensorLabel;
168 pose_x, pose_y, pose_z, pose_yaw, pose_pitch, pose_roll);
169 appendObservation(obsPtr);
172 printf(
"ERROR: WindSonic error code %u\n", status);
174 else if (list.size() == 5)
178 int status = atoi(list.at(3).c_str());
182 std::string s_units = list.at(2);
184 std::string s_speed = list.at(1);
186 obsPtr->speed = atof(s_speed.c_str());
187 else if (s_units ==
"K")
188 obsPtr->speed = atof(s_speed.c_str()) * 1000 / 3600;
192 "ERROR: WindSonic measurement units not supported: " 198 obsPtr->direction = 0.0;
201 obsPtr->sensorLabel = m_sensorLabel;
204 pose_x, pose_y, pose_z, pose_yaw, pose_pitch, pose_roll);
205 appendObservation(obsPtr);
208 printf(
"ERROR: WindSonic error code %u\n", status);
213 "ERROR: Windsonic reading incorrect format: %s [%u]\n",
214 wind_reading.c_str(),
static_cast<unsigned int>(list.size()));
217 catch (
const std::exception& e)
219 std::cerr <<
"[CGillAnemometer::doProcess] Error:" << std::endl
224 std::cerr <<
"[CGillAnemometer::doProcess] Unknown Error" << std::endl;
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
#define THROW_EXCEPTION(msg)
mrpt::system::TTimeStamp getCurrentTime()
Returns the current (UTC) system time.
Contains classes for various device interfaces.
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
static Ptr Create(Args &&... args)
void tokenize(const std::string &inString, const std::string &inDelimiters, OUT_CONTAINER &outTokens, bool skipBlankTokens=true) noexcept
Tokenizes a string according to a set of delimiting characters.
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
This class allows loading and storing values and vectors of different types from a configuration text...
#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 ...