mainwindow.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include "iostream"
  4. #include "modulecomm.h"
  5. #include "decition.pb.h"
  6. #include "chassis.pb.h"
  7. #include <QTimer>
  8. static bool gbHaveVehSpd = false;
  9. static double gfVehSpd = 0.0;
  10. static double gfAng=0.0;
  11. QString qsSpd ;
  12. QString qsAng ;
  13. void UpdateChassis(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname);
  14. //void ListenChassis(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  15. //{
  16. // UpdateChassis(strdata,nSize);
  17. //}
  18. MainWindow* instance;
  19. MainWindow::MainWindow(QWidget *parent) :
  20. QMainWindow(parent),
  21. ui(new Ui::MainWindow)
  22. {
  23. ui->setupUi(this);
  24. instance=this;
  25. this->setWindowTitle("中汽智联车辆线控测试系统");
  26. this->setObjectName("parent");
  27. this->setStyleSheet("#parent { border-image: url(:/new/prefix1/background4.png);}");
  28. this->setWindowFlags(Qt::WindowMinimizeButtonHint|Qt::WindowCloseButtonHint);
  29. timer =new QTimer(this);
  30. mpaVechicleDeciton = iv::modulecomm::RegisterSend("deciton",10000,10);
  31. gpachassis = iv::modulecomm::RegisterRecv("chassis",UpdateChassis);
  32. connect(timer,SIGNAL(timeout()),this,SLOT(ShareChassisDebug()));
  33. timer->start(20);
  34. decition_debug.set_wheelangle(5);
  35. decition_debug.set_torque(1);
  36. decition_debug.set_brake(2);
  37. decition_debug.set_leftlamp(0);
  38. decition_debug.set_rightlamp(0);
  39. }
  40. //建立自身调用
  41. MainWindow *MainWindow::getInstance()
  42. {
  43. return instance;
  44. }
  45. void UpdateChassis(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  46. {
  47. (void)index;
  48. (void)dt;
  49. (void)strmemname;
  50. iv::chassis xchassis;
  51. // static int ncount = 0;
  52. if(!xchassis.ParseFromArray(strdata,nSize))
  53. {
  54. std::cout<<"iv::decition::BrainDecition::UpdateChassis ParseFrom Array Error."<<std::endl;
  55. return;
  56. }
  57. if(xchassis.has_epsmode())
  58. {
  59. if(xchassis.epsmode() == 0)
  60. {
  61. bool gbChassisEPS = true;
  62. }
  63. }
  64. if(xchassis.has_vel())
  65. {
  66. gfVehSpd = xchassis.vel();
  67. gbHaveVehSpd = true;
  68. qsSpd = QString::number(gfVehSpd, 'f', 2);
  69. // std::cout<<" gf Veh speed : "<<gfVehSpd<<std::endl;
  70. }
  71. if(xchassis.has_angle_feedback())
  72. {
  73. gfAng = xchassis.angle_feedback();
  74. qsAng = QString::number(gfAng, 'f', 2);
  75. }
  76. MainWindow::getInstance()->ShowChassisData();
  77. }
  78. void MainWindow::ShowChassisData()
  79. {
  80. ui->Vehicle_Speed->setText(qsSpd);
  81. ui->EPS_Ang->setText(qsAng);
  82. }
  83. void MainWindow::ShareChassisDebug()
  84. {
  85. int nsize = decition_debug.ByteSize();
  86. char * str = new char[nsize];
  87. std::shared_ptr<char> pstr;
  88. pstr.reset(str);
  89. if(ui->left_turn->isChecked())
  90. {
  91. decition_debug.set_leftlamp(1);
  92. decition_debug.set_rightlamp(0);
  93. }
  94. else if(ui->right_turn->isChecked())
  95. {
  96. decition_debug.set_leftlamp(0);
  97. decition_debug.set_rightlamp(1);
  98. }
  99. else
  100. {
  101. decition_debug.set_leftlamp(0);
  102. decition_debug.set_rightlamp(0);
  103. }
  104. if(decition_debug.SerializeToArray(str,nsize))
  105. {
  106. if(ui->start_send->isChecked())
  107. iv::modulecomm::ModuleSendMsg(mpaVechicleDeciton,str,nsize);
  108. }
  109. else
  110. {
  111. std::cout<<"iv::decition::ShareChassisDebug::ShareChassisDebug serialize error."<<std::endl;
  112. }
  113. }
  114. MainWindow::~MainWindow()
  115. {
  116. iv::modulecomm::Unregister(mpaVechicleDeciton);
  117. iv::modulecomm::Unregister(gpachassis);
  118. delete ui;
  119. }
  120. void MainWindow::on_doubleang_pos_valueChanged(double arg1)
  121. {
  122. decition_debug.set_wheelangle(arg1);
  123. }
  124. void MainWindow::on_targe_acc_valueChanged(double arg1) //加速扭矩
  125. {
  126. if(arg1>=0.0)
  127. {
  128. decition_debug.set_torque(arg1);
  129. decition_debug.set_brake(0);
  130. ui->brake->setValue(0.0);
  131. }
  132. else
  133. {
  134. decition_debug.set_torque(0);
  135. }
  136. }
  137. void MainWindow::on_brake_valueChanged(double arg1)
  138. {
  139. if(arg1<=0.0)
  140. {
  141. decition_debug.set_torque(0);
  142. decition_debug.set_brake(arg1);
  143. ui->targe_acc->setValue(0.0);
  144. }
  145. else
  146. {
  147. decition_debug.set_brake(arg1);
  148. }
  149. }
  150. void MainWindow::on_left_turn_clicked()
  151. {
  152. }
  153. void MainWindow::on_left_turn_clicked(bool checked)
  154. {
  155. // if(checked)
  156. // {
  157. // decition_debug.set_leftlamp(1);
  158. // decition_debug.set_rightlamp(0);
  159. // }
  160. // else
  161. // decition_debug.set_leftlamp(0);
  162. }
  163. void MainWindow::on_right_turn_clicked(bool checked)
  164. {
  165. // if(checked)
  166. // decition_debug.set_rightlamp(1);
  167. // else
  168. // decition_debug.set_rightlamp(0);
  169. }