-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.cpp
2692 lines (2513 loc) · 93.7 KB
/
widget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "widget.h"
#include "./ui_widget.h"
template <typename T>
bool Widget::CheckEmpty(T t){
if(t.empty())
{
QMessageBox::information(this, "Error", "没有障碍物信息!");
on_pushButton_pause_clicked();
return true;
}
else
{
return false;
}
}
int Widget::CheckPlayMode(){
//icu
if(ui->checkBox_icu -> isChecked() &&
!ui->checkBox_prediction -> isChecked() &&
!ui->checkBox_control -> isChecked()){
return PlayMode::kICU;
}else if(!ui->checkBox_icu -> isChecked() &&
ui->checkBox_prediction -> isChecked() &&
!ui->checkBox_control -> isChecked()){//prediction
return PlayMode::KPrediction;
}else if(!ui->checkBox_icu -> isChecked() &&
!ui->checkBox_prediction -> isChecked() &&
ui->checkBox_control -> isChecked()){ //control
return PlayMode::kCtrl;
}else if(ui->checkBox_icu -> isChecked() &&
ui->checkBox_prediction -> isChecked() &&
!ui->checkBox_control -> isChecked()){ //icu&prediction
return PlayMode::kICUAndPrediction;
}else if(!ui->checkBox_icu -> isChecked() &&
ui->checkBox_prediction -> isChecked() &&
ui->checkBox_control -> isChecked()){ //prediction & control
return PlayMode::kPredictionAndControl;
}else if(ui->checkBox_icu -> isChecked() &&
ui->checkBox_prediction -> isChecked() &&
ui->checkBox_control -> isChecked()){ //icu&prediction & control
return PlayMode::kAll;
}else{
return PlayMode::kError;
}
return PlayMode::kError;
}
/* @brief:构造函数
* @param [in]:NONE
* @param [out]:NONE
* @return:NONE
*/
Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{
setWindowTitle("replay tool");
setMinimumSize(1230,800);
min_utm_x = 10000000, max_utm_x = 0, min_utm_y = 10000000, max_utm_y = 0;
plot_min_x_ = 10000000, plot_max_x_ = 0, plot_min_y_ = 10000000, plot_max_y_ = 0;
ctrl_min_y_ = 100, ctrl_max_y_ = 0;
ui->setupUi(this);
// tooltip_ = new QCPToolTip(ui->control_plot);
//ICU界面初始化
ui->chartview->chartInit(-60, 60, -30, 90, "激光雷达坐标系"); //初始化坐标系
ui->globalview_icu->init(-100, 100, -100, 100, "UTM坐标系");
TimerInit();
WidgetInit();
UIInit();
ComboBoxInit();
control_start_ = 0;
trans_bp_imu = calcTransformMatrix(lidar_offset_x, lidar_offset_y, lidar_offset_z, lidar_yaw, lidar_pitch, lidar_roll);
}
/* @brief:析构函数
* @param [in]:NONE
* @param [out]:NONE
* @return:NONE
*/
Widget::~Widget()
{
delete ui;
}
void Widget::TimerInit()
{
fTimer_ = new QTimer(this); //设置定时器
fTimer_->stop();
fTimer_->setInterval(time_interval);
connect(fTimer_, SIGNAL(timeout()), this, SLOT(on_timeout()));
}
void Widget::WidgetInit()
{
tracer_ = new QCPItemTracer(ui->control_plot); //生成游标
tracer_->setPen(QPen(Qt::red));//圆圈轮廓颜色
tracer_->setBrush(QBrush(Qt::red));//圆圈圈内颜色
tracer_->setStyle(QCPItemTracer::tsCircle);//圆圈
tracer_->setSize(5);//设置大小
tracer_label_ = new QCPItemText(ui->control_plot); //生成游标说明
tracer_label_->setLayer("overlay");//设置图层为overlay,因为需要频繁刷新
tracer_label_->setPen(QPen(Qt::black));//设置游标说明颜色
tracer_label_->setPositionAlignment(Qt::AlignLeft | Qt::AlignTop);//左上
tracer_label_->position->setParentAnchor(tracer_->position);//将游标说明锚固在tracer位置处,实现自动跟随
//输出信息的lineEdit设置为只读
ui->lineEdit_index->setReadOnly(true);
ui->lineEdit_obscount->setReadOnly(true);
ui->lineEdit_framecount->setReadOnly(true);
//播放功能中 button设置为false
ui->pushButton_play->setEnabled(false);
ui->pushButton_pause->setEnabled(false);
ui->pushButton_pre->setEnabled(false);
ui->pushButton_next->setEnabled(false);
ui->pushButton_reset->setEnabled(false);
//radioButton初始化
group_button_ = new QButtonGroup(this); //初始化前向后向icu ccu control选择
group_button_->addButton(ui->radioButton_front, 0);
group_button_->addButton(ui->radioButton_back, 1);
ui->radioButton_front->setChecked(true);
//checkbox初始化
ui->checkBox_icu->setTristate(false);
ui->checkBox_prediction->setTristate(false);
ui->checkBox_control->setTristate(false);
ui->checkBox_icu->setEnabled(false);
ui->checkBox_prediction->setEnabled(false);
ui->checkBox_control->setEnabled(false);
ui->horizontalSlider_local->setRange(1, 10);
ui->horizontalSlider_local->setValue(5);
ui->objSizeLocal->setText(QString::number(ui->horizontalSlider_local->value()));
ui->horizontalSlider_global->setRange(1, 10);
ui->horizontalSlider_global->setValue(5);
ui->objSizeGlobal->setText(QString::number(ui->horizontalSlider_global->value()));
QList<QLineEdit *> lineEdit = ui->groupBox_5->findChildren<QLineEdit *>();
for(int i = 0; i < lineEdit.count(); ++i)
{
lineEdit[i]->setReadOnly(true);
}
}
void Widget::UIInit(){
//prediction界面初始化
ui->prediction_plot->setInteractions(QCP::iRangeDrag|QCP::iRangeZoom|QCP::iSelectPlottables);
ui->prediction_plot->axisRect()->setRangeZoom(Qt::Vertical|Qt::Horizontal);
//设置横纵坐标系精度
ui->prediction_plot->xAxis->setNumberPrecision(9);
ui->prediction_plot->yAxis->setNumberPrecision(10);
//添加图层
ui->prediction_plot->addGraph();
prediction_graph_manage_.insert("map_edge", 0);
ui->prediction_plot->addGraph();
prediction_graph_manage_.insert("map_route", 1);
//control界面初始化
ui->control_plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
QCP::iSelectLegend | QCP::iSelectPlottables);
ui->control_plot->axisRect()->setupFullAxesBox();
ui->control_plot->yAxis2->setVisible(true);
ui->control_plot->yAxis2->setTickLabels(true);
ui->control_plot->xAxis->setLabel("x Axis");
ui->control_plot->yAxis->setLabel("纵向");
ui->control_plot->yAxis2->setLabel("横向");
QFont legendFont = font();
legendFont.setPointSize(10);
ui->control_plot->legend->setFont(legendFont);
ui->control_plot->legend->setSelectedFont(legendFont);
ui->control_plot->legend->setSelectableParts(QCPLegend::spItems);
ui->control_plot->legend->setVisible(false);
// //设置横纵坐标系精度
// ui->control_plot->xAxis->setNumberPrecision(9);
ui->control_plot->yAxis->setNumberPrecision(10);
ui->control_plot->yAxis2->setNumberPrecision(10);
//添加图层
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis2);
control_graph_manage_.insert("gps_heading", 0);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("gps_speed", 1);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("rest_dis", 2);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis2);
control_graph_manage_.insert("bia_distance", 3);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis2);
control_graph_manage_.insert("preview_dis", 4);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis2);
control_graph_manage_.insert("curve_prepoint", 5);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis2);
control_graph_manage_.insert("angle_deviation_at_prepoint", 6);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis2);
control_graph_manage_.insert("heading_angle_deviation_at_prepoint", 7);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis2);
control_graph_manage_.insert("record_m_angle_head", 8);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis2);
control_graph_manage_.insert("dev_angle_ctl", 9);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis2);
control_graph_manage_.insert("dev_heading_ctl", 10);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis2);
control_graph_manage_.insert("front_wheel_angle", 11);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis2);
control_graph_manage_.insert("wire_status_front_wheel_angle", 12);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("desired_speed", 13);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("desired_lidar_speed", 14);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("speed_preview", 15);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("vehicle_velocity", 16);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("pitch_filter_record", 17);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("slope_vehicle", 18);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("slope_preview", 29);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("speed_ctl_state", 20);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("spd_e", 21);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("spd_ec", 22);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("base_ctl_value", 23);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("delta_ctl_value", 24);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("total_ctl_value", 25);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("shift_ctrl", 26);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("wire_status_gear_shift", 27);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("throttle_pedal", 28);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("wire_status_acc_actuate_percent", 29);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("brake_pedal", 30);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("wire_status_electric_brake_actuate_percent", 31);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("hydraulic_brake", 32);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("wire_status_mechanical_brake_actuate_percent", 33);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("wire_status_front_brake_percent", 34);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("object_stop_flag", 35);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("dis_path", 36);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis2);
control_graph_manage_.insert("path_wheel_angle_pre", 37);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis);
control_graph_manage_.insert("order2_kalman_speed", 38);
ui->control_plot->addGraph(ui->control_plot->xAxis,ui->control_plot->yAxis2);
control_graph_manage_.insert("lat_bia_dis_pre", 39);
for(int i = 0; i < 40; ++i)
{
ui->control_plot->graph(i)->setName(control_graph_manage_.key(i));
ui->control_plot->graph(i)->setVisible(false);
}
// ui->control_plot->legend->clearItems();
// ui->control_plot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignCenter | Qt::AlignTop);
// connect slot that ties some axis selections together (especially opposite axes):
connect(ui->control_plot, SIGNAL(selectionChangedByUser()), this, SLOT(SelectionChanged()));
// connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
connect(ui->control_plot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(MousePress(QMouseEvent *)));
connect(ui->control_plot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(MouseWheel()));
connect(ui->control_plot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(MouseMove(QMouseEvent*)));
// make bottom and left axes transfer their ranges to top and right axes:
connect(ui->control_plot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->control_plot->xAxis2, SLOT(setRange(QCPRange)));
// connect(ui->control_plot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->control_plot->yAxis2, SLOT(setRange(QCPRange)));
ui->control_plot->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->control_plot, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(ContextMenuRequest(QPoint)));
//combobox signal
connect(ui->comboBox_horizontal, SIGNAL(selectionChanged()), this, SLOT(ComboBoxSelectionChanged()));
connect(ui->comboBox_vertical, SIGNAL(selectionChanged()), this, SLOT(ComboBoxSelectionChanged()));
}
void Widget::ComboBoxInit(){
// horizontal init
ui->comboBox_horizontal->addItem("航向");
ui->comboBox_horizontal->addItem("横向偏差");
ui->comboBox_horizontal->addItem("横向控制预瞄距离");
ui->comboBox_horizontal->addItem("控制曲率");
ui->comboBox_horizontal->addItem("预瞄点-当前点方位角偏差");
ui->comboBox_horizontal->addItem("预瞄点-当前点航向角偏差");
ui->comboBox_horizontal->addItem("关键点-当前点航向偏差");
ui->comboBox_horizontal->addItem("方位/横向偏差转角指令");
ui->comboBox_horizontal->addItem("航向偏差转角指令");
ui->comboBox_horizontal->addItem("总转角指令");
ui->comboBox_horizontal->addItem("前轮转角");
ui->comboBox_horizontal->addItem("前馈转向");
ui->comboBox_horizontal->addItem("优化预测横向偏差");
control_info_manage_.insert("航向","gps_heading");
control_info_manage_.insert("横向偏差","bia_distance");
control_info_manage_.insert("横向控制预瞄距离","preview_dis");
control_info_manage_.insert("控制曲率","curve_prepoint");
control_info_manage_.insert("预瞄点-当前点方位角偏差","angle_deviation_at_prepoint");
control_info_manage_.insert("预瞄点-当前点航向角偏差","heading_angle_deviation_at_prepoint");
control_info_manage_.insert("关键点-当前点航向偏差","record_m_angle_head");
control_info_manage_.insert("方位/横向偏差转角指令","dev_angle_ctl");
control_info_manage_.insert("航向偏差转角指令","dev_heading_ctl");
control_info_manage_.insert("总转角指令","front_wheel_angle");
control_info_manage_.insert("前轮转角","wire_status_front_wheel_angle");
control_info_manage_.insert("前馈转向","wire_status_front_wheel_angle");
control_info_manage_.insert("优化预测横向偏差","lat_bia_dis_pre");
// vertical init
ui->comboBox_vertical->addItem("gps速度");
ui->comboBox_vertical->addItem("路径停车距离误差");
ui->comboBox_vertical->addItem("总期望车速");
ui->comboBox_vertical->addItem("感知期望车速");
ui->comboBox_vertical->addItem("道路期望车速");
ui->comboBox_vertical->addItem("实际车速");
ui->comboBox_vertical->addItem("俯仰角滤波");
ui->comboBox_vertical->addItem("车辆坡度滤波");
ui->comboBox_vertical->addItem("预瞄坡度滤波");
ui->comboBox_vertical->addItem("速度控制状态");
ui->comboBox_vertical->addItem("速度偏差");
ui->comboBox_vertical->addItem("速度偏差变化滤波");
ui->comboBox_vertical->addItem("速度控制基础量");
ui->comboBox_vertical->addItem("速度控制调节量");
ui->comboBox_vertical->addItem("速度控制总控制量");
ui->comboBox_vertical->addItem("档位控制量");
ui->comboBox_vertical->addItem("档位反馈");
ui->comboBox_vertical->addItem("油门控制量");
ui->comboBox_vertical->addItem("油门反馈");
ui->comboBox_vertical->addItem("电制动控制量");
ui->comboBox_vertical->addItem("电制动反馈");
ui->comboBox_vertical->addItem("液压制动控制量");
ui->comboBox_vertical->addItem("制动反馈");
ui->comboBox_vertical->addItem("前制动反馈");
ui->comboBox_vertical->addItem("object_stop_flag");
ui->comboBox_vertical->addItem("障碍物路径距离");
ui->comboBox_vertical->addItem("二阶卡尔曼滤波速度");
control_info_manage_.insert("gps速度","gps_speed");
control_info_manage_.insert("路径停车距离误差","rest_dis");
control_info_manage_.insert("总期望车速","desired_speed");
control_info_manage_.insert("感知期望车速","desired_lidar_speed");
control_info_manage_.insert("道路期望车速","speed_preview");
control_info_manage_.insert("实际车速","vehicle_velocity");
control_info_manage_.insert("俯仰角滤波","pitch_filter_record");
control_info_manage_.insert("车辆坡度滤波","slope_vehicle");
control_info_manage_.insert("预瞄坡度滤波","slope_preview");
control_info_manage_.insert("速度控制状态","speed_ctl_state");
control_info_manage_.insert("速度偏差","spd_e");
control_info_manage_.insert("速度偏差变化滤波","spd_ec");
control_info_manage_.insert("速度控制基础量","base_ctl_value");
control_info_manage_.insert("速度控制调节量","delta_ctl_value");
control_info_manage_.insert("速度控制总控制量","total_ctl_value");
control_info_manage_.insert("档位控制量","shift_ctrl");
control_info_manage_.insert("档位反馈","wire_status_gear_shift");
control_info_manage_.insert("油门控制量","throttle_pedal");
control_info_manage_.insert("油门反馈","wire_status_acc_actuate_percent");
control_info_manage_.insert("电制动控制量","brake_pedal");
control_info_manage_.insert("电制动反馈","wire_status_electric_brake_actuate_percent");
control_info_manage_.insert("液压制动控制量","hydraulic_brake");
control_info_manage_.insert("制动反馈","wire_status_mechanical_brake_actuate_percent");
control_info_manage_.insert("前制动反馈","wire_status_front_brake_percent");
control_info_manage_.insert("object_stop_flag","object_stop_flag");
control_info_manage_.insert("障碍物路径距离","dis_path");
control_info_manage_.insert("二阶卡尔曼滤波速度","order2_kalman_speed");
}
void Widget::PlotScatters(QVector<double> x, QVector<double> y,Qt::GlobalColor color,int index,bool add,int shape,int shape_size, bool prediction){
if(x.isEmpty() || y.isEmpty())
return;
QCPScatterStyle::ScatterShape dot_shape;
switch(shape)
{
case 0:
dot_shape = QCPScatterStyle::ssCircle;break;//空心圆
case 1:
dot_shape = QCPScatterStyle::ssDisc;break;//实心点
case 2:
dot_shape = QCPScatterStyle::ssStar;break;//星星
case 3:
dot_shape = QCPScatterStyle::ssPlusCircle;break;//圆中带十字
default:
dot_shape = QCPScatterStyle::ssCircle;break;//空心圆
}
//设置画笔颜色
QColor my_color(color);
my_color.setAlpha(250);//深颜色
QPen pen;
pen.setColor(my_color);
QCPScatterStyle my_scatter_style(dot_shape,shape_size);
my_scatter_style.setPen(pen);
//ui->plot->addGraph();
if(prediction)
{
if(add)
{
ui->control_plot->graph(index)->setLineStyle(QCPGraph::lsLine);
}
else
{
ui->control_plot->graph(index)->setLineStyle(QCPGraph::lsNone);
}
ui->prediction_plot->graph(index)->setScatterStyle(my_scatter_style);
ui->prediction_plot->graph(index)->addData(x,y);
ui->prediction_plot->replot();
}
else
{
if(add)
{
ui->control_plot->graph(index)->setLineStyle(QCPGraph::lsLine);
}
else
{
ui->control_plot->graph(index)->setLineStyle(QCPGraph::lsNone);
}
ui->control_plot->graph(index)->setScatterStyle(my_scatter_style);
ui->control_plot->graph(index)->addData(x,y);
ui->control_plot->replot();
}
}
void Widget::PlotScatters(QVector<QPointF> point,Qt::GlobalColor color,int index,bool add,int shape,int shape_size,bool prediction){
if(point.isEmpty())
return;
QVector<double> x, y;
for(int i = 0; i < point.size(); ++i){
x.push_back(point[i].x());
y.push_back(point[i].y());
}
QCPScatterStyle::ScatterShape dot_shape;
switch(shape)
{
case 0:
dot_shape = QCPScatterStyle::ssCircle;break;//空心圆
case 1:
dot_shape = QCPScatterStyle::ssDisc;break;//实心点
case 2:
dot_shape = QCPScatterStyle::ssStar;break;//星星
case 3:
dot_shape = QCPScatterStyle::ssPlusCircle;break;//圆中带十字
default:
dot_shape = QCPScatterStyle::ssCircle;break;//空心圆
}
//设置画笔颜色
QColor my_color(color);
my_color.setAlpha(250);//深颜色
QPen pen;
pen.setColor(my_color);
QCPScatterStyle my_scatter_style(dot_shape,shape_size);
my_scatter_style.setPen(pen);
//ui->plot->addGraph();
if(prediction)
{
if(add)
{
ui->prediction_plot->graph(index)->setLineStyle(QCPGraph::lsLine);
}
else
{
ui->prediction_plot->graph(index)->setLineStyle(QCPGraph::lsNone);
}
ui->prediction_plot->graph(index)->setScatterStyle(my_scatter_style);
ui->prediction_plot->graph(index)->setData(x,y);
ui->prediction_plot->replot();
}
else
{
if(add)
{
ui->control_plot->graph(index)->setLineStyle(QCPGraph::lsLine);
}
else
{
ui->control_plot->graph(index)->setLineStyle(QCPGraph::lsNone);
}
ui->control_plot->graph(index)->setScatterStyle(my_scatter_style);
ui->control_plot->graph(index)->setData(x,y);
ui->control_plot->replot();
}
}
void Widget::PlotScatter(double x, double y, Qt::GlobalColor color, int index, bool add, int shape, int shape_size, bool prediction){
QCPScatterStyle::ScatterShape dot_shape;
switch(shape)
{
case 0:
dot_shape = QCPScatterStyle::ssCircle;break;//空心圆
case 1:
dot_shape = QCPScatterStyle::ssDisc;break;//实心点
case 2:
dot_shape = QCPScatterStyle::ssStar;break;//星星
case 3:
dot_shape = QCPScatterStyle::ssPlusCircle;break;//圆中带十字
default:
dot_shape = QCPScatterStyle::ssCircle;break;//空心圆
}
//设置画笔颜色
QColor my_color(color);
my_color.setAlpha(250);//深颜色
QPen pen;
pen.setColor(my_color);
QCPScatterStyle my_scatter_style(dot_shape,shape_size);
my_scatter_style.setPen(pen);
//ui->plot->addGraph();
if(prediction)
{
if(add)
{
ui->prediction_plot->graph(index)->setLineStyle(QCPGraph::lsLine);
}
else
{
ui->prediction_plot->graph(index)->setLineStyle(QCPGraph::lsNone);
}
ui->prediction_plot->graph(index)->setScatterStyle(my_scatter_style);
ui->prediction_plot->graph(index)->addData(x,y);
ui->prediction_plot->replot();
}
else
{
if(add)
{
if(ui->control_plot->graph(index)->dataCount() >= 1)
ui->control_plot->graph(index)->setLineStyle(QCPGraph::lsLine);
}
else
{
ui->control_plot->graph(index)->setLineStyle(QCPGraph::lsNone);
}
ui->control_plot->graph(index)->setScatterStyle(my_scatter_style);
ui->control_plot->graph(index)->addData(x,y);
// ui->control_plot->replot();
}
}
void Widget::UpdateCCUMap(){
QVector<QPointF> edge;
QVector<QPointF> route;
for(int i = 0; i < ccu_map_.size(); ++i){
edge.push_back(ccu_map_[i].edge[0]);
edge.push_back(ccu_map_[i].edge[1]);
route.push_back(ccu_map_[i].route);
}
// PlotScatters(edge, Qt::black, prediction_graph_manage_.value("map_edge"), false, 1, 3, true);
// PlotScatters(route, Qt::darkYellow, prediction_graph_manage_.value("map_route"), false, 1, 3, true);
PlotScatters(route, Qt::black, prediction_graph_manage_.value("map_route"), false, 1, 3, true);
ui->prediction_plot->rescaleAxes();
AdjustPlotRange(true);
}
void Widget::UpdateCarBox(){
QPen pen;
pen.setColor(Qt::black);
pen.setStyle(Qt::SolidLine);
pen.setWidth(1);
int size = ui->prediction_plot->itemCount();
for(int i = 0; i < size; ++i){
ui->prediction_plot->removeItem(ui->prediction_plot->item(0));
}
car_arrows_.clear();
car_arrows_.resize(1e7);//无穷大
if(!vehicle_box_in_){
if(prediction_info_.empty()){
return;
}else{
if(!test_){
int index = 0;
for(int i = 0; i < 48; ++i){
for(int j = 1; j < 4; ++j){ //0为车辆中心点
qDebug()<<QString::number(prediction_info_[prediction_index_].car[i][j].x(),'f',6)<<" "
<<QString::number(prediction_info_[prediction_index_].car[i][j].y(), 'f', 6);
car_arrows_[index] = new QCPItemLine(ui->prediction_plot);
car_arrows_[index]->start->setCoords(prediction_info_[prediction_index_].car[i][j].x(),
prediction_info_[prediction_index_].car[i][j].y());
car_arrows_[index]->end->setCoords(prediction_info_[prediction_index_].car[i][j+1].x(),
prediction_info_[prediction_index_].car[i][j+1].y());
car_arrows_[index]->setHead(QCPLineEnding::esNone);
car_arrows_[index]->setPen(pen);
index++;
} //for j
car_arrows_[index] = new QCPItemLine(ui->prediction_plot);
car_arrows_[index]->start->setCoords(prediction_info_[prediction_index_].car[i][4].x(),
prediction_info_[prediction_index_].car[i][4].y());
car_arrows_[index]->end->setCoords(prediction_info_[prediction_index_].car[i][1].x(),
prediction_info_[prediction_index_].car[i][1].y());
car_arrows_[index]->setHead(QCPLineEnding::esNone);
car_arrows_[index]->setPen(pen);
index++;
}
}else{
int index = 0;
for(int i = 0; i < 3; ++i){
// qDebug()<<QString::number(prediction_info_[prediction_index_].vehicle[i].x(),'f',6)<<" "
// <<QString::number(prediction_info_[prediction_index_].vehicle[i].y(), 'f', 6);
car_arrows_[index] = new QCPItemLine(ui->prediction_plot);
car_arrows_[index]->start->setCoords(prediction_info_[prediction_index_].vehicle[i].x(),
prediction_info_[prediction_index_].vehicle[i].y());
car_arrows_[index]->end->setCoords(prediction_info_[prediction_index_].vehicle[i+1].x(),
prediction_info_[prediction_index_].vehicle[i+1].y());
car_arrows_[index]->setHead(QCPLineEnding::esNone);
car_arrows_[index]->setPen(pen);
index++;
} //for j
car_arrows_[index] = new QCPItemLine(ui->prediction_plot);
car_arrows_[index]->start->setCoords(prediction_info_[prediction_index_].vehicle[3].x(),
prediction_info_[prediction_index_].vehicle[3].y());
car_arrows_[index]->end->setCoords(prediction_info_[prediction_index_].vehicle[0].x(),
prediction_info_[prediction_index_].vehicle[0].y());
car_arrows_[index]->setHead(QCPLineEnding::esNone);
car_arrows_[index]->setPen(pen);
index++;
}
// ui->prediction_plot->rescaleAxes();
ui->prediction_plot->replot();
}// if-else
}
else
{
if(car_.empty())
{
return;
}
else
{
int index = 0;
for(int i = 0; i < car_.size(); ++i){
for(int j = 1; j < 4; ++j){ //0为车辆中心点
qDebug()<<QString::number(car_[i][j].x(),'f',6)<<" "<<QString::number(car_[i][j].y(), 'f', 6);
car_arrows_[index] = new QCPItemLine(ui->prediction_plot);
car_arrows_[index]->start->setCoords(car_[i][j].x(), car_[i][j].y());
car_arrows_[index]->end->setCoords(car_[i][j+1].x(), car_[i][j+1].y());
car_arrows_[index]->setHead(QCPLineEnding::esNone);
car_arrows_[index]->setPen(pen);
index++;
} //for j
car_arrows_[index] = new QCPItemLine(ui->prediction_plot);
car_arrows_[index]->start->setCoords(car_[i][4].x(), car_[i][4].y());
car_arrows_[index]->end->setCoords(car_[i][1].x(), car_[i][1].y());
car_arrows_[index]->setHead(QCPLineEnding::esNone);
car_arrows_[index]->setPen(pen);
index++;
}// for i
ui->prediction_plot->replot();
}
}
}
void Widget::UpdateObsBox(){
QPen pen;
pen.setColor(Qt::red);
pen.setStyle(Qt::SolidLine);
pen.setWidth(1);
// int size = ui->prediction_plot->itemCount();
// for(int i = 0; i < size; ++i){
// ui->prediction_plot->removeItem(ui->prediction_plot->item(0));
// }
obs_arrows_.clear();
obs_arrows_.resize(1e7);//
qDebug() << prediction_info_[prediction_index_].obs.num;
if(prediction_info_.empty() || prediction_info_[prediction_index_].obs.num == 0){
return;
}else{
int index = 0;
int num = prediction_info_[prediction_index_].obs.num;
for(int i = 0; i < num - 1; ++i){
qDebug()<<QString::number(prediction_info_[prediction_index_].obs.vertex[i].x(),'f',6)<<" "
<<QString::number(prediction_info_[prediction_index_].obs.vertex[i].y(), 'f', 6);
obs_arrows_[index] = new QCPItemLine(ui->prediction_plot);
obs_arrows_[index]->start->setCoords(prediction_info_[prediction_index_].obs.vertex[i].x(),
prediction_info_[prediction_index_].obs.vertex[i].y());
obs_arrows_[index]->end->setCoords(prediction_info_[prediction_index_].obs.vertex[i+1].x(),
prediction_info_[prediction_index_].obs.vertex[i+1].y());
obs_arrows_[index]->setHead(QCPLineEnding::esNone);
obs_arrows_[index]->setPen(pen);
index++;
}
obs_arrows_[index] = new QCPItemLine(ui->prediction_plot);
obs_arrows_[index]->start->setCoords(prediction_info_[prediction_index_].obs.vertex[num-1].x(),
prediction_info_[prediction_index_].obs.vertex[num-1].y());
obs_arrows_[index]->end->setCoords(prediction_info_[prediction_index_].obs.vertex[0].x(),
prediction_info_[prediction_index_].obs.vertex[0].y());
obs_arrows_[index]->setHead(QCPLineEnding::esNone);
obs_arrows_[index]->setPen(pen);
index++;
ui->prediction_plot->replot();
}
}
void Widget::ShowTracer(QString str){
tracer_->position->setCoords(mouse_pos_.x(), mouse_pos_.y());//设置游标位置
tracer_label_->setText(str);//设置游标说明内容
tracer_label_->setVisible(true);
tracer_->setVisible(true);
ui->control_plot->replot();//绘制器一定要重绘,否则看不到游标位置更新情况
}
void Widget::PlayICUFrame(){
if(frame_num_ < 0){
frame_num_++;
QMessageBox::information(this, "Error", "已经是第一帧!");
return;
}
if(frame_num_ >= res.size()){
frame_num_--;
QMessageBox::information(this, "Error", "已经是一帧!");
on_pushButton_pause_clicked();
return;
}
ui->chartview->updateLocal(res[frame_num_]);
ui->globalview_icu->updateGlobal(res[frame_num_]);
DispICUInfo();
}
void Widget::PlayPredictionInfo(){
if(prediction_index_ < 0){
prediction_index_++;
QMessageBox::information(this, "Error", "已经是第一帧!");
return;
}
if(prediction_index_ >= prediction_info_.size()){
prediction_index_--;
on_pushButton_pause_clicked();
QMessageBox::information(this, "Error", "已经是最后一帧!");
return;
}
UpdateCarBox();
UpdateObsBox();
DispPredictionInfo();
}
void Widget::PlayControlInfo(bool still)
{
if(still) // only control
{
if(CheckEmpty(control_info_)){
QMessageBox::information(this, "Error", "没有控制信息!");
}
int start = ui->lineEdit_start->text().toInt();
int end = ui->lineEdit_end->text().toInt();
if(start < 1 || start > control_info_.size())
{
QMessageBox::information(this, "Error", "起始位置非法");
start = 1;
}
if(end < 1 || end > control_info_.size() )
{
QMessageBox::information(this, "Error", "终点位置非法");
end = control_info_.size();
}
if(start >= end)
{
QMessageBox::information(this, "Error", "位置设置非法");
if(start > end){
int tem = end;
end = start;
start = tem;
}else{
start = 1;
}
}
ui->lineEdit_start->setText(QString::number(start));
ui->lineEdit_end->setText(QString::number(end));
control_start_ = start - 1;
control_end_ = end - 1;
qDebug() << control_start_ << " " << control_end_;
QVector<double> x;
QVector<double> y[40];
for(int i = control_start_; i < control_end_ && i < control_info_.size(); ++i)
{
x.push_back(i);
for(int j = 0; j < 40; ++j)
{
y[j].push_back(control_info_[i].info[j]);
}
}
for(int i = 0; i < 40; ++i)
{
ui->control_plot->graph(i)->data().data()->clear();
PlotScatters(x, y[i], Qt::black, i, true, 1, 3, false);
ComboBoxSelectionChanged();
}
// PlotScatters(x,actual_y,Qt::black, control_graph_manage_.value("actual_speed"), true, 1, 3, false);
// PlotScatters(x,expected_y,Qt::darkYellow, control_graph_manage_.value("expected_speed"), true, 1, 3,false);
// PlotScatters(x,lateral_y,Qt::darkBlue, control_graph_manage_.value("lateral_deviation"), true, 1, 3,false);
// AdjustPlotRange(false);
ui->control_plot->rescaleAxes(true);
}
else // 联合播放
{
if(control_end_ >= control_info_.size()){
QMessageBox::information(this, "Error", "已经是最后一行数据!");
on_pushButton_pause_clicked();
return;
}
double x = control_end_;/*
double actual_y = control_info_[control_end_].actual_speed;
double expected_y = control_info_[control_end_].expected_speed;*/
for(int i = 0; i < 40 ; ++i)
{
double y = control_info_[control_end_].info[i];
PlotScatter(x, y, Qt::black, i, true, 1, 3, false);
}
ui->lineEdit_start->setText(QString::number(control_start_));
ui->lineEdit_end->setText(QString::number(control_end_));
if(control_end_ - control_start_ >= 50)
{
ui->control_plot->xAxis->setRange(control_end_ - 50,control_end_ + 5);
}
else
{
ui->control_plot->xAxis->setRange(control_start_, control_start_ + 50);
}
ui->control_plot->replot();
// ui->control_plot->xAxis->rescale(true);
// ui->control_plot->rescaleAxes();
// PlotScatter(x,actual_y,Qt::black, control_graph_manage_.value("actual_speed"), false, 1, 3, true);
// PlotScatter(x,expected_y,Qt::darkYellow, control_graph_manage_.value("expected_speed"), false, 1, 3,true);
}
}
bool Widget::SearchSyncTime(PlayMode mode)
{
int sync_icu = -1;
int sync_prediction = -1;
int sync_ctrl = -1;
if(sync_ctrl_index_ >= control_info_.size() || sync_ctrl_index_ < 0) sync_ctrl_index_ = 0;
TimeStamp initial;
if(mode == PlayMode::kICUAndPrediction) //icu && prediction
{
//TODO tired 不知道怎么写,没有什么思路
}
else if (mode == PlayMode::kPredictionAndControl)//prediction&&control
{
// qDebug()<<control_end_;
if(control_info_[sync_ctrl_index_].time > prediction_info_[prediction_index_].time)
{
// qDebug()<<"prediction";
initial = control_info_[sync_ctrl_index_].time;
sync_ctrl = sync_ctrl_index_;
}
else if(control_info_[sync_ctrl_index_].time < prediction_info_[prediction_index_].time)
{
// qDebug()<<"control";
initial = prediction_info_[prediction_index_].time;
sync_prediction = prediction_index_;
}
else if(control_info_[sync_ctrl_index_].time == prediction_info_[prediction_index_].time)
{
// control_end_ = control_end_;
// qDebug()<<"equal";
control_start_ = sync_ctrl_index_;
control_end_ = control_start_;
return true;
}
for(int i_ctrl = sync_ctrl_index_, i_prediction = prediction_index_; i_ctrl < control_info_.size() && i_prediction < prediction_info_.size(); )
{
if(sync_ctrl != -1)
{
if(initial == prediction_info_[i_prediction].time)
{
sync_prediction = i_prediction;
break;
}
else
{
i_prediction++;
}
}
else if(sync_prediction != -1)
{
if(initial == control_info_[i_ctrl].time)
{
sync_ctrl = i_ctrl;
break;
}
else
{
i_ctrl++;
}
}
}
if(sync_ctrl < 0 || sync_prediction < 0)
{
return false;
}
else
{
control_start_ = sync_ctrl;
control_end_ = sync_ctrl;
prediction_index_ = sync_prediction;
return true;
}
}
else if(mode == 5)//icu&&prediction&&control
{
//TODO!!!!!!
}
return false;
}
void Widget::AdjustPlotRange(bool prediction){
if(prediction)
{
if(ccu_map_.empty())
{
ui->prediction_plot->xAxis->setRange(415000,416250);
ui->prediction_plot->yAxis->setRange(4.62779e+06,4.62846e+06);
ui->prediction_plot->replot();
return;
}
else
{
double x_middle = (plot_max_x_ + plot_min_x_)/2;
double y_middle = (plot_max_y_ + plot_min_y_)/2;
double _long = (plot_max_x_ - plot_min_x_) > (plot_max_y_ - plot_min_y_) ? (plot_max_x_ - plot_min_x_):(plot_max_y_ - plot_min_y_);
double half_long = _long / 2.0;
ui->prediction_plot->xAxis->setRange(x_middle - half_long -5e-4,x_middle + half_long + 5e-4);
ui->prediction_plot->yAxis->setRange(y_middle - half_long -5e-4,y_middle + half_long + 5e-4);
ui->prediction_plot->replot();
}
}
else
{
qDebug() << " control start "<<control_start_<<" "<<control_end_;
double x_middle = (control_start_ + control_end_)/2;
double y_middle = (ctrl_max_y_ + ctrl_min_y_)/2;
double x_long = control_end_ - control_start_;
double y_long = ctrl_max_y_ - ctrl_min_y_;
double x_half_long = x_long / 2.0;
double y_half_long = y_long / 2.0;
ui->control_plot->xAxis->setRange(x_middle - x_half_long - 0.5,x_middle + x_half_long + 0.5);
ui->control_plot->yAxis->setRange(y_middle - y_half_long - 0.5,y_middle + y_half_long + 10);
ui->control_plot->replot();
}
}
void Widget::keyPressEvent(QKeyEvent *k)
{
if(k->key() == Qt::Key_S || k->key() == Qt::Key_D){
on_pushButton_next_clicked();
}
else if(k->key() == Qt::Key_A || k -> key() == Qt::Key_W){
on_pushButton_pre_clicked();
}
}
void Widget::MousePress(QMouseEvent * event)
{
QList<QCPAxis*>axes;
if (ui->control_plot->xAxis->selectedParts().testFlag(QCPAxis::spAxis))
{
axes << ui->control_plot->xAxis;
ui->control_plot->axisRect()->setRangeDragAxes(axes);
ui->control_plot->axisRect()->setRangeDrag(ui->control_plot->xAxis->orientation());
}
else if (ui->control_plot->yAxis->selectedParts().testFlag(QCPAxis::spAxis))
{
axes << ui->control_plot->yAxis;
ui->control_plot->axisRect()->setRangeDragAxes(axes);
ui->control_plot->axisRect()->setRangeDrag(ui->control_plot->yAxis->orientation());
}
else if (ui->control_plot->yAxis2->selectedParts().testFlag(QCPAxis::spAxis))
{
axes << ui->control_plot->yAxis2;
ui->control_plot->axisRect()->setRangeDragAxes(axes);
ui->control_plot->axisRect()->setRangeDrag(ui->control_plot->yAxis2->orientation());
}
else
{