Go to the documentation of this file.00001 #include "Hokuyo.h"
00002 #include <QApplication>
00003 #include <QPainter>
00004
00005 #include <QtGui>
00006
00007 #define MAX_RANGE 0.80 // 80cm
00008
00009 Hokuyo::Hokuyo(QWidget *parent)
00010 : QWidget(parent)
00011 {
00012 showlines = false;
00013 flag = 1;
00014 hokuyo_points = NULL;
00015
00016
00017 hokuyo_points = new Hokuyo_Points [683];
00018 showIR = false;
00019 showLRF = false;
00020
00021 }
00022
00023 Hokuyo::~Hokuyo()
00024
00025 {
00026
00027
00028 }
00029
00030
00031 void Hokuyo::paintEvent(QPaintEvent *event)
00032 {
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 flag = 0;
00069 int center_h = (int) (this->parentWidget()->height() /2);
00070 int center_w = (int) (this->parentWidget()->width() /2);
00071 QPainter painter(this);
00072
00073
00074
00075 QPen pen2(Qt::black, 2, Qt::SolidLine);
00076 painter.setPen(pen2);
00077 painter.setBrush(Qt::red);
00078 QRectF rectangle(center_w - 2, center_h-2, 4, 4);
00079 painter.drawEllipse(rectangle);
00080
00081
00082 if(showLRF)
00083 {
00084 QPen pen(Qt::black, 2, Qt::DashDotDotLine);
00085
00086 painter.setPen(pen);
00087
00088 painter.drawLine(20, 40, 120, 40);
00089 }
00090
00091 else if(showIR)
00092 {
00093 QPen pen(Qt::black, 2, Qt::SolidLine);
00094
00095 painter.setPen(pen);
00096
00097 painter.drawLine(20, 40, 20 + center_h, 40);
00098
00099 }
00100
00101 if(showIR)
00102 {
00103 painter.setBrush(Qt::cyan);
00104
00105 QPen pen1(Qt::black, 2, Qt::SolidLine);
00106
00107
00108 QPointF points_front[3];
00109 QPointF points_back[3];
00110
00111
00112 points_front[0] = QPointF(center_w,center_h);
00113 points_front[1] = QPointF(center_w - 50, center_h + (float)this->IR01_update * center_h);
00114 points_front[2] = QPointF(center_w + 50, center_h + (float)this->IR01_update * center_h);
00115
00116 painter.setPen(pen1);
00117 painter.drawPolygon(points_front,3);
00118
00119 painter.setBrush(Qt::darkCyan);
00120
00121 points_back[0] = QPointF(center_w, center_h);
00122 points_back[1] = QPointF(center_w - 50, center_h - (float)this->IR02_update * center_h);
00123 points_back[2] = QPointF(center_w + 50, center_h - (float)this->IR02_update * center_h);
00124
00125
00126
00127 painter.drawPolygon(points_back,3);
00128 }
00129
00130
00131 else if(showLRF)
00132 {
00133 QPen pen3(Qt::black, 2, Qt::DashDotDotLine);
00134 painter.setPen(pen3);
00135
00136 int count = 0;
00137
00138 if(hokuyo_points!=NULL)
00139 {
00140 for(int it=0;it<683;it++)
00141 {
00142 painter.drawPoint(hokuyo_points[it].x * 100 + 300, -(hokuyo_points[it].y * 100) + 300);
00143 if(showlines)
00144 painter.drawLine(300,300,hokuyo_points[it].x * 100 + 300, -(hokuyo_points[it].y * 100) + 300);
00145
00146
00147 count ++;
00148 }
00149 }
00150
00151
00152
00153 flag = 1;
00154 }
00155
00156
00157 }
00158
00159 void Hokuyo::hokuyo_update(Hokuyo_Points* hokuyo_points_)
00160 {
00161
00162
00163
00164
00165
00166
00167
00168 hokuyo_points = hokuyo_points_;
00169
00170
00171
00172
00173
00174 this->update();
00175
00176 }
00177
00178 void Hokuyo::IR_update(double IR01_new, double IR02_new)
00179 {
00180 this->IR01_update = IR01_new;
00181 this->IR02_update = IR02_new;
00182
00183
00184
00185
00186
00187 this->update();
00188 }