Browse Source

add a cyber gui program pilot_apollo_bridge_gui, not complete.

yuchuli 3 tháng trước cách đây
mục cha
commit
560c85ac21

+ 8 - 0
src/apollo/code/pilot_apollo_bridge_gui/Readme.md

@@ -0,0 +1,8 @@
+find /apollo  -name "protoc"
+
+用找到的protoc 将.proto文件转换成cpp文件
+
+比如:
+/apollo/.cache/bazel/679551712d2357b63e6e0ce858ebf90e/execroot/__main__/bazel-out/aarch64-opt-exec-2B5CBBC6/bin/external/com_google_protobuf/protoc -I=./ --cpp_out=./  *.proto
+
+

+ 11 - 0
src/apollo/code/pilot_apollo_bridge_gui/apolloctrlcmd.proto

@@ -0,0 +1,11 @@
+syntax = "proto2";
+
+package iv.apollo;
+
+message apolloctrlcmd
+{
+  required double steering_target = 1;
+  required double acceleration =2 ;//#m/s^2
+  required double brake = 3;
+ 
+};

+ 82 - 0
src/apollo/code/pilot_apollo_bridge_gui/gpsimu.proto

@@ -0,0 +1,82 @@
+syntax = "proto2";
+
+package iv.gps;
+
+message pos_accuracy_def
+{
+ optional double latstd = 1;
+ optional double lonstd = 2;
+ optional double hstd = 3;
+};
+
+message vel_accuracy_def
+{
+ optional double vnstd = 1;
+ optional double vestd = 2;
+ optional double vdstd = 3;
+};
+
+message pose_accuracy_def
+{
+ optional double rollstd = 1;
+ optional double pitchstd = 2;
+ optional double yawstd = 3;
+};
+
+message dev_temp_def
+{
+ optional double temp = 1;
+};
+
+message gps_state_def
+{
+ optional int32 pos_state = 1;
+ optional int32 satnum = 2;
+ optional int32 heading_state = 3;
+};
+
+message wheel_state_def
+{
+ optional int32 wheeldata = 1;
+};
+
+
+
+message gpsimu
+{
+ optional double pitch = 1;
+ optional double roll = 2;
+ optional double heading = 3;
+ optional double gyro_x = 4; //惯导x轴角速度
+ optional double gyro_y = 5; //惯导y轴角速度
+ optional double gyro_z = 6; //惯导z轴角速度
+ optional double acce_x = 7;
+ optional double acce_y = 8;
+ optional double acce_z = 9;
+ optional double lat = 10;
+ optional double lon = 11;
+ optional double height = 12;
+ optional double vn = 13;//北向速度
+ optional double ve = 14;//东向速度
+ optional double vd = 15;//地向速度
+ optional int32 state = 16;
+ optional int32 type = 17;
+ optional pos_accuracy_def pos_accuracy = 18;
+ optional vel_accuracy_def vel_accuracy = 19;
+ optional dev_temp_def dev_temp = 20;
+ optional gps_state_def gps_state = 21;
+ optional wheel_state_def wheel_state = 22;
+ optional double time = 23;
+ optional bytes check = 24;
+ optional pose_accuracy_def pose_accuracy = 25;
+ optional int64 msgtime = 26;
+ optional double rtk_state = 27;
+ optional double ins_state = 28;
+ optional double acc_calc = 29;
+ optional int32 satnum1 = 30;
+ optional int32 satnum2 = 31;
+ optional int32 gpsweek = 32; //from 1980-1-6 weeks.
+ optional int32 gpstime = 33; //from sunday 0:00:00 seconds.
+ optional double speed = 34;
+
+};

+ 15 - 0
src/apollo/code/pilot_apollo_bridge_gui/main.cpp

@@ -0,0 +1,15 @@
+#include "mainwindow.h"
+
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+    QApplication a(argc, argv);
+
+
+
+
+    MainWindow w;
+    w.show();
+    return a.exec();
+}

+ 176 - 0
src/apollo/code/pilot_apollo_bridge_gui/mainwindow.cpp

@@ -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;
+        }
+    }
+}

+ 67 - 0
src/apollo/code/pilot_apollo_bridge_gui/mainwindow.h

@@ -0,0 +1,67 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+#include "cyber/cyber.h"
+#include "cyber/time/rate.h"
+#include "cyber/time/time.h"
+
+#include "apolloctrlcmd.pb.h"
+#include  "gpsimu.pb.h"
+#include  "objectarray.pb.h"
+
+#include  <thread>
+
+#include <QProcess>
+
+QT_BEGIN_NAMESPACE
+namespace Ui { class MainWindow; }
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    MainWindow(QWidget *parent = nullptr);
+    ~MainWindow();
+
+private slots:
+    void on_pushButton_StartApollo_clicked();
+
+    void onReadStandardOutput();
+    void onReadStandardError();
+    void onProcessFinished(int nStatus);
+
+    void on_pushButton_StopApollo_clicked();
+
+private:
+    Ui::MainWindow *ui;
+
+private:
+    void threadtest();
+
+private:
+    std::unique_ptr<apollo::cyber::Node> pilot_node;
+
+    std::thread * mpthreadtest;
+    bool mbtestrun = true;
+
+    std::shared_ptr<apollo::cyber::Writer<iv::apollo::apolloctrlcmd>> mcmd_writer_ = nullptr;
+
+    QProcess mProc;
+    bool mbDreamviewRunning = false;
+
+    QProcess mProcMonitor;
+    bool mbMonitorRunning = false;
+
+    QProcess mProcNode;
+    bool mbProcNodeRunning;
+
+    QProcess mProcStopDreamview;
+    QProcess mProcStopMonitor;
+    bool mbProcStopApolloRunning = false;
+
+};
+#endif // MAINWINDOW_H

