speaker.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
00003  *    martius@informatik.uni-leipzig.de                                    *
00004  *    fhesse@informatik.uni-leipzig.de                                     *
00005  *    der@informatik.uni-leipzig.de                                        *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************
00022  ** Started on  Mon Oct 15 18:01:12 2007 Georg Martius
00023  ** Last update Mon Oct 15 18:01:12 2007 Georg Martius
00024  *                                                                         *
00025  *  DESCRIPTION                                                            *
00026  *                                                                         *
00027  *   $Log: speaker.h,v $
00028  *   Revision 1.2  2009/12/01 17:32:10  martius
00029  *   adapted Makefiles to ignore backward compat. errors
00030  *
00031  *   Revision 1.1  2007/11/07 13:17:40  martius
00032  *   motors in a general sense (like sound, light,...)
00033  *
00034  *
00035  *                                                                 *
00036  ***************************************************************************/
00037 #ifndef         SPEAKER_H_
00038 # define        SPEAKER_H_
00039 
00040 #include "motor.h"
00041 
00042 namespace lpzrobots {
00043   
00044   /**
00045      This "motor" emulates a speaker or piezo element to produce sound.
00046      The sound can be detected by sound sensors (@see SoundSensor).
00047      Note that obstacles do not interact with the sound in any way.
00048    */
00049   class Speaker: public Motor {
00050   public: 
00051     Speaker(float frequency)
00052       : frequency(frequency) {
00053     }
00054     virtual ~Speaker() {};
00055     
00056     virtual void init(Primitive* own){
00057       this->own=own;
00058     }
00059 
00060     virtual int getMotorNumber() const{
00061       return 1;
00062     };
00063 
00064     virtual bool act(GlobalData& globaldata){
00065       globaldata.sounds.push_back(Sound(globaldata.time, own->getPosition(),
00066                                         intensity,frequency, (void*)own));
00067       return true;
00068     }
00069 
00070     virtual int set(const motor* values, int length){
00071       if(length>0)
00072         intensity=values[0];
00073       return 1;
00074     };    
00075     
00076   private:
00077     Primitive* own;
00078     float frequency;    
00079     float intensity;
00080   };
00081 
00082 }
00083 
00084 #endif      /* !SPEAKER_H_ */
Generated on Fri Nov 4 10:59:39 2011 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3