|
@@ -0,0 +1,176 @@
|
|
|
+#include "mainwindow.h"
|
|
|
+#include "ui_mainwindow.h"
|
|
|
+
|
|
|
+#include <QProcess>
|
|
|
+
|
|
|
+MainWindow::MainWindow(QWidget *parent)
|
|
|
+ : QMainWindow(parent)
|
|
|
+ , ui(new Ui::MainWindow)
|
|
|
+{
|
|
|
+ ui->setupUi(this);
|
|
|
+
|
|
|
+ apollo::cyber::Init("pilot_apollo_bridge_gui");
|
|
|
+ pilot_node = apollo::cyber::CreateNode("pilot_apollo_bridge_gui");
|
|
|
+
|
|
|
+ mcmd_writer_ = pilot_node->CreateWriter<iv::apollo::apolloctrlcmd>("apcmd");
|
|
|
+
|
|
|
+ mpthreadtest = new std::thread(&MainWindow::threadtest,this);
|
|
|
+
|
|
|
+ ui->pushButton_StartApollo->setEnabled(true);
|
|
|
+ ui->pushButton_StopApollo->setEnabled(false);
|
|
|
+
|
|
|
+ connect(&mProc,SIGNAL(readyReadStandardOutput()),this,SLOT(onReadStandardOutput()));
|
|
|
+ connect(&mProc,SIGNAL(readyReadStandardError()),this,SLOT(onReadStandardError()));
|
|
|
+
|
|
|
+ connect(&mProcNode,SIGNAL(readyReadStandardOutput()),this,SLOT(onReadStandardOutput()));
|
|
|
+ connect(&mProcNode,SIGNAL(readyReadStandardError()),this,SLOT(onReadStandardError()));
|
|
|
+ connect(&mProcNode,SIGNAL(finished(int)),this,SLOT(onProcessFinished(int)));
|
|
|
+
|
|
|
+ connect(&mProcStopDreamview,SIGNAL(readyReadStandardOutput()),this,SLOT(onReadStandardOutput()));
|
|
|
+ connect(&mProcStopDreamview,SIGNAL(readyReadStandardError()),this,SLOT(onReadStandardError()));
|
|
|
+ connect(&mProcStopDreamview,SIGNAL(finished(int)),this,SLOT(onProcessFinished(int)));
|
|
|
+
|
|
|
+ connect(&mProcStopMonitor,SIGNAL(readyReadStandardOutput()),this,SLOT(onReadStandardOutput()));
|
|
|
+ connect(&mProcStopMonitor,SIGNAL(readyReadStandardError()),this,SLOT(onReadStandardError()));
|
|
|
+ connect(&mProcStopMonitor,SIGNAL(finished(int)),this,SLOT(onProcessFinished(int)));
|
|
|
+
|
|
|
+ setWindowTitle("Pilot Apollo Bridge");
|
|
|
+}
|
|
|
+
|
|
|
+MainWindow::~MainWindow()
|
|
|
+{
|
|
|
+ if(mbMonitorRunning)
|
|
|
+ {
|
|
|
+ QProcess * pProc = new QProcess(this);
|
|
|
+ pProc->start("cyber_launch",QStringList() << "stop"<<"modules/monitor/launch/monitor.launch");
|
|
|
+ pProc->waitForFinished();
|
|
|
+ }
|
|
|
+ if(mbDreamviewRunning)
|
|
|
+ {
|
|
|
+ QProcess * pProc = new QProcess(this);
|
|
|
+ pProc->start("cyber_launch",QStringList() << "stop"<<"modules/dreamview_plus/launch/dreamview_plus.launch");
|
|
|
+ pProc->waitForFinished();
|
|
|
+ }
|
|
|
+ mbtestrun = false;
|
|
|
+ mpthreadtest->join();
|
|
|
+ delete ui;
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::threadtest()
|
|
|
+{
|
|
|
+ double wheel = -430.0;
|
|
|
+ while(mbtestrun && (apollo::cyber::OK())){
|
|
|
+
|
|
|
+ auto cmd_ptr = std::make_shared<iv::apollo::apolloctrlcmd>();
|
|
|
+ cmd_ptr->set_acceleration(0.0);
|
|
|
+ cmd_ptr->set_brake(0.0);
|
|
|
+
|
|
|
+ wheel = wheel+1.0;
|
|
|
+ cmd_ptr->set_steering_target(wheel);
|
|
|
+ if(wheel>=430.0)wheel = -430.0;
|
|
|
+
|
|
|
+ mcmd_writer_->Write(cmd_ptr);
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void MainWindow::on_pushButton_StartApollo_clicked()
|
|
|
+{
|
|
|
+
|
|
|
+// mProc.start("cd /apollo_workspace;cyber_launch start modules/dreamview_plus/launch/dreamview_plus.launch;");
|
|
|
+ mProc.setWorkingDirectory("/apollo_workspace");
|
|
|
+ mProc.start("cyber_launch",QStringList() << "start"<<"modules/dreamview_plus/launch/dreamview_plus.launch");
|
|
|
+ mbDreamviewRunning = true;
|
|
|
+
|
|
|
+ mProcMonitor.setWorkingDirectory("/apollo_workspace");
|
|
|
+ mProcMonitor.start("cyber_launch",QStringList() << "start"<<"modules/monitor/launch/monitor.launch");
|
|
|
+ mbMonitorRunning = true;
|
|
|
+
|
|
|
+ mProcNode.start("cyber_node",QStringList() <<"list");
|
|
|
+
|
|
|
+ ui->pushButton_StartApollo->setEnabled(false);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void MainWindow::onReadStandardOutput()
|
|
|
+{
|
|
|
+ QProcess * proc = (QProcess *)sender();
|
|
|
+ QByteArray ba = proc->readAllStandardOutput();
|
|
|
+
|
|
|
+ if(proc == &mProcNode)
|
|
|
+ {
|
|
|
+ QList<QByteArray> strnode = ba.split('\n');
|
|
|
+ std::cout<<strnode.size()<<std::endl;
|
|
|
+ int nodesize = static_cast<int>(strnode.size());
|
|
|
+ if(nodesize>2)
|
|
|
+ {
|
|
|
+ QString str(strnode[0]);
|
|
|
+ if(str.indexOf("Number of active nodes")>=0)
|
|
|
+ {
|
|
|
+ int i;
|
|
|
+ for(i=1;i<nodesize;i++)
|
|
|
+ {
|
|
|
+ QString strnodename(strnode[i]);
|
|
|
+ if(strnodename.indexOf("HMI")>=0)
|
|
|
+ {
|
|
|
+ // std::cout<<" find hmi "<<i<<" nodename"<<strnodename.toLatin1().data()<<std::endl;
|
|
|
+ ui->pushButton_StopApollo->setEnabled(true);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // std::cout<<"node size: "<<strnode.size()<<std::endl;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ std::cout<<"output: "<<ba.data()<<std::endl;
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::onReadStandardError()
|
|
|
+{
|
|
|
+ QProcess * proc = (QProcess *)sender();
|
|
|
+ QByteArray ba = proc->readAllStandardError();
|
|
|
+
|
|
|
+ std::cout<<"error: "<<ba.data()<<std::endl;
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::on_pushButton_StopApollo_clicked()
|
|
|
+{
|
|
|
+ mProcStopDreamview.setWorkingDirectory("/apollo_workspace");
|
|
|
+ mProcStopDreamview.start("cyber_launch",QStringList() << "stop"<<"modules/dreamview_plus/launch/dreamview_plus.launch");
|
|
|
+ mProcStopMonitor.setWorkingDirectory("/apollo_workspace");
|
|
|
+ mProcStopMonitor.start("cyber_launch",QStringList() << "stop"<<"modules/monitor/launch/monitor.launch");
|
|
|
+ mbProcStopApolloRunning = true;
|
|
|
+ ui->pushButton_StopApollo->setEnabled(false);
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::onProcessFinished(int nStatus)
|
|
|
+{
|
|
|
+ (void)nStatus;
|
|
|
+ QProcess * proc = (QProcess *)sender();
|
|
|
+ if(proc == &mProcNode)
|
|
|
+ {
|
|
|
+ std::cout<<"Process Node Finished."<<std::endl;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(proc == &mProcStopMonitor)
|
|
|
+ {
|
|
|
+ mbMonitorRunning = false;
|
|
|
+ if((mbDreamviewRunning == false)&&(mbMonitorRunning == false))
|
|
|
+ {
|
|
|
+ ui->pushButton_StartApollo->setEnabled(true);
|
|
|
+ mbProcStopApolloRunning = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(proc == &mProcStopDreamview)
|
|
|
+ {
|
|
|
+ mbDreamviewRunning = false;
|
|
|
+ if((mbDreamviewRunning == false)&&(mbMonitorRunning == false))
|
|
|
+ {
|
|
|
+ ui->pushButton_StartApollo->setEnabled(true);
|
|
|
+ mbProcStopApolloRunning = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|