ソースを参照

add tool/controller_torquebrake_get. for get torque brake add relation.

yuchuli 4 年 前
コミット
ddb4e0e874

+ 4 - 2
src/controller/controller_ge3/controller_ge3.pro

@@ -26,7 +26,8 @@ SOURCES += $$PWD/main.cpp \
     ../../include/msgtype/canmsg.pb.cc \
     ../../include/msgtype/canraw.pb.cc \
     ../../include/msgtype/chassis.pb.cc \
-    ../../include/msgtype/remotectrl.pb.cc
+    ../../include/msgtype/remotectrl.pb.cc \
+    ../../include/msgtype/torquebrake.pb.cc
 
 include($$PWD/control/control.pri)
 
@@ -55,6 +56,7 @@ HEADERS += \
     ../../include/msgtype/canmsg.pb.h \
     ../../include/msgtype/canraw.pb.h \
     ../../include/msgtype/chassis.pb.h \
-    ../../include/msgtype/remotectrl.pb.h
+    ../../include/msgtype/remotectrl.pb.h \
+    ../../include/msgtype/torquebrake.pb.h
 
 

+ 45 - 0
src/controller/controller_ge3/main.cpp

@@ -18,12 +18,15 @@
 
 #include "remotectrl.pb.h"
 
+#include "torquebrake.pb.h"
+
 #include <thread>
 
 void * gpacansend;
 void * gpadecition;
 void * gpachassis;
 void * gparemote;
+void * gpatorquebrake;
 
 std::string gstrmemdecition;
 std::string gstrmemcansend;
@@ -55,6 +58,10 @@ QMutex gMutex;
 
 boost::shared_ptr<iv::control::Controller> gcontroller;	//实际车辆控制器
 
+iv::controller::torquebrake gtb;
+int gnothavetb = 10;
+QMutex gMutextb;
+
 
 //void executeDecition(const iv::decition::Decition decition)
 //{
@@ -86,6 +93,29 @@ void executeDecition(const iv::brain::decition decition)
 
     gcontroller->control_torque(decition.torque());
     gcontroller->control_brake(decition.brake());
+
+    if(gnothavetb < 10)
+    {
+        iv::controller::torquebrake xtb;
+        gMutextb.lock();
+        xtb.CopyFrom(gtb);
+        gMutextb.unlock();
+        if(xtb.enable())
+        {
+            gcontroller->control_torque(xtb.torque());
+            gcontroller->control_brake(xtb.brake());
+//            qDebug("use tb value torque is %f brake is %f",xtb.torque(),xtb.brake());
+        }
+        else
+        {
+//            qDebug("torquebrake not enable.");
+        }
+        gnothavetb++;
+    }
+    else
+    {
+//        qDebug("no tb");
+    }
     gcontroller->control_engine(decition.engine());
     gcontroller->control_grade(decition.grade());
     gcontroller->control_mode(decition.mode());
@@ -100,6 +130,20 @@ void executeDecition(const iv::brain::decition decition)
 //    qDebug("dangwei is %d mode is %d",decition.gear(),decition.mode());
 }
 
