sphere_sensor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, The Regents of the University of California (Regents).
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following
14  * disclaimer in the documentation and/or other materials provided
15  * with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Please contact the author(s) of this library if you have any questions.
34  * Authors: David Fridovich-Keil ( dfk@eecs.berkeley.edu )
35  */
36 
38 //
39 // Sensor to detect spherical obstacles. Templated on environment type.
40 //
42 
43 #ifndef FASTRACK_SENSOR_SPHERE_SENSOR_H
44 #define FASTRACK_SENSOR_SPHERE_SENSOR_H
45 
46 #include <fastrack/sensor/sensor.h>
48 #include <fastrack_msgs/SensedSpheres.h>
49 
50 namespace fastrack {
51 namespace sensor {
52 
53 template<typename E>
54 class SphereSensor : public Sensor<
55  E, fastrack_msgs::SensedSpheres, SphereSensorParams> {
56 public:
58  explicit SphereSensor()
59  : Sensor<E, fastrack_msgs::SensedSpheres, SphereSensorParams>() {}
60 
61 private:
62  // Load parameters. This may be overridden by derived classes if needed
63  // (they should still call this one via Sensor::LoadParameters).
64  bool LoadParameters(const ros::NodeHandle& n);
65 
66  // Update sensor parameters.
67  void UpdateParameters();
68 
69  // Derived classes must have some sort of visualization through RViz.
70  void Visualize() const;
71 }; //\class SphereSensor
72 
73 // ----------------------------- IMPLEMENTATION ----------------------------- //
74 
75 // Load parameters. This may be overridden by derived classes if needed
76 // (they should still call this one via Sensor::LoadParameters).
77 template<typename E>
78 bool SphereSensor<E>::LoadParameters(const ros::NodeHandle& n) {
80  LoadParameters(n))
81  return false;
82 
83  ros::NodeHandle nl(n);
84 
85  // Range.
86  if (!nl.getParam("range", this->params_.range)) return false;
87 
88  return true;
89 }
90 
91 // Update sensor parameters.
92 template<typename E>
94  // Get the current sensor pose from tf.
95  geometry_msgs::TransformStamped tf;
96 
97  try {
98  tf = this->tf_buffer_.lookupTransform(
99  this->fixed_frame_.c_str(), this->sensor_frame_.c_str(), ros::Time(0));
100  } catch(tf2::TransformException &ex) {
101  ROS_WARN("%s: %s", this->name_.c_str(), ex.what());
102  ROS_WARN("%s: Could not determine current sensor pose.", this->name_.c_str());
103  return;
104  }
105 
106  // Unpack into parameters struct.
107  this->params_.position(0) = tf.transform.translation.x;
108  this->params_.position(1) = tf.transform.translation.y;
109  this->params_.position(2) = tf.transform.translation.z;
110 
111  return;
112 }
113 
114 // Derived classes must have some sort of visualization through RViz.
115 template<typename E>
117  visualization_msgs::Marker m;
118  m.ns = "sensor";
119  m.header.frame_id = this->sensor_frame_;
120  m.header.stamp = ros::Time::now();
121  m.id = 0;
122  m.type = visualization_msgs::Marker::SPHERE;
123  m.action = visualization_msgs::Marker::ADD;
124  m.color.a = 0.3;
125  m.color.r = 0.1;
126  m.color.g = 0.5;
127  m.color.b = 0.3;
128  m.scale.x = 2.0 * this->params_.range;
129  m.scale.y = 2.0 * this->params_.range;
130  m.scale.z = 2.0 * this->params_.range;
131 
132  this->vis_pub_.publish(m);
133 }
134 
135 } //\namespace sensor
136 } //\namespace fastrack
137 
138 #endif
Definition: box.h:53
bool LoadParameters(const ros::NodeHandle &n)
Definition: sphere_sensor.h:78


fastrack
Author(s): David Fridovich-Keil
autogenerated on Mon Aug 3 2020 21:28:37