22 #ifndef REGILO_NEATOCONTROLLER_HPP 23 #define REGILO_NEATOCONTROLLER_HPP 27 #include <boost/algorithm/string.hpp> 29 #include "scancontroller.hpp" 30 #include "serialcontroller.hpp" 31 #include "socketcontroller.hpp" 76 virtual void setMotor(
int left,
int right,
int speed) = 0;
82 virtual std::string
getTime() = 0;
88 template<
typename ProtocolController>
92 bool testMode =
false;
93 bool ldsRotation =
false;
96 virtual inline std::string
getScanCommand()
const override {
return CMD_GET_LDS_SCAN; }
97 virtual bool parseScanData(std::istream& in,
ScanData& data)
override;
100 static std::string
ON;
133 virtual inline bool getTestMode()
const override {
return testMode; }
141 virtual void setMotor(
int left,
int right,
int speed)
override;
143 virtual std::string
getTime()
override;
152 template<
typename ProtocolController>
155 template<
typename ProtocolController>
158 template<
typename ProtocolController>
161 template<
typename ProtocolController>
164 template<
typename ProtocolController>
167 template<
typename ProtocolController>
170 template<
typename ProtocolController>
173 template<
typename ProtocolController>
176 template<
typename ProtocolController>
179 template<
typename ProtocolController>
182 this->RESPONSE_END = std::string(1, 0x1a);
185 template<
typename ProtocolController>
188 this->RESPONSE_END = std::string(1, 0x1a);
191 template<
typename ProtocolController>
194 this->RESPONSE_END = std::string(1, 0x1a);
197 template<
typename ProtocolController>
201 this->testMode = testMode;
204 template<
typename ProtocolController>
208 this->ldsRotation = ldsRotation;
211 template<
typename ProtocolController>
214 this->sendFormattedCommand(
CMD_SET_MOTOR, left, right, speed);
217 template<
typename ProtocolController>
221 double M_PI_180 = M_PI / 180.0;
224 std::getline(in, line);
225 boost::algorithm::trim(line);
227 if(line == NeatoController<ProtocolController>::LDS_SCAN_HEADER)
231 std::getline(in, line);
232 boost::algorithm::trim(line);
234 if(boost::algorithm::starts_with(line, NeatoController<ProtocolController>::LDS_SCAN_FOOTER))
236 std::vector<std::string> values;
237 boost::algorithm::split(values, line, boost::algorithm::is_any_of(
","));
244 std::vector<std::string> values;
245 boost::algorithm::split(values, line, boost::algorithm::is_any_of(
","));
248 double angle = std::stod(values.at(0)) * M_PI_180;
249 double distance = std::stod(values.at(1));
250 int intensity = std::stoi(values.at(2));
251 int errorCode = std::stoi(values.at(3));
252 bool error = (errorCode != 0);
254 if(error) distance = -1;
256 data.emplace_back(
id, angle, distance, intensity, errorCode, error);
266 template<
typename ProtocolController>
274 #endif // REGILO_NEATOCONTROLLER_HPP static std::string CMD_SET_LDS_ROTATION
A template for the setldsrotation command.
Definition: neatocontroller.hpp:106
virtual ~INeatoController()=default
Default destructor.
static std::string LDS_SCAN_HEADER
A header of the LDS scan output.
Definition: neatocontroller.hpp:102
static std::string CMD_TEST_MODE
A template for the testmode command.
Definition: neatocontroller.hpp:105
Definition: controller.hpp:35
The IScanController interface is used for all controller classes that implement scanning functionalit...
Definition: scancontroller.hpp:34
virtual std::string getScanCommand() const override
Get a string that can be used for getting a scan.
Definition: neatocontroller.hpp:96
The INeatoController interface is used for the NeatoController class.
Definition: neatocontroller.hpp:38
static std::string CMD_GET_TIME
A template for the gettime command.
Definition: neatocontroller.hpp:108
virtual void setMotor(int left, int right, int speed)=0
Set the specified motor to run in a direction at a requested speed.
static std::string CMD_GET_LDS_SCAN
A template for the getldsscan command.
Definition: neatocontroller.hpp:109
static std::string CMD_SET_MOTOR
A template for the setmotor command.
Definition: neatocontroller.hpp:107
The NeatoController class is used to communicate with the Neato robot.
Definition: neatocontroller.hpp:89
The ScanController class implements parsing of scanned laser data.
Definition: scancontroller.hpp:54
virtual bool parseScanData(std::istream &in, ScanData &data) override
Parse the raw scan data.
Definition: neatocontroller.hpp:218
virtual std::string sendCommand(const std::string &command)=0
Send a command to the device.
virtual std::string getTime()=0
Get the current scheduler time.
static std::string LDS_SCAN_FOOTER
A footer of the LDS scan output.
Definition: neatocontroller.hpp:103
The ScanData class is used to store laser data.
Definition: scandata.hpp:34
virtual void setLdsRotation(bool ldsRotation) override
Set LDS rotation on or off.
Definition: neatocontroller.hpp:205
virtual bool getTestMode() const =0
Get whether the Neato is in the test mode.
double rotationSpeed
The rotation speed (in Hz).
Definition: scandata.hpp:38
virtual void setTestMode(bool testMode) override
Set or unset the test mode.
Definition: neatocontroller.hpp:198
NeatoController()
Default constructor.
Definition: neatocontroller.hpp:180
static std::string OFF
A string that represents the OFF value.
Definition: neatocontroller.hpp:101
virtual std::string getTime() override
Get the current scheduler time.
Definition: neatocontroller.hpp:267
virtual void setTestMode(bool testMode)=0
Set or unset the test mode.
virtual bool getLdsRotation() const =0
Get whether the Neato has LDS rotation on or off.
virtual void setMotor(int left, int right, int speed) override
Set the specified motor to run in a direction at a requested speed.
Definition: neatocontroller.hpp:212
static std::string ON
A string that represents the ON value.
Definition: neatocontroller.hpp:100
virtual void setLdsRotation(bool ldsRotation)=0
Set LDS rotation on or off.
virtual bool getLdsRotation() const override
Get whether the Neato has LDS rotation on or off.
Definition: neatocontroller.hpp:137
virtual bool getTestMode() const override
Get whether the Neato is in the test mode.
Definition: neatocontroller.hpp:133