+void UpdateTorqueBrake(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
+{
+    iv::controller::torquebrake xtb;
+    if(!xtb.ParseFromArray(strdata,nSize))
+    {
+        std::cout<<"UpdateTorqueBrake ParseFrom Array Error."<<std::endl;
+        return;
+    }
+    gMutextb.lock();
+    gtb.CopyFrom(xtb);
+    gMutextb.unlock();
+    gnothavetb= 0;
+}
+
 void UpdateChassis(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
 {
     iv::chassis xchassis;
@@ -309,6 +353,7 @@ int main(int argc, char *argv[])
     gpacansend = iv::modulecomm::RegisterSend(gstrmemcansend.data(),10000,1);
     gpadecition = iv::modulecomm::RegisterRecv(gstrmemdecition.data(),ListenDeciton);
     gpachassis = iv::modulecomm::RegisterRecv(gstrmemchassis.data(),UpdateChassis);
+    gpatorquebrake = iv::modulecomm::RegisterRecv("torquebrake",UpdateTorqueBrake);
 
 
     if(gbAllowRemote)

+ 12 - 0
src/include/proto/torquebrake.proto

@@ -0,0 +1,12 @@
+syntax = "proto2";
+
+package iv.controller;
+
+message torquebrake
+{
+	required double torque	= 1;
+	required double brake	= 2;
+	required bool enable	= 3;
+};
+
+

+ 73 - 0
src/tool/controller_torquebrake_get/.gitignore

@@ -0,0 +1,73 @@
+# This file is used to ignore files which are generated
+# ----------------------------------------------------------------------------
+
+*~
+*.autosave
+*.a
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.rej
+*.so
+*.so.*
+*_pch.h.cpp
+*_resource.rc
+*.qm
+.#*
+*.*#
+core
+!core/
+tags
+.DS_Store
+.directory
+*.debug
+Makefile*
+*.prl
+*.app
+moc_*.cpp
+ui_*.h
+qrc_*.cpp
+Thumbs.db
+*.res
+*.rc
+/.qmake.cache
+/.qmake.stash
+
+# qtcreator generated files
+*.pro.user*
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.sdf
+*.opensdf
+*.vcxproj
+*vcxproj.*
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# Python byte code
+*.pyc
+
+# Binaries
+# --------
+*.dll
+*.exe
+

+ 41 - 0
src/tool/controller_torquebrake_get/controller_torquebrake_get.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/torquebrake.pb.cc \
+    main.cpp \
+    mainwindow.cpp
+
+HEADERS += \
+    ../../include/msgtype/torquebrake.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!" )
+}

+ 11 - 0
src/tool/controller_torquebrake_get/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();
+}

+ 59 - 0
src/tool/controller_torquebrake_get/mainwindow.cpp

@@ -0,0 +1,59 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+MainWindow::MainWindow(QWidget *parent)
+    : QMainWindow(parent)
+    , ui(new Ui::MainWindow)
+{
+    ui->setupUi(this);
+
+    ui->lineEdit_Brake->setText("0.0");
+    ui->lineEdit_Torque->setText("35.0");
+
+    mpa = iv::modulecomm::RegisterSend("torquebrake",1000,1);
+
+    mpTimer = new QTimer();
+    connect(mpTimer,SIGNAL(timeout()),this,SLOT(onTimer()));
+    mpTimer->start(10);
+
+    setWindowTitle("Get Torque Brake acc Relation");
+
+}
+
+MainWindow::~MainWindow()
+{
+    delete ui;
+}
+
+void MainWindow::onTimer()
+{
+    iv::controller::torquebrake xtb;
+    xtb.set_torque(mfTorque);
+    xtb.set_brake(mfBrake);
+    xtb.set_enable(mbEnable);
+
+    int ndatasize = xtb.ByteSize();
+    std::shared_ptr<char> strbuf_ptr = std::shared_ptr<char>(new char[ndatasize]);
+    if(xtb.SerializeToArray(strbuf_ptr.get(),ndatasize))
+    {
+        iv::modulecomm::ModuleSendMsg(mpa,strbuf_ptr.get(),ndatasize);
+    }
+
+}
+
+
+
+void MainWindow::on_checkBox_clicked()
+{
+    if(ui->checkBox->isChecked())
+    {
+        mbEnable = true;
+    }
+    else
+    {
+        mbEnable = false;
+    }
+    mfTorque = ui->lineEdit_Torque->text().toDouble();
+    mfBrake = ui->lineEdit_Brake->text().toDouble();
+
+}

+ 39 - 0
src/tool/controller_torquebrake_get/mainwindow.h

@@ -0,0 +1,39 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QTimer>
+
+#include "torquebrake.pb.h"
+#include "modulecomm.h"
+#include <memory>
+
+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 onTimer();
+
+    void on_checkBox_clicked();
+
+private:
+    Ui::MainWindow *ui;
+
+    QTimer * mpTimer;
+
+    double mfTorque = 35.0;
+    double mfBrake = 0;
+    bool mbEnable = false;
+
+    void * mpa;
+};
+#endif // MAINWINDOW_H

+ 127 - 0
src/tool/controller_torquebrake_get/mainwindow.ui

@@ -0,0 +1,127 @@
+<?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="QPlainTextEdit" name="plainTextEdit">
+    <property name="geometry">
+     <rect>
+      <x>60</x>
+      <y>210</y>
+      <width>531</width>
+      <height>311</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QCheckBox" name="checkBox">
+    <property name="geometry">
+     <rect>
+      <x>560</x>
+      <y>100</y>
+      <width>211</width>
+      <height>61</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Enable</string>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label">
+    <property name="geometry">
+     <rect>
+      <x>60</x>
+      <y>35</y>
+      <width>111</width>
+      <height>41</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Torque</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_Torque">
+    <property name="geometry">
+     <rect>
+      <x>200</x>
+      <y>30</y>
+      <width>181</width>
+      <height>51</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QPushButton" name="pushButton_ClearRecord">
+    <property name="geometry">
+     <rect>
+      <x>620</x>
+      <y>260</y>
+      <width>161</width>
+      <height>51</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Clear Record</string>
+    </property>
+   </widget>
+   <widget class="QPushButton" name="pushButton_SaveRecord">
+    <property name="geometry">
+     <rect>
+      <x>620</x>
+      <y>420</y>
+      <width>161</width>
+      <height>51</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Save Record</string>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_2">
+    <property name="geometry">
+     <rect>
+      <x>450</x>
+      <y>44</y>
+      <width>111</width>
+      <height>31</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Brake</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_Brake">
+    <property name="geometry">
+     <rect>
+      <x>550</x>
+      <y>31</y>
+      <width>181</width>
+      <height>51</height>
+     </rect>
+    </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>