22 #ifndef REGILO_HOKUYOCONTROLLER_HPP 23 #define REGILO_HOKUYOCONTROLLER_HPP 28 #include <boost/algorithm/string/trim.hpp> 30 #include "scancontroller.hpp" 31 #include "serialcontroller.hpp" 32 #include "socketcontroller.hpp" 57 template<
typename ProtocolController>
61 std::size_t validFromStep = 44;
62 std::size_t validToStep = 725;
63 std::size_t maxStep = 768;
64 std::size_t fromStep = 0;
65 std::size_t toStep = maxStep;
66 std::size_t clusterCount = 1;
67 double startAngle = -135 * M_PI / 180;
70 virtual inline std::string
getScanCommand()
const override {
return this->createFormattedCommand(CMD_GET_SCAN, fromStep, toStep, clusterCount); }
71 virtual bool parseScanData(std::istream& in,
ScanData& data)
override;
99 virtual std::map<std::string, std::string>
getVersionInfo()
override;
107 void setScanParameters(std::size_t fromStep, std::size_t toStep, std::size_t clusterCount);
116 template<
typename ProtocolController>
119 template<
typename ProtocolController>
122 template<
typename ProtocolController>
125 this->RESPONSE_END =
"\n\n";
128 template<
typename ProtocolController>
131 this->RESPONSE_END =
"\n\n";
134 template<
typename ProtocolController>
137 this->RESPONSE_END =
"\n\n";
140 template<
typename ProtocolController>
143 std::map<std::string, std::string> versionInfo;
145 if(ProtocolController::template sendCommand<char>(
CMD_GET_VERSION) ==
'0')
148 while(std::getline(this->deviceOutput, line))
150 if(line.empty())
continue;
152 std::size_t colonPos = line.find(
':');
153 std::string name = line.substr(0, colonPos);
154 std::string value = line.substr(colonPos + 1);
156 boost::algorithm::trim(name);
157 boost::algorithm::trim(value);
159 versionInfo[name] = value;
166 template<
typename ProtocolController>
169 if(fromStep > maxStep)
throw std::invalid_argument(
"Invalid fromStep argument.");
170 if(toStep > maxStep)
throw std::invalid_argument(
"Invalid fromStep argument.");
171 if(clusterCount > 99)
throw std::invalid_argument(
"Invalid clusterCount argument.");
172 if(fromStep > toStep)
throw std::invalid_argument(
"fromStep has to be lower than toStep.");
174 this->fromStep = fromStep;
175 this->toStep = toStep;
176 this->clusterCount = clusterCount;
179 template<
typename ProtocolController>
184 if(status !=
'0')
return false;
186 double resolution = M_PI / 512;
189 std::size_t step = fromStep - 1;
197 if(step < validFromStep || step > validToStep)
continue;
200 double angle = step * resolution + startAngle;
201 int distance = ((high -
'0') << 6) | (low -
'0');
207 errorCode = distance;
212 data.emplace_back(
id, angle, distance, -1, errorCode, error);
220 #endif // REGILO_HOKUYOCONTROLLER_HPP Definition: controller.hpp:35
The IScanController interface is used for all controller classes that implement scanning functionalit...
Definition: scancontroller.hpp:34
static std::string CMD_GET_SCAN
A command for getting a scan.
Definition: hokuyocontroller.hpp:75
static std::string CMD_GET_VERSION
A command for getting the scanner version.
Definition: hokuyocontroller.hpp:74
The IHokuyoController interface is used for the HokuyoController class.
Definition: hokuyocontroller.hpp:39
virtual std::map< std::string, std::string > getVersionInfo() override
Return information about the scanner version.
Definition: hokuyocontroller.hpp:141
virtual bool parseScanData(std::istream &in, ScanData &data) override
Parse the raw scan data.
Definition: hokuyocontroller.hpp:180
The HokuyoController class is used to communicate with the Hokuyo scanner.
Definition: hokuyocontroller.hpp:58
The ScanController class implements parsing of scanned laser data.
Definition: scancontroller.hpp:54
HokuyoController()
Default constructor.
Definition: hokuyocontroller.hpp:123
virtual std::string getScanCommand() const override
Get a string that can be used for getting a scan.
Definition: hokuyocontroller.hpp:70
The ScanData class is used to store laser data.
Definition: scandata.hpp:34
virtual std::map< std::string, std::string > getVersionInfo()=0
Return information about the scanner version.
virtual ~IHokuyoController()=default
Default destructor.
void setScanParameters(std::size_t fromStep, std::size_t toStep, std::size_t clusterCount)
Set parameters for the scan command.
Definition: hokuyocontroller.hpp:167