qslamandnavwidget.cpp
Go to the documentation of this file.
1 #include "qslamandnavwidget.h"
2 #include <stdio.h>
3 using namespace GMapping;
4 
5 
6 QSLAMandNavWidget::QSLAMandNavWidget( QWidget * parent, const char * name, WFlags f)
7 : QMapPainter(parent, name, f), dumper("slamandnav", 1){
8  robotPose=IntPoint(0,0);
9  robotHeading=0;
10  slamRestart=false;
11  slamFinished=false;
12  enableMotion=false;
13  startWalker=false;
14  trajectorySent=false;
15  goHome=false;
16  wantsQuit=false;
17  printHelp=false;
18  saveGoalPoints=false;
19  writeImages=false;
20  drawRobot=true;
21 }
22 
24 
25 
26 void QSLAMandNavWidget::mousePressEvent ( QMouseEvent * e ){
27  QPoint p=e->pos();
28  int mx=p.x();
29  int my=height()-p.y();
30  if ( e->state()&Qt::ShiftButton && e->button()==Qt::LeftButton) {
31  if (trajectorySent)
32  trajectoryPoints.clear();
33  e->accept();
34  IntPoint p=IntPoint(mx, my);
35  trajectoryPoints.push_back(p);
36  trajectorySent=false;
37  }
38 }
39 
40 void QSLAMandNavWidget::keyPressEvent ( QKeyEvent * e ){
41  if (e->key()==Qt::Key_Delete){
42  e->accept();
43  if (!trajectoryPoints.empty())
44  trajectoryPoints.pop_back();
45  }
46  if (e->key()==Qt::Key_S){
47  e->accept();
49  }
50  if (e->key()==Qt::Key_W){
51  e->accept();
53  }
54  if (e->key()==Qt::Key_G){
55  e->accept();
56  slamRestart=true;
57  }
58  if (e->key()==Qt::Key_T){
59  e->accept();
60  trajectorySent=true;
61  }
62  if (e->key()==Qt::Key_R){
63  e->accept();
64  goHome=true;
65  }
66  if (e->key()==Qt::Key_C){
67  e->accept();
68  slamFinished=true;
69 
70  }
71  if (e->key()==Qt::Key_Q){
72  e->accept();
73  wantsQuit=true;
74 
75  }
76  if (e->key()==Qt::Key_H){
77  e->accept();
78  printHelp=true;
79  //BABSI
80  //insert the help here
81  }
82  if (e->key()==Qt::Key_Y){
83  e->accept();
84  saveGoalPoints=true;
85  //BABSI
86  //insert the help here
87  }
88  if (e->key()==Qt::Key_D){
89  e->accept();
91  //BABSI
92  //insert the help here
93  }
94 }
95 
96 void QSLAMandNavWidget::paintEvent ( QPaintEvent * ){
97  QPixmap pixmap(*m_pixmap);
98  QPainter painter(&pixmap);
99  if (trajectorySent)
100  painter.setPen(Qt::red);
101  bool first=true;
102  int oldx=0, oldy=0;
103  //paint the path
104  for (std::list<IntPoint>::const_iterator it=trajectoryPoints.begin(); it!=trajectoryPoints.end(); it++){
105  int x=it->x;
106  int y=height()-it->y;
107  if (! first)
108  painter.drawLine(oldx, oldy, x,y);
109  oldx=x;
110  oldy=y;
111  first=false;
112  }
113 
114  //paint the robot
115  if (drawRobot){
116  painter.setPen(Qt::black);
117  int rx=robotPose.x;
118  int ry=height()-robotPose.y;
119  int robotSize=6;
120  painter.drawLine(rx, ry,
121  rx+(int)(robotSize*cos(robotHeading)), ry-(int)(robotSize*sin(robotHeading)));
122  painter.drawEllipse(rx-robotSize, ry-robotSize, 2*robotSize, 2*robotSize);
123  }
124  if (writeImages){
125  dumper.dump(pixmap);
126  }
127  bitBlt(this,0,0,&pixmap,0,0,pixmap.width(),pixmap.height(),CopyROP);
128 }
virtual void mousePressEvent(QMouseEvent *e)
virtual void keyPressEvent(QKeyEvent *e)
QPixmapDumper dumper
point< int > IntPoint
Definition: point.h:201
std::list< GMapping::IntPoint > trajectoryPoints
QPixmap * m_pixmap
Definition: qmappainter.h:26
bool dump(const QPixmap &pixmap)
QSLAMandNavWidget(QWidget *parent=0, const char *name=0, WFlags f=0)
GMapping::IntPoint robotPose
virtual void paintEvent(QPaintEvent *paintevent)


openslam_gmapping
Author(s): Giorgio Grisetti, Cyrill Stachniss, Wolfram Burgard
autogenerated on Mon Jun 10 2019 14:04:22