Skip to content

Commit 7c22cdd

Browse files
committed
Fix flake8
python scripts don't seem to be ported to ROS2 tho
1 parent b392269 commit 7c22cdd

File tree

3 files changed

+39
-20
lines changed

3 files changed

+39
-20
lines changed

tf2_sensor_msgs/src/tf2_sensor_msgs/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@
2525
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2626
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2727
# POSSIBILITY OF SUCH DAMAGE.
28+
29+
from tf2_sensor_msgs import * # noqa(E401)

tf2_sensor_msgs/src/tf2_sensor_msgs/tf2_sensor_msgs.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Copyright 2008 Willow Garage, Inc.
2-
#
2+
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions are met:
5-
#
5+
#
66
# * Redistributions of source code must retain the above copyright
77
# notice, this list of conditions and the following disclaimer.
88
#
@@ -13,7 +13,7 @@
1313
# * Neither the name of the Willow Garage, Inc. nor the names of its
1414
# contributors may be used to endorse or promote products derived from
1515
# this software without specific prior written permission.
16-
#
16+
#
1717
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1818
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1919
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -29,26 +29,33 @@
2929
from sensor_msgs.msg import PointCloud2
3030
from sensor_msgs.point_cloud2 import read_points, create_cloud
3131
import PyKDL
32-
import rospy
32+
import rospy # noqa(E401)
3333
import tf2_ros
3434

35+
3536
def to_msg_msg(msg):
3637
return msg
3738

39+
3840
tf2_ros.ConvertRegistration().add_to_msg(PointCloud2, to_msg_msg)
3941

42+
4043
def from_msg_msg(msg):
4144
return msg
4245

46+
4347
tf2_ros.ConvertRegistration().add_from_msg(PointCloud2, from_msg_msg)
4448

49+
4550
def transform_to_kdl(t):
46-
return PyKDL.Frame(PyKDL.Rotation.Quaternion(t.transform.rotation.x, t.transform.rotation.y,
51+
return PyKDL.Frame(PyKDL.Rotation.Quaternion(
52+
t.transform.rotation.x, t.transform.rotation.y,
4753
t.transform.rotation.z, t.transform.rotation.w),
48-
PyKDL.Vector(t.transform.translation.x,
49-
t.transform.translation.y,
54+
PyKDL.Vector(t.transform.translation.x,
55+
t.transform.translation.y,
5056
t.transform.translation.z))
5157

58+
5259
# PointStamped
5360
def do_transform_cloud(cloud, transform):
5461
t_kdl = transform_to_kdl(transform)
@@ -58,4 +65,6 @@ def do_transform_cloud(cloud, transform):
5865
points_out.append(p_out)
5966
res = create_cloud(transform.header, cloud.fields, points_out)
6067
return res
68+
69+
6170
tf2_ros.TransformRegistration().add(PointCloud2, do_transform_cloud)

tf2_sensor_msgs/test/test_tf2_sensor_msgs.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,44 +36,52 @@
3636
from tf2_ros import TransformStamped
3737
import copy
3838

39-
## A sample python unit test
39+
40+
# A sample python unit test
4041
class PointCloudConversions(unittest.TestCase):
4142
def setUp(self):
4243
self.point_cloud_in = point_cloud2.PointCloud2()
43-
self.point_cloud_in.fields = [PointField('x', 0, PointField.FLOAT32, 1),
44-
PointField('y', 4, PointField.FLOAT32, 1),
45-
PointField('z', 8, PointField.FLOAT32, 1)]
44+
self.point_cloud_in.fields = [
45+
PointField('x', 0, PointField.FLOAT32, 1),
46+
PointField('y', 4, PointField.FLOAT32, 1),
47+
PointField('z', 8, PointField.FLOAT32, 1)]
4648

4749
self.point_cloud_in.point_step = 4 * 3
4850
self.point_cloud_in.height = 1
4951
# we add two points (with x, y, z to the cloud)
5052
self.point_cloud_in.width = 2
51-
self.point_cloud_in.row_step = self.point_cloud_in.point_step * self.point_cloud_in.width
53+
self.point_cloud_in.row_step = \
54+
self.point_cloud_in.point_step * self.point_cloud_in.width
5255

5356
points = [1, 2, 0, 10, 20, 30]
5457
self.point_cloud_in.data = struct.pack('%sf' % len(points), *points)
5558

56-
5759
self.transform_translate_xyz_300 = TransformStamped()
5860
self.transform_translate_xyz_300.transform.translation.x = 300
5961
self.transform_translate_xyz_300.transform.translation.y = 300
6062
self.transform_translate_xyz_300.transform.translation.z = 300
61-
self.transform_translate_xyz_300.transform.rotation.w = 1 # no rotation so we only set w
63+
# no rotation so we only set w
64+
self.transform_translate_xyz_300.transform.rotation.w = 1
6265

63-
assert(list(point_cloud2.read_points(self.point_cloud_in)) == [(1.0, 2.0, 0.0), (10.0, 20.0, 30.0)])
66+
assert(list(point_cloud2.read_points(self.point_cloud_in)) ==
67+
[(1.0, 2.0, 0.0), (10.0, 20.0, 30.0)])
6468

6569
def test_simple_transform(self):
66-
old_data = copy.deepcopy(self.point_cloud_in.data) # deepcopy is not required here because we have a str for now
67-
point_cloud_transformed = tf2_sensor_msgs.do_transform_cloud(self.point_cloud_in, self.transform_translate_xyz_300)
70+
# deepcopy is not required here because we have a str for now
71+
old_data = copy.deepcopy(self.point_cloud_in.data)
72+
point_cloud_transformed = tf2_sensor_msgs.do_transform_cloud(
73+
self.point_cloud_in, self.transform_translate_xyz_300)
6874

6975
k = 300
7076
expected_coordinates = [(1+k, 2+k, 0+k), (10+k, 20+k, 30+k)]
7177
new_points = list(point_cloud2.read_points(point_cloud_transformed))
7278
print("new_points are %s" % new_points)
7379
assert(expected_coordinates == new_points)
74-
assert(old_data == self.point_cloud_in.data) # checking no modification in input cloud
80+
# checking no modification in input cloud
81+
assert(old_data == self.point_cloud_in.data)
82+
7583

7684
if __name__ == '__main__':
7785
import rosunit
78-
rosunit.unitrun("test_tf2_sensor_msgs", "test_point_cloud_conversion", PointCloudConversions)
79-
86+
rosunit.unitrun("test_tf2_sensor_msgs", "test_point_cloud_conversion",
87+
PointCloudConversions)

0 commit comments

Comments
 (0)