pinger_visualisation.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 # Copyright 2018 Jonathan Wheare (jonathan.wheare@flinders.edu.au)
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are met:
7 #
8 # 1. Redistributions of source code must retain the above copyright notice,
9 # this list of conditions and the following disclaimer.
10 #
11 # 2. Redistributions in binary form must reproduce the above copyright notice,
12 # this list of conditions and the following disclaimer in the documentation
13 # and/or other materials provided with the distribution.
14 #
15 # 3. Neither the name of the copyright holder nor the names of its contributors
16 # may be used to endorse or promote products derived from this software without
17 # specific prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30 #
31 # BSD 3-term license. Source: https://opensource.org/licenses/BSD-3-Clause
32 # Used under creative-commons attribution license.
33 #
34 
35 import math
36 import rospy
37 
38 from geometry_msgs.msg import Point
39 from usv_msgs.msg import RangeBearing
40 from visualization_msgs.msg import Marker
41 
42 """@package pinger_visualisation.py
43 This node takes a RangeBearing message and produces a corresponding Marker
44 message suitable for use with rviz.
45 """
46 
47 
49  """Class used to store the parameters and variables for the script.
50  """
51  def __init__(self):
52  """Initialise and run the class."""
53  rospy.init_node("pinger_visualisation")
54 
55  # Startup a publisher of the marker messages
56  self.markerPub = rospy.Publisher("/wamv/sensors/pingers/pinger/marker/signal", Marker,
57  queue_size=10, latch=True)
58 
59  # Start subscriber
60  self.pingerSub = rospy.Subscriber("/wamv/sensors/pingers/pinger/range_bearing",
61  RangeBearing, self.pingerCallback)
62 
63  # Spin until closed
64  rospy.spin()
65 
66  # Callback to handle an incoming range bearing message
67  def pingerCallback(self, msg):
68  """Callback to handle receipt of a RangeBearing message."""
69 
70  # Create a Marker message
71  visMsg = Marker()
72 
73  # The frame ID and timestamp should be identical to the received pinger
74  # message
75  visMsg.header.frame_id = msg.header.frame_id
76  visMsg.header.stamp = msg.header.stamp
77  visMsg.ns = ""
78  visMsg.id = 0
79 
80  # Visualisation will be an arrow
81  visMsg.type = Marker.ARROW
82  visMsg.action = Marker.ADD
83 
84  # Position will be specified by start and end points.
85  visMsg.pose.position.x = 0
86  visMsg.pose.position.y = 0
87  visMsg.pose.position.z = 0
88  visMsg.pose.orientation.x = 0.0
89  visMsg.pose.orientation.y = 0.0
90  visMsg.pose.orientation.z = 0.0
91  visMsg.pose.orientation.w = 1.0
92 
93  visMsg.scale.x = 0.1
94  visMsg.scale.y = 0.5
95  visMsg.scale.z = 0.5
96 
97  # Make it blue
98  visMsg.color.r = 0.0
99  visMsg.color.g = 0.0
100  visMsg.color.b = 1.0
101  visMsg.color.a = 1.0
102 
103  # When using start and end points, we need to include two more messages
104  # of type geometry_msgs/Point. These are appended to the list of
105  # points. Origin is a 0,0. Since the visualisation is in the sensor
106  # frame, arrow should start at the sensor.
107  startPoint = Point()
108  startPoint.x = 0
109  startPoint.y = 0
110  startPoint.z = 0
111  visMsg.points.append(startPoint)
112 
113  # Finish at the estimated pinger position.
114  endPoint = Point()
115  endPoint.x = msg.range*math.cos(msg.elevation)*math.cos(msg.bearing)
116  endPoint.y = msg.range*math.cos(msg.elevation)*math.sin(msg.bearing)
117  endPoint.z = msg.range*math.sin(msg.elevation)
118  visMsg.points.append(endPoint)
119 
120  # Publish the message.
121  self.markerPub.publish(visMsg)
122 
123 
124 if __name__ == '__main__':


vrx_gazebo
Author(s): Brian Bingham , Carlos Aguero
autogenerated on Thu May 7 2020 03:54:56