sensor_base.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  STDR Simulator - Simple Two DImensional Robot Simulator
3  Copyright (C) 2013 STDR Simulator
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 3 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 
16  Authors :
17  * Manos Tsardoulias, etsardou@gmail.com
18  * Aris Thallas, aris.thallas@gmail.com
19  * Chris Zalidis, zalidis@gmail.com
20 ******************************************************************************/
21 
23 
24 namespace stdr_robot {
25 
37  const nav_msgs::OccupancyGrid& map,
38  const std::string& name,
39  ros::NodeHandle& n,
40  const geometry_msgs::Pose2D& sensorPose,
41  const std::string& sensorFrameId,
42  float updateFrequency)
43  :
44  _map(map),
45  _namespace(name),
46  _sensorPose(sensorPose),
47  _sensorFrameId(sensorFrameId),
48  _updateFrequency(updateFrequency),
49  _gotTransform(false)
50  {
51  _timer = n.createTimer(
52  ros::Duration(1/updateFrequency), &Sensor::checkAndUpdateSensor, this);
54  ros::Duration(1/(2*updateFrequency)), &Sensor::updateTransform, this);
55  }
56 
57 
64  {
65  if (!_gotTransform) {
66  return;
67  }
68 
70  }
71 
77  {
78  try {
79  _tfListener.waitForTransform("map_static",
80  _namespace + "_" + _sensorFrameId,
81  ros::Time(0),
82  ros::Duration(0.2));
83  _tfListener.lookupTransform("map_static",
84  _namespace + "_" + _sensorFrameId,
86  _gotTransform = true;
87  }
88  catch (tf::TransformException ex) {
89  ROS_DEBUG("%s",ex.what());
90  }
91  }
92 } // namespace stdr_robot
const std::string & _namespace
< The base for the sensor frame_id
Definition: sensor_base.h:114
tf::TransformListener _tfListener
ROS transform from sensor to map.
Definition: sensor_base.h:133
void checkAndUpdateSensor(const ros::TimerEvent &ev)
Checks if transform is available and calls updateSensorCallback()
Definition: sensor_base.cpp:63
The main namespace for STDR Robot.
Definition: exceptions.h:27
void updateTransform(const ros::TimerEvent &ev)
Function for updating the sensor tf transform.
Definition: sensor_base.cpp:76
ros::Timer _timer
A ROS timer for updating the sensor tf.
Definition: sensor_base.h:126
bool waitForTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration &timeout, const ros::Duration &polling_sleep_duration=ros::Duration(0.01), std::string *error_msg=NULL) const
virtual void updateSensorCallback(void)=0
Virtual function for sensor value callback. Implement this function on derived class to publish senso...
Sensor(const nav_msgs::OccupancyGrid &map, const std::string &name, ros::NodeHandle &n, const geometry_msgs::Pose2D &sensorPose, const std::string &sensorFrameId, float updateFrequency)
Default constructor.
Definition: sensor_base.cpp:36
tf::StampedTransform _sensorTransform
True if sensor got the _sensorTransform.
Definition: sensor_base.h:135
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
void lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, StampedTransform &transform) const
ros::Timer _tfTimer
ROS publisher for posting the sensor measurements.
Definition: sensor_base.h:128
const std::string _sensorFrameId
A ROS timer for updating the sensor values.
Definition: sensor_base.h:123
#define ROS_DEBUG(...)


stdr_robot
Author(s): Manos Tsardoulias, Chris Zalidis, Aris Thallas
autogenerated on Mon Jun 10 2019 15:15:10