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