23 char frameHeader =
' ';
24 std::istringstream frameStream(frame);
26 int frameLength = strlen(frame.c_str());
28 frameStream >> frameHeader;
29 if(frameStream.fail() || frameHeader !=
'X')
31 qDebug() <<
"Could not read frame identifier or is incorrect";
41 for(
int i = 0; i < 200; ++i)
43 float angle = 0, distance = 0;
44 frameStream >> angle >> distance;
45 angle = (angle * 360.0) / 200.0;
49 frameStream >> std::hex >>
_CRC16;
51 const char* buffer = frame.c_str();
52 int length = frameLength - 4;
56 CRC16 ^= *(
unsigned const char*)buffer++ << 8;
57 for(
int i = 0; i < 8; i++)
59 CRC16 = CRC16 & 0x8000 ? (CRC16 << 1) ^
CRC_POLYNOMIAL : CRC16 << 1;
65 qDebug() <<
"Calculated CRC16 different from read one";
89 if(value.toFloat() > 0)
93 else if(value.toFloat() < 0)
104 if(value.toFloat() > 0)
108 else if(value.toFloat() < 0)
140 const int speed = -30;
145 const int speed = -5;
150 const int speed = 30;
165 const int speed = 0.01398 * xAxis - 27.27;
170 const int speed = -0.01554 * xAxis + 30.0;
175 const int speed = -(0.01474 * yAxis - 30.3685);
180 const int speed = -0.01554 * yAxis + 30.0;
185 const int speed = xAxis + yAxis;
194 const int speed = -5;
199 const int speed = -30;
209 const int speed = 30;
219 const int speed = -(0.01398 * xAxis - 27.27);
224 const int speed = -(-0.01554 * xAxis + 30.0);
229 const int speed = -(0.01474 * yAxis - 30.3685);
234 const int speed = -0.01554 * yAxis + 30.0;
239 const int speed = xAxis + yAxis;
int _xAxis
The joystick swing on the x axis.
float calculateSpeedLeft(const int &xAxis, const int &yAxis)
Calculate speed value on the left motor from the joystick swing.
float calculateSpeedRight(const int &xAxis, const int &yAxis)
Calculate speed value on the right motor from the joystick swing.
void changedRightMotorAcceleration(const QString &accelerationValue)
A signal emitted when parsed data of the right motor acceleration is ready.
void setObstacleCloseStatus()
Set the Obstacle Close Status.
void changedLidar(const std::map< float, int > lidarData)
A signal emitted when parsed data of the lidar is ready.
void leftMotorDirection(const int &direction)
A signal emitted to pass wheel rotating direction to the openGL widget.
int _leftAcceleration
The left motor acceleration.
void changedLeftMotorGSpeed(const QString &speedValue)
A signal emitted when parsed data of the left motor given speed is ready.
void changedBattery(int battery)
A signal emitted when parsed data of the battery voltage is ready.
void processData()
Process data from a one frame.
bool parseFrame(const std::string &frame)
Parse line from the serial port into managed variables.
void changedRightMotorSpeed(const QString &speedValue)
A signal emitted when parsed data of the right motor speed is ready.
int _CRC16
Sent CRC from the device.
void changedLeftMotorSpeed(const QString &speedValue)
A signal emitted when parsed data of the left motor speed is ready.
int _battery
The battery voltage.
void changedJoystick(const QPoint &coordinates)
A signal emitted when parsed data of a joystick swing is ready.
int _leftSpeed
The left motor speed.
int _rightSpeed
The right motor speed.
void changedRightMotorGSpeed(const QString &speedValue)
A signal emitted when parsed data of the right motor given speed is ready.
void resetObstacleCloseStatus()
Reset the Obstacle Close Status.
int _rightAcceleration
The right motor acceleration.
void rightMotorDirection(const int &direction)
A signal emitted to pass wheel rotating direction to the openGL widget.
void changedLeftMotorAcceleration(const QString &accelerationValue)
A signal emitted when parsed data of the left motor acceleration is ready.
int _yAxis
The joystick swing on the y axis.
std::map< float, int > _lidarData
Data from a laser sensor.
Parser class declaration.
#define L_JOY_LIMIT_X
Joystick low limit in the x axis.
#define H_JOY_LIMIT_Y
Joystick high limit in the y axis.
#define L_JOY_LIMIT_Y
Joystick low limit in the y axis.
#define H_JOY_LIMIT_X
Joystick high limit in the x axis.