瀏覽代碼

complete tool_chassis_check

yuchuli 1 月之前
父節點
當前提交
9db9704c95

二進制
doc/工具/线控底盘检测项目.docx


二進制
doc/工具/线控底盘检测项目.pdf


+ 78 - 4
src/tool/tool_chassis_check/mainwindow.cpp

@@ -28,21 +28,29 @@ MainWindow::MainWindow(QWidget *parent)
     ui->lineEdit_brake->setText(QString::number(mfbrake,'g'));
 
     QString styleLabel =  "QLabel {"
-                                 "    background-color: rgb(10, 90, 160);"  // 背景颜色
+                                 "    background-color: rgb(72, 116, 203);"  // 背景颜色
                                  "    color: white;"               // 字体颜色
                                  "}";
     QString styleEdit =  "QLineEdit {"
-                                 "    background-color: rgb(0, 160, 50);"  // 背景颜色
+                                 "    background-color: rgb(90, 141, 52);"  // 背景颜色
                                  "    color: white;"               // 字体颜色
                                  "}";
     QString styleCheck =  "QCheckBox {"
-                                 "    background-color: rgb(0, 160, 50);"  // 背景颜色
+                                 "    background-color: rgb(90, 141, 52);"  // 背景颜色
                                  "    color: white;"               // 字体颜色
                                  "}";
+
+    QString styleMainWindow =  "QMainWindow {"
+                                 "    background-color: rgb(223, 226, 241);"  // 背景颜色
+                                 "}";
     ui->label_1->setStyleSheet(styleLabel);
     ui->label_2->setStyleSheet(styleLabel);
     ui->label_3->setStyleSheet(styleLabel);
     ui->label_4->setStyleSheet(styleLabel);
+    ui->label_1->setAlignment(Qt::AlignCenter);
+    ui->label_2->setAlignment(Qt::AlignCenter);
+    ui->label_3->setAlignment(Qt::AlignCenter);
+    ui->label_4->setAlignment(Qt::AlignCenter);
 
     ui->checkBox_left->setStyleSheet(styleCheck);
     ui->checkBox_right->setStyleSheet(styleCheck);
@@ -51,14 +59,28 @@ MainWindow::MainWindow(QWidget *parent)
     ui->lineEdit_drive->setStyleSheet(styleEdit);
     ui->lineEdit_brake->setStyleSheet(styleEdit);
 
+    setStyleSheet(styleMainWindow);
+
     updatevalue();
 
+    mpadecision = iv::modulecomm::RegisterSend("deciton",1000,1);
+
+    mbthreadrun = true;
+    mpthreadsend = new std::thread(&MainWindow::threadsend,this);
+
+    mpTimer =new QTimer(this);
+    connect(mpTimer,SIGNAL(timeout()),this,SLOT(onTimer()));
+    mpTimer->start(10);
+
     setWindowTitle(tr("线控底盘检测项目"));
 
 }
 
 MainWindow::~MainWindow()
 {
+    mbthreadrun = false;
+    mpthreadsend->join();
+    iv::modulecomm::Unregister(mpadecision);
     delete ui;
 }
 
@@ -116,7 +138,7 @@ void MainWindow::updatevalue()
 {
     const double MAXWHEEL = 430.0;
     const double MINWHEEL = -430.0;
-    const double MAXTORQUE = 100;
+    const double MAXTORQUE = 260;
     const double MAXBRAKE = -3.0;
 
     if(ui->checkBox_left->isChecked())mbleft = true;
@@ -166,3 +188,55 @@ void MainWindow::updatevalue()
              mbleft,mbright,mfwheel,mftorque,mfbrake);
     mpLabelInfo->setText(strout);
 }
+
+void MainWindow::onTimer()
+{
+    static int ntorquebig = 0;
+    if(mftorque>30)ntorquebig++;
+    else ntorquebig = 0;
+    if(ntorquebig>1000)
+    {
+        ui->lineEdit_drive->setText("0");
+        updatevalue();
+    }
+}
+
+void MainWindow::threadsend()
+{
+    while(mbthreadrun)
+    {
+        iv::brain::decition xdecition;
+        if(mftorque>0)
+            xdecition.set_accelerator(0.1);
+        else
+            xdecition.set_accelerator(0.0);
+        xdecition.set_brake(mfbrake);
+        xdecition.set_leftlamp(mbleft);
+        xdecition.set_rightlamp(mbright);
+        xdecition.set_speed(3);
+        xdecition.set_wheelangle(mfwheel);
+        xdecition.set_wheelspeed(300);
+        xdecition.set_torque(mftorque);
+        xdecition.set_mode(1);
+        xdecition.set_gear(1);
+        xdecition.set_handbrake(0);
+        xdecition.set_grade(1);
+        xdecition.set_engine(0);
+        xdecition.set_brakelamp(false);
+        xdecition.set_ttc(15);
+        xdecition.set_roof_light(0);
+        xdecition.set_home_light(0);
+        xdecition.set_door(0);
+        xdecition.set_dippedlight(0);
+
+        int nbytesize = (int)xdecition.ByteSize();
+        std::shared_ptr<char> pstr_ptr = std::shared_ptr<char>(new char[nbytesize]);
+        if(!xdecition.SerializeToArray(pstr_ptr.get(),nbytesize))
+        {
+            std::cout<<" ctrlcmd2decition::ListenCtrlCmd Serialize Fail. "<<std::endl;
+            return;
+        }
+        iv::modulecomm::ModuleSendMsg(mpadecision,pstr_ptr.get(),nbytesize);
+        std::this_thread::sleep_for(std::chrono::milliseconds(10));
+    }
+}

