Browse Source

add contoller_test

yuchuli 2 months ago
parent
commit
5e4668a466

+ 11 - 0
src/tool/tool_controller_test/main.cpp

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

+ 270 - 0
src/tool/tool_controller_test/mainwindow.cpp

@@ -0,0 +1,270 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+#include <QMessageBox>
+
+MainWindow::MainWindow(QWidget *parent)
+    : QMainWindow(parent)
+    , ui(new Ui::MainWindow)
+{
+    ui->setupUi(this);
+
+    mpLabelTip = new QLabel(this);
+    mpLabelTip->setText(tr("回车确认输入"));
+    mpLabelTip->setMidLineWidth(50);
+
+    mpLabelInfo = new QLabel(this);
+    mpLabelInfo->setText(tr(""));
+    mpLabelInfo->setMidLineWidth(150);
+
+    ui->statusbar->addWidget(mpLabelTip);
+    ui->statusbar->addWidget(mpLabelInfo);
+
+    ui->checkBox_left->setChecked(mbleft);
+    ui->checkBox_right->setChecked(mbright);
+
+    ui->lineEdit_wheel->setText(QString::number(mfwheel,'g'));
+    ui->lineEdit_drive->setText(QString::number(mftorque,'g'));
+    ui->lineEdit_brake->setText(QString::number(mfbrake,'g'));
+    ui->lineEdit_speed->setText(QString::number(mfspeed,'g'));
+
+    QString styleLabel =  "QLabel {"
+                                 "    background-color: rgb(72, 116, 203);"  // 背景颜色
+                                 "    color: white;"               // 字体颜色
+                                 "}";
+    QString styleEdit =  "QLineEdit {"
+                                 "    background-color: rgb(90, 141, 52);"  // 背景颜色
+                                 "    color: white;"               // 字体颜色
+                                 "}";
+    QString styleCheck =  "QCheckBox {"
+                                 "    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_6->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->label_6->setAlignment(Qt::AlignCenter);
+
+    ui->checkBox_left->setStyleSheet(styleCheck);
+    ui->checkBox_right->setStyleSheet(styleCheck);
+
+    ui->lineEdit_wheel->setStyleSheet(styleEdit);
+    ui->lineEdit_drive->setStyleSheet(styleEdit);
+    ui->lineEdit_brake->setStyleSheet(styleEdit);
+    ui->lineEdit_speed->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;
+}
+
+
+void MainWindow::on_checkBox_left_stateChanged(int arg1)
+{
+    (void)arg1;
+}
+
+void MainWindow::on_checkBox_right_stateChanged(int arg1)
+{
+    (void)arg1;
+}
+
+void MainWindow::on_checkBox_left_clicked()
+{
+    if(ui->checkBox_left->isChecked())
+    {
+        if(ui->checkBox_right->isChecked())ui->checkBox_right->setChecked(false);
+    }
+    updatevalue();
+}
+
+void MainWindow::on_checkBox_right_clicked()
+{
+    if(ui->checkBox_right->isChecked()){
+        if(ui->checkBox_left->isChecked())ui->checkBox_left->setChecked(false);
+    }
+    updatevalue();
+}
+
+void MainWindow::keyPressEvent(QKeyEvent *event){
+    (void)event;
+    if (event->modifiers() == Qt::ControlModifier && event->key() == Qt::Key_E) {
+        updatevalue();
+    }
+}
+
+void MainWindow::on_lineEdit_wheel_returnPressed()
+{
+    updatevalue();
+}
+
+void MainWindow::on_lineEdit_drive_returnPressed()
+{
+    updatevalue();
+}
+
+void MainWindow::on_lineEdit_brake_returnPressed()
+{
+    updatevalue();
+}
+
+void MainWindow::updatevalue()
+{
+    const double MAXWHEEL = 430.0;
+    const double MINWHEEL = -430.0;
+    const double MAXTORQUE = 260;
+    const double MAXBRAKE = -3.0;
+    const double MAXSPEED = 5.0;
+
+    if(ui->checkBox_left->isChecked())mbleft = true;
+    else mbleft = false;
+    if(ui->checkBox_right->isChecked())mbright = true;
+    else mbright = false;
+    double fwheel = ui->lineEdit_wheel->text().toDouble();
+    if(fwheel>MAXWHEEL){
+        char strtip[256];
+        snprintf(strtip,256,"Wheel exceed maximum wheel. Wheel Range is %6.1f  ---  %6.1f",MINWHEEL,MAXWHEEL);
+        QMessageBox::warning(this,tr("Warning"),strtip,QMessageBox::YesAll);
+        return;
+    }
+    if(fwheel<MINWHEEL){
+        char strtip[256];
+        snprintf(strtip,256,"Wheel exceed maximum wheel. Wheel Range is %6.1f  ---  %6.1f",MINWHEEL,MAXWHEEL);
+        QMessageBox::warning(this,tr("Warning"),strtip,QMessageBox::YesAll);
+        return;
+    }
+    mfwheel = fwheel;
+    double ftorque = ui->lineEdit_drive->text().toDouble();
+    if(ftorque > MAXTORQUE){
+        char strtip[256];
+        snprintf(strtip,256,"Torque exceed maximum torque. Torque Range is %6.1f  ---  %6.1f",0.0,MAXTORQUE);
+        QMessageBox::warning(this,tr("Warning"),strtip,QMessageBox::YesAll);
+        return;
+    }
+    if(ftorque<-0.0000001)
+    {
+        char strtip[256];
+        snprintf(strtip,256,"Torque must bigger than 0. Torque Range is %6.1f  ---  %6.1f",0.0,MAXTORQUE);
+        QMessageBox::warning(this,tr("Warning"),strtip,QMessageBox::YesAll);
+        return;
+    }
+    mftorque = ftorque;
+    double fbrake = ui->lineEdit_brake->text().toDouble();
+    if(fbrake < MAXBRAKE)
+    {
+        char strtip[256];
+        snprintf(strtip,256,"Brake exceed maximum brake. Brake Range is %6.1f  ---  %6.1f",MAXBRAKE,0.0);
+        QMessageBox::warning(this,tr("Warning"),strtip,QMessageBox::YesAll);
+        return;
+    }
+    mfbrake = fbrake;
+
+
+    double fspeed = ui->lineEdit_speed->text().toDouble();
+    if(fspeed >MAXSPEED ){
+        char strtip[256];
+        snprintf(strtip,256,"speed exceed maximum speed. speed Range is %6.1f  ---  %6.1f",0.0,MAXSPEED);
+        QMessageBox::warning(this,tr("Warning"),strtip,QMessageBox::YesAll);
+        return;
+    }
+    if(fspeed<-0.0000001)
+    {
+        char strtip[256];
+        snprintf(strtip,256,"speed exceed maximum speed. speed Range is %6.1f  ---  %6.1f",0.0,MAXSPEED);
+        QMessageBox::warning(this,tr("Warning"),strtip,QMessageBox::YesAll);
+        return;
+    }
+    mfspeed = fspeed;
+    char strout[1000];
+    snprintf(strout,1000,"Left:%d Right:%d  Wheel:%6.1f Torque:%6.1f Brake:%6.1f Speed:%6.1f",
+             mbleft,mbright,mfwheel,mftorque,mfbrake,mfspeed);
+    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(mfspeed);
+        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));
+    }
+}
+
+void MainWindow::on_lineEdit_speed_returnPressed()
+{
+    updatevalue();
+}
+

