27 char frameHeader =
' ';
28 std::istringstream frameStream(frame);
30 int frameLength = strlen(frame.c_str());
32 frameStream >> frameHeader;
33 if(frameStream.fail() || frameHeader !=
'X')
35 qDebug() <<
"Could not read frame identifier or is incorrect";
45 for(
int i = 0; i < 200; ++i)
47 float angle = 0, distance = 0;
48 frameStream >> angle >> distance;
49 angle = (angle * 360.0) / 200.0;
53 frameStream >> std::hex >>
_CRC16;
55 const char* buffer = frame.c_str();
56 int length = frameLength - 4;
60 CRC16 ^= *(
unsigned const char*)buffer++ << 8;
61 for(
int i = 0; i < 8; i++)
63 CRC16 = CRC16 & 0x8000 ? (CRC16 << 1) ^
CRC_POLYNOMIAL : CRC16 << 1;
69 qDebug() <<
"Calculated CRC16 different from read one";
109 const int speed = -30;
110 qDebug() <<
"Right motor - turn left during backward move.";
115 const int speed = -5;
116 qDebug() <<
"Right motor - turn right during backward move.";
121 const int speed = 30;
122 qDebug() <<
"Right motor - turn left during forward move.";
128 qDebug() <<
"Right motor - turn right during forward move.";
134 qDebug() <<
"Right motor - Stop.";
139 const int speed = 0.01398 * xAxis - 27.27;
140 qDebug() <<
"Right motor - turn right.";
145 const int speed = -0.01554 * xAxis + 30.0;
146 qDebug() <<
"Right motor - turn left.";
151 const int speed = -(0.01474 * yAxis - 30.3685);
152 qDebug() <<
"Right motor - move backward.";
157 const int speed = -0.01554 * yAxis + 30.0;
158 qDebug() <<
"Right motor - move forward.";
163 const int speed = xAxis + yAxis;
172 const int speed = -5;
173 qDebug() <<
"Left motor - turn left during backward move.";
178 const int speed = -30;
179 qDebug() <<
"Left motor - turn right during backward move.";
185 qDebug() <<
"Left motor - turn left during forward move.";
190 const int speed = 30;
191 qDebug() <<
"Left motor - turn right during forward move.";
197 qDebug() <<
"Left motor - Stop.";
202 const int speed = -(0.01398 * xAxis - 27.27);
203 qDebug() <<
"Left motor - turn right.";
208 const int speed = -(-0.01554 * xAxis + 30.0);
209 qDebug() <<
"Left motor - turn left.";
214 const int speed = -(0.01474 * yAxis - 30.3685);
215 qDebug() <<
"Left motor - move backward.";
220 const int speed = -0.01554 * yAxis + 30.0;
221 qDebug() <<
"Left motor - move forward.";
226 const int speed = xAxis + yAxis;
float calculateSpeedLeft(const int &xAxis, const int &yAxis)
Calculate speed value on left motor from joystick swing.
float calculateSpeedRight(const int &xAxis, const int &yAxis)
Calculate speed value on right motor from joystick swing.
float calculateAcceleration(const int &acceleration)
calculateAcceleration
Parser()
Construct new Parser object.
void changedRightMotorAcceleration(const QString &accelerationValue)
Signal emitted when parsed data of right motor acceleration is ready.
void changedLidar(const std::map< float, int > lidarData)
Signal emitted when parsed data of lidar is ready.
~Parser()
Destruct Parser object.
void changedLeftMotorGSpeed(const QString &speedValue)
Signal emitted when parsed data of left motor given speed is ready.
void changedBattery(int battery)
Signal emitted when parsed data of battery voltage is ready.
void processData()
processData
bool parseFrame(const std::string &frame)
Parse line from serial port into managed variables.
void changedRightMotorSpeed(const QString &speedValue)
Signal emitted when parsed data of right motor speed is ready.
void changedLeftMotorSpeed(const QString &speedValue)
Signal emitted when parsed data of left motor speed is ready.
void changedJoystick(const QPoint &coordinates)
Signal emitted when parsed data of joystick swing is ready.
void changedRightMotorGSpeed(const QString &speedValue)
Signal emitted when parsed data of right motor given speed is ready.
void changedLeftMotorAcceleration(const QString &accelerationValue)
Signal emitted when parsed data of left motor acceleration is ready.
std::map< float, int > _lidarData