Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
speaker.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef SPEAKER_H_
25 #define SPEAKER_H_
26 
27 #include "motor.h"
28 
29 namespace lpzrobots {
30 
31  /**
32  This "motor" emulates a speaker or piezo element to produce sound.
33  The sound can be detected by sound sensors (@see SoundSensor).
34  Note that obstacles do not interact with the sound in any way.
35  */
36  class Speaker: public Motor {
37  public:
38  Speaker(float frequency, double visualSize = 0.5, Pos visualOffset = Pos(0,0,1))
39  : own(0), frequency(frequency), intensity(0.0),
40  visualSize(visualSize), visualOffset(visualOffset) {
41  }
42  virtual ~Speaker() {};
43 
44  virtual void init(Primitive* own, Joint* joint = 0){
45  this->own=own;
46  }
47 
48  virtual int getMotorNumber() const{
49  return 1;
50  };
51 
52  virtual bool act(GlobalData& globaldata){
53  Sound s = Sound(globaldata.time, own->getPosition(),
54  intensity,frequency, (void*)own);
55  globaldata.sounds.push_back(s);
56  s.createVisual(globaldata, visualSize, visualOffset);
57 
58  return true;
59  }
60 
61  virtual int set(const motor* values, int length){
62  if(length>0)
63  intensity=std::max(std::min(values[0],1.0),0.0);
64  return 1;
65  };
66 
67  private:
68  Primitive* own;
69  float frequency;
70  float intensity;
71 
72  double visualSize;
73  Pos visualOffset;
74  };
75 
76 }
77 
78 #endif /* !SPEAKER_H_ */
double time
Definition: globaldata.h:77
Definition: joint.h:41
SoundList sounds
< this is used to be able to attach objects to the static environment
Definition: globaldata.h:72
This "motor" emulates a speaker or piezo element to produce sound.
Definition: speaker.h:36
Definition: pos.h:36
void createVisual(GlobalData &globalData, double visualSize, Pos visualOffset) const
Definition: sound.cpp:43
Speaker(float frequency, double visualSize=0.5, Pos visualOffset=Pos(0, 0, 1))
Definition: speaker.h:38
Abstact base class for attachable motors.
Definition: motor.h:35
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
double max(const matrix::Matrix &v)
returns the largest element
Definition: controller_misc.cpp:318
Data structure holding all essential global information.
Definition: globaldata.h:57
Object that represents a sound signal in the simulator.
Definition: sound.h:35
virtual bool act(GlobalData &globaldata)
performs the actions, This is usually called in doInternalStuff() from the robot
Definition: speaker.h:52
virtual ~Speaker()
Definition: speaker.h:42
double motor
Definition: types.h:30
virtual void init(Primitive *own, Joint *joint=0)
initialises motor with body of robot
Definition: speaker.h:44
virtual int set(const motor *values, int length)
sends the action commands to the motor.
Definition: speaker.h:61
virtual Pos getPosition() const
returns the position
Definition: primitive.cpp:181
double min(const matrix::Matrix &v)
returns the smallest element
Definition: controller_misc.cpp:307
virtual int getMotorNumber() const
return the dimensionality of this motor
Definition: speaker.h:48