speaker.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
00003  *    Georg Martius  <georg dot martius at web dot de>                     *
00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
00006  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
00007  *                                                                         *
00008  *   This program is free software; you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation; either version 2 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  *   This program is distributed in the hope that it will be useful,       *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU General Public License for more details.                          *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU General Public License     *
00019  *   along with this program; if not, write to the                         *
00020  *   Free Software Foundation, Inc.,                                       *
00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00022  *                                                                         *
00023  ***************************************************************************/
00024 #ifndef         SPEAKER_H_
00025 # define        SPEAKER_H_
00026 
00027 #include "motor.h"
00028 
00029 namespace lpzrobots {
00030   
00031   /**
00032      This "motor" emulates a speaker or piezo element to produce sound.
00033      The sound can be detected by sound sensors (@see SoundSensor).
00034      Note that obstacles do not interact with the sound in any way.
00035    */
00036   class Speaker: public Motor {
00037   public: 
00038     Speaker(float frequency)
00039       : frequency(frequency) {
00040     }
00041     virtual ~Speaker() {};
00042     
00043     virtual void init(Primitive* own){
00044       this->own=own;
00045     }
00046 
00047     virtual int getMotorNumber() const{
00048       return 1;
00049     };
00050 
00051     virtual bool act(GlobalData& globaldata){
00052       globaldata.sounds.push_back(Sound(globaldata.time, own->getPosition(),
00053                                         intensity,frequency, (void*)own));
00054       return true;
00055     }
00056 
00057     virtual int set(const motor* values, int length){
00058       if(length>0)
00059         intensity=values[0];
00060       return 1;
00061     };    
00062     
00063   private:
00064     Primitive* own;
00065     float frequency;    
00066     float intensity;
00067   };
00068 
00069 }
00070 
00071 #endif      /* !SPEAKER_H_ */
Generated on Thu Jun 28 14:45:37 2012 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3