Skip to content

Commit 0bdca26

Browse files
committed
Replace tf with tf2 (demos)
1 parent 9ca0757 commit 0bdca26

File tree

5 files changed

+15
-21
lines changed

5 files changed

+15
-21
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ This is the main Robot-Centric Elevation Mapping node. It uses the distance sens
145145

146146
The robot pose and covariance.
147147

148-
* **`/tf`** ([tf/tfMessage])
148+
* **`/tf`** ([tf2_msgs/TFMessage])
149149

150150
The transformation tree.
151151

@@ -400,7 +400,7 @@ Please report bugs and request features using the [Issue Tracker](https://github
400400
[grid_map_msgs/GridMap]: https://github.com/anybotics/grid_map/blob/master/grid_map_msgs/msg/GridMap.msg
401401
[sensor_msgs/PointCloud2]: http://docs.ros.org/api/sensor_msgs/html/msg/PointCloud2.html
402402
[geometry_msgs/PoseWithCovarianceStamped]: http://docs.ros.org/api/geometry_msgs/html/msg/PoseWithCovarianceStamped.html
403-
[tf/tfMessage]: http://docs.ros.org/kinetic/api/tf/html/msg/tfMessage.html
403+
[tf2_msgs/TFMessage]: http://docs.ros.org/en/noetic/api/tf2_msgs/html/msg/TFMessage.html
404404
[std_srvs/Empty]: http://docs.ros.org/api/std_srvs/html/srv/Empty.html
405405
[grid_map_msgs/GetGridMap]: https://github.com/anybotics/grid_map/blob/master/grid_map_msgs/srv/GetGridMap.srv
406406
[grid_map_msgs/ProcessFile]: https://github.com/ANYbotics/grid_map/blob/master/grid_map_msgs/srv/ProcessFile.srv

elevation_mapping_demos/launch/simple_demo.launch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</node>
1717

1818
<!-- Setup a transform between the world and the robot -->
19-
<node pkg="tf" type="static_transform_publisher" name="world_to_robot" args="2.0 6.0 0 0 0.0 0 /map /base 100"/>
19+
<node pkg="tf2_ros" type="static_transform_publisher" name="world_to_robot" args="2.0 6.0 0.0 0.0 0.0 0.0 /map /base"/>
2020

2121
<!-- Launch visualizations for the resulting elevation map -->
2222
<include file="$(find elevation_mapping_demos)/launch/visualization.launch" />

elevation_mapping_demos/launch/turtlesim3_waffle_demo.launch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<arg name="gui" value="false"/> <!-- Launch the user interface window of Gazebo-->
1616
<arg name="headless" value="false"/> <!-- Enable gazebo state log recording-->
1717
<arg name="debug" value="false"/> <!-- Start gzserver (Gazebo Server) in debug mode using gdb-->
18+
<arg name="verbose" value="false"/> <!-- Start gazebo in verbose mode-->
1819
</include>
1920

2021
<!-- Load robot_description param for tf, rviz and gazebo spawn. -->

elevation_mapping_demos/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<exec_depend>pcl_ros</exec_depend>
2121
<exec_depend>point_cloud_io</exec_depend>
2222
<exec_depend>robot_state_publisher</exec_depend>
23-
<exec_depend>tf</exec_depend>
23+
<exec_depend>tf2_ros</exec_depend>
2424
<exec_depend>turtlebot3_gazebo</exec_depend>
2525
<exec_depend>xacro</exec_depend>
2626

elevation_mapping_demos/scripts/tf_to_pose_publisher.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,25 @@
22

33
import rospy
44
import geometry_msgs.msg
5-
import tf
5+
import tf2_ros
66

77
def callback(newPose):
88
"""Listens to a transform between from_frame and to_frame and publishes it
99
as a pose with a zero covariance."""
10-
global publisher, tf_listener, from_frame, to_frame
10+
global publisher, tf_buffer, tf_listener, from_frame, to_frame
1111

1212
# Listen to transform and throw exception if the transform is not
1313
# available.
1414
try:
15-
(trans, rot) = tf_listener.lookupTransform(
16-
from_frame, to_frame, rospy.Time(0))
17-
except (tf.LookupException, tf.ConnectivityException,
18-
tf.ExtrapolationException):
15+
trans = tf_buffer.lookup_transform(from_frame, to_frame, rospy.Time())
16+
except (tf2_ros.LookupException, tf2_ros.ConnectivityException, tf2_ros.ExtrapolationException):
1917
return
2018

2119
# Create and fill pose message for publishing
2220
pose = geometry_msgs.msg.PoseWithCovarianceStamped()
23-
pose.header.stamp = rospy.Time(0)
24-
pose.header.frame_id = from_frame
25-
pose.pose.pose.position.x = trans[0]
26-
pose.pose.pose.position.y = trans[1]
27-
pose.pose.pose.position.z = trans[2]
28-
pose.pose.pose.orientation.x = rot[0]
29-
pose.pose.pose.orientation.y = rot[1]
30-
pose.pose.pose.orientation.z = rot[2]
31-
pose.pose.pose.orientation.w = rot[3]
21+
pose.header = trans.header
22+
pose.pose.pose.position = trans.transform.translation
23+
pose.pose.pose.orientation = trans.transform.rotation
3224

3325
# Since tf transforms do not have a covariance, pose is filled with
3426
# a zero covariance.
@@ -45,14 +37,15 @@ def callback(newPose):
4537
def main_program():
4638
""" Main function initializes node and subscribers and starts
4739
the ROS loop. """
48-
global publisher, tf_listener, from_frame, to_frame
40+
global publisher, tf_buffer, tf_listener, from_frame, to_frame
4941
rospy.init_node('tf_to_pose_publisher')
5042
# Read frame id's for tf listener
5143
from_frame = rospy.get_param("~from_frame")
5244
to_frame = rospy.get_param("~to_frame")
5345
pose_name = str(to_frame) + "_pose"
5446

55-
tf_listener = tf.TransformListener()
47+
tf_buffer = tf2_ros.Buffer()
48+
tf_listener = tf2_ros.TransformListener(tf_buffer)
5649
publisher = rospy.Publisher(
5750
pose_name, geometry_msgs.msg.PoseWithCovarianceStamped, queue_size=10)
5851

0 commit comments

Comments
 (0)