165 lines
4.6 KiB
C++
165 lines
4.6 KiB
C++
#pragma once
|
||
#include <qdialog.h>
|
||
#include <QTcpSocket>
|
||
#include <QJsonDocument>
|
||
#include <QJsonObject>
|
||
#include <QJsonArray>
|
||
#include <QDebug>
|
||
#include <QThread>
|
||
#include <QNetworkProxy>
|
||
#include <QtEndian>
|
||
#include <QNetworkAccessManager>
|
||
#include <QNetworkReply>
|
||
#include <QAuthenticator>
|
||
#include <QDebug>
|
||
#include <QRegularExpression>
|
||
#include <QProcess>
|
||
#include <QStringListModel>
|
||
#include <QTimer>
|
||
|
||
#include "ui_RobotArmControl.h"
|
||
#include "fileOperation.h"
|
||
|
||
|
||
struct ECData
|
||
{
|
||
quint32 msgSize;
|
||
quint64 timeStamp;
|
||
quint8 auto_cycle;
|
||
double machinePos[8];//关节坐标
|
||
double machinePose[6];//基座坐标
|
||
double machineUserPose[6];//用户坐标
|
||
double torque[8];//关节额定力矩百分比
|
||
quint32 robotState;//机器人状态
|
||
quint32 servoReady;//伺服使能状态
|
||
quint32 can_motor_run;//同步状态
|
||
qint32 motor_speed[8];//各轴电机转速
|
||
quint32 robotMode;//机器人模式
|
||
double analog_ioInput[3];//模拟量输入口数据
|
||
double analog_ioOutput[5];//模拟量输出口数据
|
||
quint64 digital_ioInput;//数字量输入口数据的二进制形式
|
||
quint64 digital_ioOutput;//数字量输出口数据的二进制形式
|
||
quint8 collision;//碰撞报警状态
|
||
double machineFlangePose[6];//基座坐标系下的法兰盘中心位姿
|
||
double machineUserFlangePose[6];//用户坐标系下的法兰盘中心位姿
|
||
quint8 emergencyStopState;//当前是否处于急停状态
|
||
double tcpSpeed;//tcp运动速度
|
||
double joIntSpeed[8];//关节运动下各关节运动速度
|
||
double tcpAcc;//tcp加速度
|
||
double joIntAcc[8];//关节运动下各关节加速度
|
||
double joIntTemperature[6];//温度
|
||
double joIntTorque[6];//输出扭矩
|
||
double extJoIntTorques[6];//外部关节扭矩值
|
||
double exTcpForceIntool[6];//当前工具坐标系下的外部末端力/力矩估计值
|
||
quint8 dragState;//拖动使能状态
|
||
quint8 sensor_connected_state;//力控传感器连接状态
|
||
quint8 reserved;
|
||
quint32 matchingWord;
|
||
};
|
||
|
||
class EC8056 : public QObject
|
||
{
|
||
Q_OBJECT
|
||
|
||
public:
|
||
explicit EC8056(QObject* parent = nullptr);
|
||
void connectToHost(const QString& host, quint16 port= 8056);
|
||
|
||
signals:
|
||
void dataReceived(const ECData& data);
|
||
void errorOccurred(const QString& error);
|
||
|
||
private slots:
|
||
void onReadyRead();
|
||
void onSocketError(QAbstractSocket::SocketError socketError);
|
||
|
||
private:
|
||
QTcpSocket* socket;
|
||
QByteArray buffer;
|
||
|
||
double readDouble(const QByteArray& buf, int& offset);
|
||
quint64 readUInt64(const QByteArray& buf, int& offset);
|
||
quint32 readUInt32(const QByteArray& buf, int& offset);
|
||
qint32 readInt32(const QByteArray& buf, int& offset);
|
||
quint8 readUInt8(const QByteArray& buf, int& offset);
|
||
};
|
||
|
||
class RobotController : public QObject
|
||
{
|
||
Q_OBJECT
|
||
public:
|
||
explicit RobotController(QObject* parent = nullptr);
|
||
~RobotController();
|
||
|
||
bool connectToRobot(const QString& ip, quint16 port = 8055);
|
||
void disconnectFromRobot();
|
||
void sendCommand(const QString& cmd, const QJsonValue& params = QJsonArray(), int id = 1);
|
||
bool processResponse(QJsonObject response, QString& re);
|
||
bool processResponse_getJbiState(QJsonObject response, QString& result);
|
||
|
||
bool getRobotPose(QJsonObject& re);
|
||
bool getRobotState(QJsonObject& re);//停止状态 0,暂停状态 1,急停状态 2,运行状态 3,报警状态 4,碰撞状态 5
|
||
bool getJbiState(QJsonObject& re);//0 停止状态,1 暂停状态,2 急停状态,3 运行状态,4 错误状态
|
||
bool getCurrentJobLine(QJsonObject& re);
|
||
bool getRobotMode(QJsonObject& re);//示教模式 0,自动模式 1,远程模式 2
|
||
bool checkJbiExist(const QString& jbiFilename, QJsonObject& re);
|
||
bool setServoStatus(int status, QJsonObject& re);
|
||
bool runJbi(const QString& jbiFilename, QJsonObject& re, bool isRecordHsi);
|
||
bool pauseTask(QJsonObject& re);
|
||
bool run(QJsonObject& re);
|
||
bool continueTask(QJsonObject& re);
|
||
bool setRobotPowerStatus(int status, QJsonObject& re);
|
||
|
||
bool onReadyRead(QJsonObject& re);
|
||
|
||
private:
|
||
QTcpSocket* socket;
|
||
|
||
QTimer* m_timer;
|
||
int m_iTimeout = 3000;
|
||
int m_iCurrentJbiJobLine = 0;
|
||
int m_iFileCounter = 0;
|
||
|
||
signals:
|
||
void commandResponse(bool success, const QJsonObject& response);
|
||
void hsiRecordSignal(int);
|
||
|
||
private slots:
|
||
void getPoint();
|
||
};
|
||
|
||
class RobotArmControl : public QDialog
|
||
{
|
||
Q_OBJECT
|
||
|
||
public:
|
||
RobotArmControl(QWidget* parent = nullptr);
|
||
~RobotArmControl();
|
||
RobotController* robotController;
|
||
|
||
void onCommandResponse(QString str, const QJsonObject& response);
|
||
|
||
public Q_SLOTS:
|
||
|
||
void getTaskList();
|
||
void getPose();
|
||
|
||
void connectRobotArm();
|
||
void executeTaskWithHyperImager();
|
||
void executeTaskWithoutHyperImager();
|
||
void pauseTask();
|
||
void continueTask();
|
||
|
||
void monitorRobotArm(const ECData& data);
|
||
|
||
signals:
|
||
//void Opened();
|
||
//void Closed();
|
||
|
||
private:
|
||
Ui::RobotArmControl_UI ui;
|
||
|
||
EC8056* robotMonitor;
|
||
QStringListModel* m_pModel;
|
||
};
|