-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoythread.h
More file actions
85 lines (67 loc) · 3.43 KB
/
joythread.h
File metadata and controls
85 lines (67 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef JOYTHREAD_H
#define JOYTHREAD_H
#include <QThread>
// for joystick
#include <windows.h>
#include <mmsystem.h>
// for socket
#include <QTcpSocket>
#include <QHostAddress>
// for Roboteq driver
#include "RoboteqDevice.h"
#include "Constants.h"
#include "ErrorCodes.h"
#define SERVER_MODE 1
#define DEVICE_MODE 2
// inheritance of QThread to get joystick position
class JoyThread : public QThread
{
Q_OBJECT
public:
quint8 joyId; // joystick id
QString comPort; // COM port
double joyMidValue = 32767; // middle joystick value of each axis
double motorMaxValue = 1000; // maximum value of RoboteQ motor command
double motorMinValue = -1000; // minimum value of RoboteQ motor command
double throttleMaxRotValue = 100; // maximum joystick value for robot's rotation
int numMotors; // number of motors
JoyThread(); // constructor
~JoyThread(); // destructor
void stop(); // to stop thread
void startJoyThread(int JoyId, QStringList leftMotors, QStringList rightMotors, QStringList indiMotors1, QStringList indiMotors2, int numMotors);
void startServerJoyThread(int JoyId, QTcpSocket* mySocket, QStringList leftMotors, QStringList rightMotors, QStringList indiMotors1, QStringList indiMotors2, int numMotors);
void startDeviceJoyThread(int JoyId, RoboteqDevice* myDevice, QStringList leftMotors, QStringList rightMotors, QStringList indiMotors1, QStringList indiMotors2, int numMotors);
void changeMotorIDs(QStringList leftMotorList, QStringList rightMotorList, QStringList indi1MotorList, QStringList indi2MotorList);
int connectMode; // switch connection server or driver
signals:
// signal for sending joystick value
void printJoyValue(const QString &x, const QString &y, const QString &z, const QString &r, const QString &bt);
// signal for sending encoder value
void printEncoderValue(const QStringList enc);
// signal for sending motor power value
void printPowerValue(const QStringList pow);
// signal for sending motor alive motor list
void setAliveMotors(const QStringList aliveMotorList);
protected:
void run(); // running process
private:
volatile bool runFlag; // flag for thread running (volatile: surpress optimization of compile)
JOYINFOEX joyInfo; // joystick interface
QTcpSocket* mySocket; // TCP socket
RoboteqDevice* myDevice; // RoboteQ device
QStringList leftMotorList; // left motor ids
QStringList rightMotorList; // right motor ids
QStringList indi1MotorList; // individual motor ids, group 1
QStringList indi2MotorList; // individual motor ids, group 2
QStringList aliveMotorList; // alive motor ID string
// limit value in then range between min and max
double JoyThread::limitValue(double value,double min,double max);
// send/receive command to/from the server or driver
QByteArray SetCommandSocket(QString cmd, quint8 id, int val);
QByteArray GetValueSocket(QString cmd, quint8 id);
QByteArray SetCommandDevice(QString cmd, quint8 id, int val);
QByteArray GetValueDevice(QString cmd, quint8 id);
QByteArray SetCommand(QString cmd, quint8 id, int val, int mode);
QByteArray GetValue(QString cmd, quint8 id, int mode);
};
#endif // JOYTHREAD_H