Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdr_robot/sensors/microphone.h>
00023
00024 namespace stdr_robot {
00025
00034 SoundSensor::SoundSensor(
00035 const nav_msgs::OccupancyGrid& map,
00036 const stdr_msgs::SoundSensorMsg& msg,
00037 const std::string& name,
00038 ros::NodeHandle& n)
00039 : Sensor(map, name, n, msg.pose, msg.frame_id, msg.frequency)
00040 {
00041 _description = msg;
00042
00043 _publisher = n.advertise<stdr_msgs::SoundSensorMeasurementMsg>
00044 ( _namespace + "/" + msg.frame_id, 1 );
00045
00046 sound_sources_subscriber_ = n.subscribe(
00047 "stdr_server/sound_sources_list",
00048 1,
00049 &SoundSensor::receiveSoundSources,
00050 this);
00051 }
00052
00057 SoundSensor::~SoundSensor(void)
00058 {
00059
00060 }
00061
00066 void SoundSensor::updateSensorCallback()
00067 {
00068 if (sound_sources_.sound_sources.size() == 0) return;
00069
00070 stdr_msgs::SoundSensorMeasurementMsg measuredSourcesMsg;
00071
00072 measuredSourcesMsg.header.frame_id = _description.frame_id;
00073 measuredSourcesMsg.sound_dbs = 0;
00074
00075 float max_range = _description.maxRange;
00076 float sensor_th = tf::getYaw(_sensorTransform.getRotation());
00077 float min_angle = sensor_th - _description.angleSpan / 2.0;
00078 float max_angle = sensor_th + _description.angleSpan / 2.0;
00079
00081 for(unsigned int i = 0 ; i < sound_sources_.sound_sources.size() ; i++)
00082 {
00084 float sensor_x = _sensorTransform.getOrigin().x();
00085 float sensor_y = _sensorTransform.getOrigin().y();
00086 float dist = sqrt(
00087 pow(sensor_x - sound_sources_.sound_sources[i].pose.x, 2) +
00088 pow(sensor_y - sound_sources_.sound_sources[i].pose.y, 2)
00089 );
00090 if(dist > max_range)
00091 {
00092 continue;
00093 }
00094
00096 float ang = atan2(
00097 sound_sources_.sound_sources[i].pose.y - sensor_y,
00098 sound_sources_.sound_sources[i].pose.x - sensor_x);
00099
00100 if(!stdr_robot::angCheck(ang, min_angle, max_angle))
00101 {
00102 continue;
00103 }
00104
00105 if(dist > 0.5)
00106 {
00107 measuredSourcesMsg.sound_dbs += sound_sources_.sound_sources[i].dbs *
00108 pow(0.5, 2) / pow(dist, 2);
00109 }
00110 else
00111 {
00112 measuredSourcesMsg.sound_dbs += sound_sources_.sound_sources[i].dbs;
00113 }
00114 }
00115
00116 measuredSourcesMsg.header.stamp = ros::Time::now();
00117 measuredSourcesMsg.header.frame_id =
00118 _namespace + "_" + _description.frame_id;
00119 _publisher.publish( measuredSourcesMsg );
00120 }
00121
00125 void SoundSensor::receiveSoundSources(const stdr_msgs::SoundSourceVector& msg)
00126 {
00127 sound_sources_ = msg;
00128 }
00129
00130 }