+ 58 - 0
src/apollo/code/pilot_apollo_bridge_gui/mainwindow.ui

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>800</width>
+    <height>600</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralwidget">
+   <widget class="QPushButton" name="pushButton_StartApollo">
+    <property name="geometry">
+     <rect>
+      <x>110</x>
+      <y>30</y>
+      <width>171</width>
+      <height>41</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Start Apollo</string>
+    </property>
+   </widget>
+   <widget class="QPushButton" name="pushButton_StopApollo">
+    <property name="geometry">
+     <rect>
+      <x>500</x>
+      <y>30</y>
+      <width>171</width>
+      <height>41</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Stop Apollo</string>
+    </property>
+   </widget>
+  </widget>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>800</width>
+     <height>28</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QStatusBar" name="statusbar"/>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 80 - 0
src/apollo/code/pilot_apollo_bridge_gui/modulecomm.h

@@ -0,0 +1,80 @@
+#ifndef MODULECOMM_H
+#define MODULECOMM_H
+
+
+//#include <QtCore/qglobal.h>
+#include <QDateTime>
+
+#include <functional>
+
+
+
+
+#if defined(MODULECOMM_LIBRARY)
+#  define MODULECOMMSHARED_EXPORT Q_DECL_EXPORT
+#else
+#  define MODULECOMMSHARED_EXPORT Q_DECL_IMPORT
+#endif
+
+
+
+
+
+
+//#include <iostream>
+//#include <thread>
+
+//using namespace std::placeholders;
+
+#ifndef IV_MODULE_FUN
+
+typedef std::function<void(const char * ,const unsigned int , const unsigned int , QDateTime * ,const char *)> ModuleFun;
+typedef void (* SMCallBack)(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
+#define IV_MODULE_FUN
+#endif
+
+namespace iv {
+namespace modulecomm {
+
+enum ModuleComm_TYPE
+{
+    ModuleComm_SHAREMEM = 0,
+    ModuleComm_INTERIOR = 1,
+    ModuleComm_FASTRTPS = 2,
+    ModuleComm_FASTRTPS_TCP = 3,
+    ModuleComm_UNDEFINE = 4
+};
+
+void *  RegisterSend(const char * strcommname);
+
+
+void *  RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount
+                                            ,ModuleComm_TYPE xmctype,const unsigned short nport);
+void *  RegisterRecv(const char * strcommname,SMCallBack pCall,
+                                            ModuleComm_TYPE xmctype ,const char * strip,const unsigned short );
+void *  RegisterRecvPlus(const char * strcommname,ModuleFun xFun,
+                                                ModuleComm_TYPE xmctype,const char * strip,const unsigned short );
+
+
+//void * MODULECOMMSHARED_EXPORT RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount
+//                                            ,ModuleComm_TYPE xmctype = ModuleComm_UNDEFINE,const unsigned short nport = 5100);
+//void * MODULECOMMSHARED_EXPORT RegisterRecv(const char * strcommname,SMCallBack pCall,
+//                                            ModuleComm_TYPE xmctype = ModuleComm_UNDEFINE,const char * strip = 0,const unsigned short = 5100);
+//void * MODULECOMMSHARED_EXPORT RegisterRecvPlus(const char * strcommname,ModuleFun xFun,
+//                                                ModuleComm_TYPE xmctype = ModuleComm_UNDEFINE,const char * strip = 0,const unsigned short = 5100);
+
+void MODULECOMMSHARED_EXPORT ModuleSendMsg(void * pHandle,const char * strdata,const unsigned int nDataLen);
+void MODULECOMMSHARED_EXPORT Unregister(void * pHandle);
+void MODULECOMMSHARED_EXPORT PauseComm(void * pHandle);
+void MODULECOMMSHARED_EXPORT ContintuComm(void * pHandle);
+
+void *  RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount);
+void *  RegisterRecv(const char * strcommname,SMCallBack pCall);
+void *  RegisterRecvPlus(const char * strcommname,ModuleFun xFun);
+
+
+}
+
+}
+
+#endif // MODULECOMM_H

+ 59 - 0
src/apollo/code/pilot_apollo_bridge_gui/objectarray.proto