+ 16 - 0
src/tool/tool_chassis_check/mainwindow.h

@@ -4,6 +4,13 @@
 #include <QMainWindow>
 #include <QLabel>
 #include <QKeyEvent>
+#include <QTimer>
+
+#include <thread>
+
+#include "decition.pb.h"
+
+#include "modulecomm.h"
 
 QT_BEGIN_NAMESPACE
 namespace Ui { class MainWindow; }
@@ -32,6 +39,8 @@ private slots:
 
     void on_lineEdit_brake_returnPressed();
 
+    void onTimer();
+
 public:
     void keyPressEvent(QKeyEvent *event) override;
 
@@ -43,6 +52,7 @@ private:
 
 private:
     void updatevalue();
+    void threadsend();
 
 private:
     bool mbleft  = false;
@@ -50,5 +60,11 @@ private:
     double mfwheel = 0.0;
     double mftorque = 0.0;
     double mfbrake = 0.0;
+
+    void * mpadecision;
+
+    std::thread * mpthreadsend;
+    bool mbthreadrun;
+    QTimer * mpTimer;
 };
 #endif // MAINWINDOW_H

+ 12 - 12
src/tool/tool_chassis_check/mainwindow.ui

@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>445</width>
+    <width>501</width>
     <height>338</height>
    </rect>
   </property>
@@ -17,7 +17,7 @@
    <widget class="QLabel" name="label_1">
     <property name="geometry">
      <rect>
-      <x>100</x>
+      <x>131</x>
       <y>80</y>
       <width>80</width>
       <height>41</height>
@@ -30,7 +30,7 @@
    <widget class="QLabel" name="label_2">
     <property name="geometry">
      <rect>
-      <x>100</x>
+      <x>131</x>
       <y>130</y>
       <width>80</width>
       <height>41</height>
@@ -43,7 +43,7 @@
    <widget class="QLabel" name="label_3">
     <property name="geometry">
      <rect>
-      <x>100</x>
+      <x>131</x>
       <y>180</y>
       <width>80</width>
       <height>41</height>
@@ -56,7 +56,7 @@
    <widget class="QLabel" name="label_4">
     <property name="geometry">
      <rect>
-      <x>100</x>
+      <x>131</x>
       <y>230</y>
       <width>80</width>
       <height>41</height>
@@ -69,7 +69,7 @@
    <widget class="QLabel" name="label_5">
     <property name="geometry">
      <rect>
-      <x>133</x>
+      <x>164</x>
       <y>20</y>
       <width>210</width>
       <height>61</height>
@@ -89,7 +89,7 @@
    <widget class="QCheckBox" name="checkBox_left">
     <property name="geometry">
      <rect>
-      <x>210</x>
+      <x>241</x>
       <y>80</y>
       <width>51</width>
       <height>41</height>
@@ -102,7 +102,7 @@
    <widget class="QCheckBox" name="checkBox_right">
     <property name="geometry">
      <rect>
-      <x>280</x>
+      <x>311</x>
       <y>80</y>
       <width>51</width>
       <height>41</height>
@@ -115,7 +115,7 @@
    <widget class="QLineEdit" name="lineEdit_wheel">
     <property name="geometry">
      <rect>
-      <x>210</x>
+      <x>241</x>
       <y>130</y>
       <width>121</width>
       <height>41</height>
@@ -125,7 +125,7 @@
    <widget class="QLineEdit" name="lineEdit_drive">
     <property name="geometry">
      <rect>
-      <x>210</x>
+      <x>241</x>
       <y>180</y>
       <width>121</width>
       <height>41</height>
@@ -135,7 +135,7 @@
    <widget class="QLineEdit" name="lineEdit_brake">
     <property name="geometry">
      <rect>
-      <x>210</x>
+      <x>241</x>
       <y>230</y>
       <width>121</width>
       <height>41</height>
@@ -148,7 +148,7 @@
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>445</width>
+     <width>501</width>
      <height>28</height>
     </rect>
    </property>

+ 10 - 0
src/tool/tool_chassis_check/tool_chassis_check.pro

@@ -16,10 +16,12 @@ DEFINES += QT_DEPRECATED_WARNINGS
 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
 
 SOURCES += \
+    ../../include/msgtype/decition.pb.cc \
     main.cpp \
     mainwindow.cpp
 
 HEADERS += \
+    ../../include/msgtype/decition.pb.h \
     mainwindow.h
 
 FORMS += \
@@ -29,3 +31,11 @@ FORMS += \
 qnx: target.path = /tmp/$${TARGET}/bin
 else: unix:!android: target.path = /opt/$${TARGET}/bin
 !isEmpty(target.path): INSTALLS += target
+
+!include(../../../include/common.pri ) {
+    error( "Couldn't find the common.pri file!" )
+}
+
+!include(../../../include/ivprotobuf.pri ) {
+    error( "Couldn't find the ivprotobuf.pri file!" )
+}