qslamandnavwidget.cpp
Go to the documentation of this file.
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 }
QSLAMandNavWidget::keyPressEvent
virtual void keyPressEvent(QKeyEvent *e)
Definition: qslamandnavwidget.cpp:40
QSLAMandNavWidget::goHome
bool goHome
Definition: qslamandnavwidget.h:22
QSLAMandNavWidget::slamFinished
bool slamFinished
Definition: qslamandnavwidget.h:18
QSLAMandNavWidget::paintEvent
virtual void paintEvent(QPaintEvent *paintevent)
Definition: qslamandnavwidget.cpp:96
QSLAMandNavWidget::startWalker
bool startWalker
Definition: qslamandnavwidget.h:20
QSLAMandNavWidget::slamRestart
bool slamRestart
Definition: qslamandnavwidget.h:17
QSLAMandNavWidget::wantsQuit
bool wantsQuit
Definition: qslamandnavwidget.h:23
QSLAMandNavWidget::dumper
QPixmapDumper dumper
Definition: qslamandnavwidget.h:28
QSLAMandNavWidget::mousePressEvent
virtual void mousePressEvent(QMouseEvent *e)
Definition: qslamandnavwidget.cpp:26
GMapping
Definition: configfile.cpp:34
QSLAMandNavWidget::robotPose
GMapping::IntPoint robotPose
Definition: qslamandnavwidget.h:14
QMapPainter::m_pixmap
QPixmap * m_pixmap
Definition: qmappainter.h:26
GMapping::IntPoint
point< int > IntPoint
Definition: point.h:201
QSLAMandNavWidget::enableMotion
bool enableMotion
Definition: qslamandnavwidget.h:19
QSLAMandNavWidget::trajectoryPoints
std::list< GMapping::IntPoint > trajectoryPoints
Definition: qslamandnavwidget.h:13
QSLAMandNavWidget::trajectorySent
bool trajectorySent
Definition: qslamandnavwidget.h:21
GMapping::point::y
T y
Definition: point.h:16
QPixmapDumper::dump
bool dump(const QPixmap &pixmap)
Definition: qpixmapdumper.cpp:20
QMapPainter
Definition: qmappainter.h:11
QSLAMandNavWidget::QSLAMandNavWidget
QSLAMandNavWidget(QWidget *parent=0, const char *name=0, WFlags f=0)
Definition: qslamandnavwidget.cpp:6
QSLAMandNavWidget::printHelp
bool printHelp
Definition: qslamandnavwidget.h:24
GMapping::point
Definition: point.h:13
QSLAMandNavWidget::writeImages
bool writeImages
Definition: qslamandnavwidget.h:26
QSLAMandNavWidget::drawRobot
bool drawRobot
Definition: qslamandnavwidget.h:27
QSLAMandNavWidget::saveGoalPoints
bool saveGoalPoints
Definition: qslamandnavwidget.h:25
qslamandnavwidget.h
QSLAMandNavWidget::~QSLAMandNavWidget
virtual ~QSLAMandNavWidget()
Definition: qslamandnavwidget.cpp:23
QSLAMandNavWidget::robotHeading
double robotHeading
Definition: qslamandnavwidget.h:15
GMapping::point::x
T x
Definition: point.h:16


openslam_gmapping
Author(s): Cyrill Stachniss, Udo Frese, Giorgio Grisetti, Wolfram Burgard
autogenerated on Thu Oct 19 2023 02:25:51