@@ -0,0 +1,59 @@
+syntax = "proto2";
+
+package iv.lidar;
+
+
+message PointXYZI {
+  optional float x = 1 [default = nan];
+  optional float y = 2 [default = nan];
+  optional float z = 3 [default = nan];
+  optional float i = 4 [default = 0];
+};
+
+message PointXYZ {
+  optional float x = 1 [default = nan];
+  optional float y = 2 [default = nan];
+  optional float z = 3 [default = nan];
+};
+
+message Dimension {
+  optional float x = 1 [default = 0];
+  optional float y = 2 [default = 0];
+  optional float z = 3 [default = 0];
+};
+
+message VelXY {
+  optional float x =1 [default = 0];
+  optional float y =2 [default = 0];
+};
+
+message lidarobject
+{
+  optional PointXYZ min_point = 1;
+  optional PointXYZ max_point = 2;
+  optional PointXYZ centroid = 3;
+  optional Dimension dimensions = 4;
+  optional PointXYZ position = 5;
+  optional double angle =6;
+  optional double velocity_linear_x = 7;
+  optional double acceleration_linear_y = 8;
+  optional double timestamp = 9;
+  optional double tyaw = 10;
+  required int32 mnType = 11;
+  optional int32 id = 12;
+  optional int32 behavior_state = 13;
+  optional float score = 14;
+  optional bool velocity_reliable = 15;
+  optional bool pose_reliable = 16;
+  repeated float type_probs = 17;
+  repeated PointXYZI cloud = 18;
+  optional string type_name = 19;
+  optional VelXY vel_relative = 20; //相对速度
+};
+
+
+message objectarray
+{
+  repeated lidarobject obj = 1;
+  optional double timestamp = 2;
+};

+ 76 - 0
src/apollo/code/pilot_apollo_bridge_gui/pilot_apollo_bridge_gui.pro

@@ -0,0 +1,76 @@
+QT       += core gui
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+CONFIG += c++11
+
+# The following define makes your compiler emit warnings if you use
+# any Qt feature that has been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if it uses deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += \
+    apolloctrlcmd.pb.cc \
+    gpsimu.pb.cc \
+    main.cpp \
+    mainwindow.cpp \
+    objectarray.pb.cc
+
+HEADERS += \
+    apolloctrlcmd.pb.h \
+    gpsimu.pb.h \
+    mainwindow.h \
+    modulecomm.h \
+    objectarray.pb.h
+
+FORMS += \
+    mainwindow.ui
+
+# Default rules for deployment.
+qnx: target.path = /tmp/$${TARGET}/bin
+else: unix:!android: target.path = /opt/$${TARGET}/bin
+!isEmpty(target.path): INSTALLS += target
+
+INCLUDEPATH += /opt/apollo/neo/include
+INCLUDEPATH += /apollo_workspace/bazel-bin/external/apollo_src
+
+LIBS += -L/opt/apollo/neo/lib/cyber -lcyber -lcyber_binary -lcyber_state
+
+LIBS += /opt/apollo/neo/lib/cyber/component/*.so
+LIBS += /opt/apollo/neo/lib/cyber/context/*.so
+LIBS += /opt/apollo/neo/lib/cyber/io/*.so
+LIBS += /opt/apollo/neo/lib/cyber/logger/*.so
+LIBS += /opt/apollo/neo/lib/cyber/parameter/*.so
+LIBS += /opt/apollo/neo/lib/cyber/plugin_manager/*.so
+LIBS += /opt/apollo/neo/lib/cyber/node/*.so
+LIBS += /opt/apollo/neo/lib/cyber/blocker/*.so
+LIBS += /opt/apollo/neo/lib/cyber/class_loader/*.so
+LIBS += /opt/apollo/neo/lib/cyber/profiler/*.so
+LIBS += /opt/apollo/neo/lib/cyber/scheduler/*.so
+LIBS += /opt/apollo/neo/lib/cyber/service/*.so
+LIBS += /opt/apollo/neo/lib/cyber/statistics/*.so
+LIBS += /opt/apollo/neo/lib/cyber/task/*.so
+LIBS += /opt/apollo/neo/lib/cyber/common/*.so
+LIBS += /opt/apollo/neo/lib/cyber/service_discovery/*.so
+LIBS += /opt/apollo/neo/lib/cyber/transport/*.so
+LIBS += /opt/apollo/neo/lib/cyber/message/*.so
+LIBS += /opt/apollo/neo/lib/cyber/proto/*.so
+LIBS += /opt/apollo/neo/lib/cyber/croutine/*.so
+LIBS += /opt/apollo/neo/lib/cyber/event/*.so
+LIBS += /opt/apollo/neo/lib/cyber/time/*.so
+
+LIBS += -L/opt/apollo/neo/lib/3rd-fastdds-wrap -lfastrtps
+
+LIBS += -L/lib/aarch64-linux-gnu -lgflags -lglog
+
+LIBS += -L/usr/local/lib/ -lbvar
+
+LIBS += -L/opt/apollo/neo/lib/3rd-protobuf -lprotobuf
+
+LIBS += -L/usr/local/lib -lmodulecomm