+ 73 - 0
src/tool/tool_controller_test/mainwindow.h

@@ -0,0 +1,73 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QLabel>
+#include <QKeyEvent>
+#include <QTimer>
+
+#include <thread>
+
+#include "decition.pb.h"
+
+#include "modulecomm.h"
+
+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_checkBox_left_stateChanged(int arg1);
+
+    void on_checkBox_right_stateChanged(int arg1);
+
+    void on_checkBox_left_clicked();
+
+    void on_checkBox_right_clicked();
+
+    void on_lineEdit_wheel_returnPressed();
+
+    void on_lineEdit_drive_returnPressed();
+
+    void on_lineEdit_brake_returnPressed();
+
+    void onTimer();
+
+    void on_lineEdit_speed_returnPressed();
+
+public:
+    void keyPressEvent(QKeyEvent *event) override;
+
+private:
+    Ui::MainWindow *ui;
+
+    QLabel * mpLabelInfo;
+    QLabel * mpLabelTip;
+
+private:
+    void updatevalue();
+    void threadsend();
+
+private:
+    bool mbleft  = false;
+    bool mbright = false;
+    double mfwheel = 0.0;
+    double mftorque = 0.0;
+    double mfbrake = 0.0;
+    double mfspeed = 0.0;
+
+    void * mpadecision;
+
+    std::thread * mpthreadsend;
+    bool mbthreadrun;
+    QTimer * mpTimer;
+};
+#endif // MAINWINDOW_H

