Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "SonarPainter.h"
00012
00013 #include "Messages/FastRobotPoseM.h"
00014 #include "Devices/PioneerRobot/SonarSensorConfig.h"
00015 #include "Messages/SonarDataM.h"
00016
00017 #include <QtOpenGL>
00018 #include <GL/glut.h>
00019
00020
00021 #define THIS SonarPainter
00022
00023 THIS::THIS() : PainterPlugin( )
00024 {
00025 setName ( "Sonar Data" );
00026 }
00027
00028
00029 THIS::~THIS()
00030 {
00031 }
00032
00033
00034 void THIS::processMessage ( Message* newMessage )
00035 {
00036 PainterPlugin::processMessage ( newMessage );
00037 switch ( newMessage->getType() )
00038 {
00039 case MessageTypes::SONAR_DATA_M:
00040 {
00041 SonarDataM* message = Message::castTo<SonarDataM> ( newMessage );
00042 if ( message )
00043 {
00044 m_SonarData = message->getRangeVector();
00045 requestRedraw();
00046 }
00047 break;
00048 }
00049
00050 case MessageTypes::FAST_ROBOT_POSE_M:
00051 {
00052 FastRobotPoseM* message = Message::castTo<FastRobotPoseM> ( newMessage );
00053 if ( message )
00054 {
00055 m_RobotPose = message->getRobotPose();
00056 requestRedraw();
00057 }
00058 break;
00059 }
00060
00061 default:
00062 break;
00063
00064 }
00065 }
00066
00067 void THIS::paint ( float next2DLayer )
00068 {
00069
00070 glTranslatef ( m_RobotPose.x(), m_RobotPose.y(), next2DLayer );
00071 glRotatef ( m_RobotPose.theta() * 180.0 / M_PI, 0.0, 0.0, 1.0 );
00072 glPolygonMode ( GL_FRONT_AND_BACK, GL_FILL );
00073
00074 glColor4f ( 0.0, 1.0, 0.0, 0.7 );
00075
00076 glEnable ( GL_BLEND );
00077 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
00078
00079 for ( unsigned int i = 0; i < m_SonarData.size(); i++ )
00080 {
00081 int range = m_SonarData[i];
00082 if ( range >= SonarSensorConfig::VALID_MIN_RANGE && range <= SonarSensorConfig::VALID_MAX_RANGE )
00083 {
00084 float sensorAngle = 6.0;
00085 float sensorFatFactor = 100;
00086 glPushMatrix();
00087
00088 glTranslatef ( SonarSensorConfig::SONAR_SENSOR_POSITIONS_X[i], SonarSensorConfig::SONAR_SENSOR_POSITIONS_Y[i], 10.0 );
00089
00090 glRotatef ( SonarSensorConfig::SONAR_SENSOR_ORIENTATIONS_DEG[i], 0.0, 0.0, 1.0 );
00091
00092 float Rad = 1.0f / 180 * 3.141592654;
00093
00094 glBegin ( GL_POLYGON );
00095 glVertex3f ( cos ( Rad * sensorAngle ) * ( range + sensorFatFactor ), sin ( Rad * sensorAngle ) * range, 0.0 );
00096 glVertex3f ( cos ( Rad * sensorAngle ) * ( range + sensorFatFactor ), ( -1 ) * sin ( Rad * sensorAngle ) * range, 0.0 );
00097 glVertex3f ( cos ( Rad * sensorAngle ) * ( range ), ( -1 ) * sin ( Rad * sensorAngle ) * range, 0.0 );
00098 glVertex3f ( cos ( Rad * sensorAngle ) * ( range ), sin ( Rad * sensorAngle ) * range, 0.0 );
00099 glEnd();
00100
00101 glPopMatrix();
00102 }
00103 }
00104 glDisable ( GL_BLEND );
00105 }
00106
00107 #undef THIS