| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include "iostream"
- #include "modulecomm.h"
- #include "decition.pb.h"
- #include "chassis.pb.h"
- #include <QTimer>
- static bool gbHaveVehSpd = false;
- static double gfVehSpd = 0.0;
- static double gfAng=0.0;
- QString qsSpd ;
- QString qsAng ;
- void UpdateChassis(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname);
- //void ListenChassis(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
- //{
- // UpdateChassis(strdata,nSize);
- //}
- MainWindow* instance;
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- instance=this;
- this->setWindowTitle("中汽智联车辆线控测试系统");
- this->setObjectName("parent");
- this->setStyleSheet("#parent { border-image: url(:/new/prefix1/background4.png);}");
- this->setWindowFlags(Qt::WindowMinimizeButtonHint|Qt::WindowCloseButtonHint);
- timer =new QTimer(this);
- mpaVechicleDeciton = iv::modulecomm::RegisterSend("deciton",10000,10);
- gpachassis = iv::modulecomm::RegisterRecv("chassis",UpdateChassis);
- connect(timer,SIGNAL(timeout()),this,SLOT(ShareChassisDebug()));
- timer->start(20);
- decition_debug.set_wheelangle(5);
- decition_debug.set_torque(1);
- decition_debug.set_brake(2);
- decition_debug.set_leftlamp(0);
- decition_debug.set_rightlamp(0);
- }
- //建立自身调用
- MainWindow *MainWindow::getInstance()
- {
- return instance;
- }
- void UpdateChassis(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
- {
- (void)index;
- (void)dt;
- (void)strmemname;
- iv::chassis xchassis;
- // static int ncount = 0;
- if(!xchassis.ParseFromArray(strdata,nSize))
- {
- std::cout<<"iv::decition::BrainDecition::UpdateChassis ParseFrom Array Error."<<std::endl;
- return;
- }
- if(xchassis.has_epsmode())
- {
- if(xchassis.epsmode() == 0)
- {
- bool gbChassisEPS = true;
- }
- }
- if(xchassis.has_vel())
- {
- gfVehSpd = xchassis.vel();
- gbHaveVehSpd = true;
- qsSpd = QString::number(gfVehSpd, 'f', 2);
- // std::cout<<" gf Veh speed : "<<gfVehSpd<<std::endl;
- }
- if(xchassis.has_angle_feedback())
- {
- gfAng = xchassis.angle_feedback();
- qsAng = QString::number(gfAng, 'f', 2);
- }
- MainWindow::getInstance()->ShowChassisData();
- }
- void MainWindow::ShowChassisData()
- {
- ui->Vehicle_Speed->setText(qsSpd);
- ui->EPS_Ang->setText(qsAng);
- }
- void MainWindow::ShareChassisDebug()
- {
- int nsize = decition_debug.ByteSize();
- char * str = new char[nsize];
- std::shared_ptr<char> pstr;
- pstr.reset(str);
- if(ui->left_turn->isChecked())
- {
- decition_debug.set_leftlamp(1);
- decition_debug.set_rightlamp(0);
- }
- else if(ui->right_turn->isChecked())
- {
- decition_debug.set_leftlamp(0);
- decition_debug.set_rightlamp(1);
- }
- else
- {
- decition_debug.set_leftlamp(0);
- decition_debug.set_rightlamp(0);
- }
- if(decition_debug.SerializeToArray(str,nsize))
- {
- if(ui->start_send->isChecked())
- iv::modulecomm::ModuleSendMsg(mpaVechicleDeciton,str,nsize);
- }
- else
- {
- std::cout<<"iv::decition::ShareChassisDebug::ShareChassisDebug serialize error."<<std::endl;
- }
- }
- MainWindow::~MainWindow()
- {
- iv::modulecomm::Unregister(mpaVechicleDeciton);
- iv::modulecomm::Unregister(gpachassis);
- delete ui;
- }
- void MainWindow::on_doubleang_pos_valueChanged(double arg1)
- {
- decition_debug.set_wheelangle(arg1);
- }
- void MainWindow::on_targe_acc_valueChanged(double arg1) //加速扭矩
- {
- if(arg1>=0.0)
- {
- decition_debug.set_torque(arg1);
- decition_debug.set_brake(0);
- ui->brake->setValue(0.0);
- }
- else
- {
- decition_debug.set_torque(0);
- }
- }
- void MainWindow::on_brake_valueChanged(double arg1)
- {
- if(arg1<=0.0)
- {
- decition_debug.set_torque(0);
- decition_debug.set_brake(arg1);
- ui->targe_acc->setValue(0.0);
- }
- else
- {
- decition_debug.set_brake(arg1);
- }
- }
- void MainWindow::on_left_turn_clicked()
- {
- }
- void MainWindow::on_left_turn_clicked(bool checked)
- {
- // if(checked)
- // {
- // decition_debug.set_leftlamp(1);
- // decition_debug.set_rightlamp(0);
- // }
- // else
- // decition_debug.set_leftlamp(0);
- }
- void MainWindow::on_right_turn_clicked(bool checked)
- {
- // if(checked)
- // decition_debug.set_rightlamp(1);
- // else
- // decition_debug.set_rightlamp(0);
- }
|