Hokuyo.cpp
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     //IR01_update = 0;
00016     //IR02_update = 0;
00017     hokuyo_points = new Hokuyo_Points [683];
00018     showIR = false;
00019     showLRF = false;
00020 
00021 }
00022 
00023 Hokuyo::~Hokuyo()
00024 
00025 {
00026     //delete [] hokuyo_points;
00027     //hokuyo_points = NULL;
00028 }
00029 
00030 
00031 void Hokuyo::paintEvent(QPaintEvent *event)
00032 {
00033 
00034 //  QPen pen(Qt::black, 2, Qt::SolidLine);
00035 
00036 //  QPainter painter(this);
00037 
00038 //  painter.setPen(pen);
00039 //  painter.drawLine(20, 40, 250, 40);
00040 
00041 //  pen.setStyle(Qt::DashLine);
00042 //  painter.setPen(pen);
00043 //  painter.drawLine(20, 80, 250, 80);
00044 
00045 //  pen.setStyle(Qt::DashDotLine);
00046 //  painter.setPen(pen);
00047 //  painter.drawLine(20, 120, 250, 120);
00048 
00049 //  pen.setStyle(Qt::DotLishowlinesne);
00050 //  painter.setPen(pen);
00051 //  painter.drawLine(20, 160, 250, 160);
00052 
00053 //  pen.setStyle(Qt::DashDotDotLine);
00054 //  painter.setPen(pen);
00055 //  painter.drawLine(20, 200, 250, 200);
00056 
00057 
00058 //  QVector<qreal> dashes;
00059 //  qreal space = 4;
00060 
00061 //  dashes << 1 << space << 5 << space;
00062 
00063 //  pen.setStyle(Qt::CustomDashLine);
00064 //  pen.setDashPattern(dashes);
00065 //  painter.setPen(pen);
00066 //  painter.drawLine(20, 240, 250, 240);
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        // painter.setBrush(brush);
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     //painter.setPen(pen1);
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          //       qDebug("x value = %d  \n",hokuyo_points[it].x );
00146          //       qDebug("y value = %d  \n",hokuyo_points[it].y );
00147                 count ++;
00148             }
00149         }
00150 
00151         //qDebug("How many points have been plotted ? %d \n",count);
00152 
00153         flag = 1;
00154    }
00155 
00156 
00157 }
00158 
00159 void Hokuyo::hokuyo_update(Hokuyo_Points* hokuyo_points_)
00160 {
00161 
00162 //    for(int it=0;it<683;it++)
00163 //    {
00164 //       qDebug("x value = %f  \n",hokuyo_points_[it].x );
00165 //       qDebug("y value = %f  \n",hokuyo_points_[it].y );
00166 //    }
00167 
00168     hokuyo_points = hokuyo_points_;
00169 
00170     //this->setAutoFillBackground(true);
00171 
00172     //this->repaint();
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   // qDebug("GOT IR vales IR01 = %f; IR02 = %f  \n",IR01_update,IR02_update); 
00184 
00185    //this->repaint();
00186 
00187    this->update();
00188 }


corobot_teleop
Author(s): Morgan Cormier/Gang Li/mcormier@coroware.com
autogenerated on Tue Jan 7 2014 11:39:41