+ 183 - 0
src/tool/tool_controller_test/mainwindow.ui

@@ -0,0 +1,183 @@
+<?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>504</width>
+    <height>411</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralwidget">
+   <widget class="QLabel" name="label_1">
+    <property name="geometry">
+     <rect>
+      <x>131</x>
+      <y>80</y>
+      <width>80</width>
+      <height>41</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>灯光控制</string>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_2">
+    <property name="geometry">
+     <rect>
+      <x>131</x>
+      <y>130</y>
+      <width>80</width>
+      <height>41</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>转向控制</string>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_3">
+    <property name="geometry">
+     <rect>
+      <x>131</x>
+      <y>180</y>
+      <width>80</width>
+      <height>41</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>驱动控制</string>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_4">
+    <property name="geometry">
+     <rect>
+      <x>131</x>
+      <y>230</y>
+      <width>80</width>
+      <height>41</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>制动控制</string>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_5">
+    <property name="geometry">
+     <rect>
+      <x>164</x>
+      <y>20</y>
+      <width>210</width>
+      <height>61</height>
+     </rect>
+    </property>
+    <property name="font">
+     <font>
+      <pointsize>16</pointsize>
+      <weight>75</weight>
+      <bold>true</bold>
+     </font>
+    </property>
+    <property name="text">
+     <string>线控底盘检测</string>
+    </property>
+   </widget>
+   <widget class="QCheckBox" name="checkBox_left">
+    <property name="geometry">
+     <rect>
+      <x>241</x>
+      <y>80</y>
+      <width>51</width>
+      <height>41</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>左</string>
+    </property>
+   </widget>
+   <widget class="QCheckBox" name="checkBox_right">
+    <property name="geometry">
+     <rect>
+      <x>311</x>
+      <y>80</y>
+      <width>51</width>
+      <height>41</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>右</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_wheel">
+    <property name="geometry">
+     <rect>
+      <x>241</x>
+      <y>130</y>
+      <width>121</width>
+      <height>41</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_drive">
+    <property name="geometry">
+     <rect>
+      <x>241</x>
+      <y>180</y>
+      <width>121</width>
+      <height>41</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_brake">
+    <property name="geometry">
+     <rect>
+      <x>241</x>
+      <y>230</y>
+      <width>121</width>
+      <height>41</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_6">
+    <property name="geometry">
+     <rect>
+      <x>130</x>
+      <y>280</y>
+      <width>80</width>
+      <height>41</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>速度控制</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_speed">
+    <property name="geometry">
+     <rect>
+      <x>240</x>
+      <y>280</y>
+      <width>121</width>
+      <height>41</height>
+     </rect>
+    </property>
+   </widget>
+  </widget>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>504</width>
+     <height>28</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QStatusBar" name="statusbar"/>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 41 - 0
src/tool/tool_controller_test/tool_controller_test.pro

@@ -0,0 +1,41 @@
+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 += \
+    ../../include/msgtype/decition.pb.cc \
+    main.cpp \
+    mainwindow.cpp
+
+HEADERS += \
+    ../../include/msgtype/decition.pb.h \
+    mainwindow.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
+
+!include(../../../include/common.pri ) {
+    error( "Couldn't find the common.pri file!" )
+}
+
+!include(../../../include/ivprotobuf.pri ) {
+    error( "Couldn't find the ivprotobuf.pri file!" )
+}