机械臂和光谱仪联动,右下角机械臂控制窗口不会触发相机采集;
This commit is contained in:
@ -3,15 +3,13 @@
|
||||
RobotArmControl::RobotArmControl(QWidget* parent): QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
robotController = new RobotController(this);
|
||||
connect(robotController, SIGNAL(commandResponse(bool, const QJsonObject)), this, SLOT(onCommandResponse(bool, const QJsonObject)));
|
||||
|
||||
robotController = new RobotController(this);
|
||||
|
||||
connect(ui.get_task_list_btn, SIGNAL(clicked()), this, SLOT(getTaskList()));
|
||||
connect(ui.get_pose_btn, SIGNAL(clicked()), this, SLOT(getPose()));
|
||||
connect(ui.connect2arm_btn, SIGNAL(clicked()), this, SLOT(connectRobotArm()));
|
||||
|
||||
connect(ui.execute_task_btn, SIGNAL(clicked()), this, SLOT(executeTask()));
|
||||
connect(ui.execute_task_btn, SIGNAL(clicked()), this, SLOT(executeTaskWithoutHyperImager()));
|
||||
connect(ui.pause_task_btn, SIGNAL(clicked()), this, SLOT(pauseTask()));
|
||||
connect(ui.continue_task_btn, SIGNAL(clicked()), this, SLOT(continueTask()));
|
||||
|
||||
@ -21,7 +19,6 @@ RobotArmControl::RobotArmControl(QWidget* parent): QDialog(parent)
|
||||
|
||||
m_pModel = new QStringListModel(ui.taskList_listView);
|
||||
|
||||
//<2F><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>б<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
|
||||
ui.taskList_listView->setModel(m_pModel);
|
||||
}
|
||||
|
||||
@ -41,32 +38,37 @@ void RobotArmControl::monitorRobotArm(const ECData& data)
|
||||
ui.pose_z_label->setText(QString::number(z));
|
||||
}
|
||||
|
||||
void RobotArmControl::onCommandResponse(bool success, const QJsonObject& response)
|
||||
void RobotArmControl::onCommandResponse(QString str, const QJsonObject& response)
|
||||
{
|
||||
if (success)
|
||||
//qDebug() << "response:" << response;
|
||||
|
||||
QString re;
|
||||
if (response.contains("result"))
|
||||
{
|
||||
QString re;
|
||||
if (response.contains("result"))
|
||||
{
|
||||
re = response["result"].toVariant().toString();
|
||||
ui.textEdit->append("Result: " + re);
|
||||
}
|
||||
else if (response.contains("error"))
|
||||
{
|
||||
auto errorStr = response["error"].toObject()["message"].toString();
|
||||
|
||||
ui.textEdit->append("Error: " + errorStr);
|
||||
}
|
||||
re = response["result"].toVariant().toString();
|
||||
ui.textEdit->append(str + " Result: " + re);
|
||||
}
|
||||
else if (response.contains("error"))
|
||||
{
|
||||
//auto delete11 = response["error"].toObject();
|
||||
//qDebug() << "response[\"error\"]:" << delete11;
|
||||
|
||||
auto errorStr = response["error"].toObject()["message"].toString();
|
||||
|
||||
ui.textEdit->append(str + " Error: " + errorStr);
|
||||
}
|
||||
}
|
||||
|
||||
void RobotArmControl::getTaskList()
|
||||
{
|
||||
QString pythonScript = "D:\\PycharmProjects\\ELITE_ROBOTS\\get_jbi_filename.py";
|
||||
FileOperation* fileOperation = new FileOperation();
|
||||
string directory = fileOperation->getDirectoryOfExe();
|
||||
|
||||
QString pythonScript = QString::fromStdString(directory) + "\\get_jbi_filename.py";
|
||||
|
||||
QProcess process;
|
||||
|
||||
process.start("C:\\ProgramData\\anaconda3\\python.exe", QStringList() << pythonScript);
|
||||
process.start("python.exe", QStringList() << pythonScript);
|
||||
process.waitForFinished();
|
||||
QString output = process.readAllStandardOutput();
|
||||
|
||||
@ -94,7 +96,9 @@ void RobotArmControl::getTaskList()
|
||||
|
||||
void RobotArmControl::getPose()
|
||||
{
|
||||
robotController->getRobotPose();
|
||||
QJsonObject response;
|
||||
bool x = robotController->getRobotPose(response);
|
||||
onCommandResponse("getPose", response);
|
||||
}
|
||||
|
||||
void RobotArmControl::connectRobotArm()
|
||||
@ -103,7 +107,7 @@ void RobotArmControl::connectRobotArm()
|
||||
robotMonitor->connectToHost("192.168.1.100");
|
||||
}
|
||||
|
||||
void RobotArmControl::executeTask()
|
||||
void RobotArmControl::executeTaskWithHyperImager()
|
||||
{
|
||||
QModelIndex index = ui.taskList_listView->currentIndex();
|
||||
if (-1 == index.row())
|
||||
@ -114,17 +118,83 @@ void RobotArmControl::executeTask()
|
||||
}
|
||||
QString fileName = index.data(Qt::DisplayRole).toString();
|
||||
|
||||
robotController->runJbi(fileName);
|
||||
QJsonObject response;
|
||||
bool x;
|
||||
|
||||
x = robotController->checkJbiExist(fileName, response);
|
||||
onCommandResponse("checkJbiExist", response);
|
||||
if (!x)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
x = robotController->setServoStatus(1, response);
|
||||
onCommandResponse("setServoStatus", response);
|
||||
if (!x)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
x = robotController->runJbi(fileName, response, true);
|
||||
onCommandResponse("runJbi", response);
|
||||
if (!x)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void RobotArmControl::executeTaskWithoutHyperImager()
|
||||
{
|
||||
QModelIndex index = ui.taskList_listView->currentIndex();
|
||||
if (-1 == index.row())
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>û<EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>ļ<EFBFBD>
|
||||
ui.textEdit->append("Please select file on the left!");
|
||||
return;
|
||||
}
|
||||
QString fileName = index.data(Qt::DisplayRole).toString();
|
||||
|
||||
QJsonObject response;
|
||||
bool x;
|
||||
|
||||
x = robotController->checkJbiExist(fileName, response);
|
||||
onCommandResponse("checkJbiExist", response);
|
||||
if (!x)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
x = robotController->setServoStatus(1, response);
|
||||
onCommandResponse("setServoStatus", response);
|
||||
if (!x)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
x = robotController->runJbi(fileName, response, false);
|
||||
onCommandResponse("runJbi", response);
|
||||
if (!x)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void RobotArmControl::pauseTask()
|
||||
{
|
||||
robotController->pauseTask();
|
||||
QJsonObject response;
|
||||
bool x;
|
||||
|
||||
x = robotController->pauseTask(response);
|
||||
onCommandResponse("pauseTask", response);
|
||||
}
|
||||
|
||||
void RobotArmControl::continueTask()
|
||||
{
|
||||
robotController->continueTask();
|
||||
QJsonObject response;
|
||||
bool x;
|
||||
|
||||
x = robotController->continueTask(response);
|
||||
onCommandResponse("continueTask", response);
|
||||
}
|
||||
|
||||
|
||||
@ -134,10 +204,10 @@ void RobotArmControl::continueTask()
|
||||
|
||||
RobotController::RobotController(QObject* parent) : QObject(parent), socket(new QTcpSocket(this))
|
||||
{
|
||||
connect(socket, &QTcpSocket::readyRead, this, &RobotController::onReadyRead);
|
||||
//connect(socket, &QTcpSocket::readyRead, this, &RobotController::onReadyRead);
|
||||
|
||||
timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(getPoint()));
|
||||
m_timer = new QTimer(this);
|
||||
connect(m_timer, SIGNAL(timeout()), this, SLOT(getPoint()));
|
||||
}
|
||||
|
||||
RobotController::~RobotController()
|
||||
@ -158,7 +228,6 @@ bool RobotController::connectToRobot(const QString& ip, quint16 port)
|
||||
qDebug() << "Connected successfully!";
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
void RobotController::disconnectFromRobot()
|
||||
@ -169,10 +238,97 @@ void RobotController::disconnectFromRobot()
|
||||
}
|
||||
}
|
||||
|
||||
bool RobotController::processResponse(QJsonObject response, QString& result)
|
||||
{
|
||||
//qDebug() << "response:" << response;
|
||||
|
||||
if (response.contains("result"))
|
||||
{
|
||||
result = response["result"].toVariant().toString();
|
||||
|
||||
//qDebug() << "result1:" << result;
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (response.contains("error"))
|
||||
{
|
||||
result = response["error"].toObject()["message"].toString();
|
||||
//qDebug() << "result2:" << result;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool RobotController::processResponse_getJbiState(QJsonObject response, QString& result)
|
||||
{
|
||||
//qDebug() << "response:" << response;
|
||||
|
||||
if (response.contains("result"))
|
||||
{
|
||||
QString resultStr = response["result"].toString();
|
||||
|
||||
QJsonDocument resultDoc = QJsonDocument::fromJson(resultStr.toUtf8());
|
||||
QJsonObject resultObj = resultDoc.object();
|
||||
//qDebug() << "resultObj:" << resultObj;
|
||||
|
||||
int runState = resultObj["runState"].toInt();
|
||||
//qDebug() << "runState:" << runState;
|
||||
|
||||
result = QString::number(runState);
|
||||
//qDebug() << "result:" << result;
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (response.contains("error"))
|
||||
{
|
||||
result = response["error"].toObject()["message"].toString();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void RobotController::getPoint()
|
||||
{
|
||||
getJbiState();
|
||||
getCurrentJobLine();
|
||||
QJsonObject response;
|
||||
getJbiState(response);//0 ֹͣ״̬,1 <20><>ͣ״̬,2 <20><>ͣ״̬,3 <20><><EFBFBD><EFBFBD>״̬,4 <20><><EFBFBD><EFBFBD>״̬
|
||||
QString result;
|
||||
bool x = processResponse_getJbiState(response, result);
|
||||
//qDebug() << "getJbiState:" << result;
|
||||
|
||||
if (result.toInt() != 3)
|
||||
{
|
||||
m_timer->stop();
|
||||
|
||||
m_iCurrentJbiJobLine = 0;
|
||||
m_iFileCounter = 0;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>źţ<C5BA><C5A3><EFBFBD><EFBFBD><EFBFBD>ֹͣ<CDA3>ɼ<EFBFBD>
|
||||
emit hsiRecordSignal(-1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonObject response2;
|
||||
getCurrentJobLine(response2);
|
||||
QString result2;
|
||||
bool x2 = processResponse(response2, result2);
|
||||
|
||||
int m_iCurrentJbiJobLine_tmp = result2.toInt();
|
||||
|
||||
|
||||
if (m_iCurrentJbiJobLine_tmp != m_iCurrentJbiJobLine)
|
||||
{
|
||||
m_iFileCounter++;
|
||||
|
||||
qDebug() << "Changed! CurrentJobLine:" << m_iCurrentJbiJobLine_tmp;
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>źţ<C5BA><C5A3><EFBFBD><EFBFBD><EFBFBD>ֹͣ<CDA3>ɼ<EFBFBD>
|
||||
emit hsiRecordSignal(-1);
|
||||
|
||||
m_iCurrentJbiJobLine = m_iCurrentJbiJobLine_tmp;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>źţ<C5BA><C5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ɼ<EFBFBD>
|
||||
emit hsiRecordSignal(m_iFileCounter);
|
||||
}
|
||||
}
|
||||
|
||||
void RobotController::sendCommand(const QString& cmd, const QJsonValue& params, int id)
|
||||
@ -185,95 +341,151 @@ void RobotController::sendCommand(const QString& cmd, const QJsonValue& params,
|
||||
|
||||
QJsonDocument doc(request);
|
||||
QByteArray data = doc.toJson(QJsonDocument::Compact) + "\n";
|
||||
qDebug() << "send command:" << data.constData();
|
||||
//qDebug() << "send command:" << data.constData();
|
||||
|
||||
socket->write(data);
|
||||
socket->waitForBytesWritten();
|
||||
}
|
||||
|
||||
void RobotController::onReadyRead()
|
||||
bool RobotController::onReadyRead(QJsonObject& re)
|
||||
{
|
||||
QByteArray data = socket->readAll();
|
||||
QJsonDocument doc = QJsonDocument::fromJson(data);
|
||||
if (!doc.isNull() && doc.isObject())
|
||||
{
|
||||
QJsonObject response = doc.object();
|
||||
//qDebug() << "Received all:" << response;
|
||||
re = doc.object();
|
||||
//qDebug() << "Received all:" << re;
|
||||
|
||||
if (response.contains("result"))
|
||||
if (re.contains("result"))
|
||||
{
|
||||
//qDebug() << "Received result:" << response["result"].toVariant();
|
||||
//qDebug() << "Received result:" << re["result"].toVariant();
|
||||
return true;
|
||||
}
|
||||
else if (response.contains("error"))
|
||||
else if (re.contains("error"))
|
||||
{
|
||||
//qDebug() << "Received error:" << response["error"];
|
||||
//qDebug() << "Received error:" << re["error"];
|
||||
return false;
|
||||
}
|
||||
|
||||
emit commandResponse(true, doc.object());
|
||||
//emit commandResponse(true, doc.object());
|
||||
}
|
||||
else
|
||||
{
|
||||
emit commandResponse(false, QJsonObject());
|
||||
//emit commandResponse(false, QJsonObject());
|
||||
|
||||
re = QJsonObject();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void RobotController::getRobotPose()
|
||||
bool RobotController::getRobotPose(QJsonObject& re)
|
||||
{
|
||||
sendCommand("getRobotPose");
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
void RobotController::getRobotState()
|
||||
bool RobotController::getRobotState(QJsonObject& re)
|
||||
{
|
||||
sendCommand("getRobotState");
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
void RobotController::getJbiState()
|
||||
bool RobotController::getJbiState(QJsonObject& re)
|
||||
{
|
||||
sendCommand("getJbiState");
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
void RobotController::getCurrentJobLine()
|
||||
bool RobotController::getCurrentJobLine(QJsonObject& re)
|
||||
{
|
||||
sendCommand("getCurrentJobLine");
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
void RobotController::getRobotMode()
|
||||
bool RobotController::getRobotMode(QJsonObject& re)
|
||||
{
|
||||
sendCommand("getRobotMode");
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
void RobotController::runJbi(const QString& jbiFilename)
|
||||
bool RobotController::checkJbiExist(const QString& jbiFilename, QJsonObject& re)
|
||||
{
|
||||
QJsonObject paramsRunJbi;
|
||||
paramsRunJbi["filename"] = jbiFilename;//ʹ<>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ṹ
|
||||
|
||||
QJsonObject params_set_servo_status;
|
||||
params_set_servo_status["status"] = 1;//ʹ<>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ṹ
|
||||
sendCommand("checkJbiExist", paramsRunJbi);
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
//sendCommand("checkJbiExist", paramsRunJbi);
|
||||
sendCommand("set_servo_status", params_set_servo_status);
|
||||
sendCommand("runJbi", paramsRunJbi);
|
||||
|
||||
//timer->start(1000);
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
void RobotController::pauseTask()
|
||||
bool RobotController::setServoStatus(int status, QJsonObject& re)
|
||||
{
|
||||
QJsonObject params_set_servo_status;
|
||||
params_set_servo_status["status"] = status;//ʹ<>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ṹ
|
||||
|
||||
sendCommand("set_servo_status", params_set_servo_status);
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
bool RobotController::runJbi(const QString& jbiFilename, QJsonObject& re, bool isRecordHsi)
|
||||
{
|
||||
QJsonObject paramsRunJbi;
|
||||
paramsRunJbi["filename"] = jbiFilename;//ʹ<>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ṹ
|
||||
|
||||
sendCommand("runJbi", paramsRunJbi);
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
if (isRecordHsi)
|
||||
{
|
||||
m_timer->start(1000);
|
||||
}
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
bool RobotController::pauseTask(QJsonObject& re)
|
||||
{
|
||||
sendCommand("pause");
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
void RobotController::run()
|
||||
bool RobotController::run(QJsonObject& re)
|
||||
{
|
||||
sendCommand("run");
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
void RobotController::continueTask()
|
||||
bool RobotController::continueTask(QJsonObject& re)
|
||||
{
|
||||
sendCommand("run");
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
void RobotController::setRobotPowerStatus(int status)
|
||||
bool RobotController::setRobotPowerStatus(int status, QJsonObject& re)
|
||||
{
|
||||
sendCommand("set_robot_power_status", QJsonArray{ status });
|
||||
socket->waitForReadyRead(m_iTimeout);
|
||||
|
||||
return onReadyRead(re);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user