From 46076a3d4847b3321293f38809fcf062d9579eb0 Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Sun, 25 Feb 2018 02:22:13 +0000 Subject: [PATCH 01/10] add orientation data type to markers --- robot/markers.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/robot/markers.py b/robot/markers.py index 40f5938..c0acc53 100644 --- a/robot/markers.py +++ b/robot/markers.py @@ -46,6 +46,45 @@ def rot_y_degrees(self) -> Degrees: return Degrees(math.degrees(self.rot_y_radians)) +_Orientation = NamedTuple('Orientation', ( + ('rot_x_radians', Radians), + ('rot_y_radians', Radians), + ('rot_z_radians', Radians), +)) + + +class Orientation(_Orientation): + """ + Represents the orientation in 3d space as rotations around x, y, and z axes. + + Rotations around the different axes can be thought of as follows: + - X rotation represents pitch. Positive rotation + around the X axis represents a rotation with the nearest point going downwards, + and furthest going upwards. (i.e. a bowing motion is a positive x rotation) + - Y rotation represents yaw. Positive rotation around the Y axis represents + a rotation with the nearest point going to the left, and the furthest going to the + right. + - Z rotation represents roll. Positive rotation around the Z axis represents + a rotation with the highest point going to the right, and the bottom going to the + left. + """ + + @property + def rot_x_degrees(self) -> Degrees: + """Rotation about the x-axis in degrees.""" + return Degrees(math.degrees(self.rot_x_radians)) + + @property + def rot_y_degrees(self) -> Degrees: + """Rotation about the y-axis in degrees.""" + return Degrees(math.degrees(self.rot_y_radians)) + + @property + def rot_z_degrees(self) -> Degrees: + """Rotation about the z-axis in degrees.""" + return Degrees(math.degrees(self.rot_z_radians)) + + class PolarCoord: """ Deprecated: represents a point expressed in legacy "polar" co-ordinates. From 728f929e29c6700fb164084fa734a642ca96c101 Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Sun, 25 Feb 2018 02:31:48 +0000 Subject: [PATCH 02/10] add Orientation to markers --- robot/markers.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/robot/markers.py b/robot/markers.py index c0acc53..368e7d6 100644 --- a/robot/markers.py +++ b/robot/markers.py @@ -217,3 +217,15 @@ def spherical(self) -> SphericalCoord: space is different to the usual representation of a spherical space. """ return SphericalCoord(*self._raw_data['spherical']) + + @property + def orientation(self) -> Orientation: + """ + The rotation of the marker in relative to the camera. + + Describes a rotation as angles about the x, y, and z axes, which + corresponds pitch, yaw, and roll of the marker respectively. The + angles are measured as an offset from the marker directly facing + the camera. + """ + return Orientation(*self._raw_data['orientation']) From 0e6e16427da9e918cc2dfe790692228926e307bb Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Sun, 25 Feb 2018 02:34:09 +0000 Subject: [PATCH 03/10] add Orientation to tests --- tests/test_camera.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_camera.py b/tests/test_camera.py index 18c535c..14440be 100644 --- a/tests/test_camera.py +++ b/tests/test_camera.py @@ -3,7 +3,7 @@ import unittest from robot.camera import ResultList -from robot.markers import CartCoord, PolarCoord, SphericalCoord +from robot.markers import CartCoord, Orientation, PolarCoord, SphericalCoord from robot.robot import Robot from sb_vision.camera import FileCamera from tests.mock_robotd import MockRobotD @@ -80,6 +80,12 @@ def test_can_see_something(self): "Invalid spherical coordinates", ) + self.assertIsInstance( + token.orientation, + Orientation, + "Invalid orientation coordinates", + ) + self.assertIsInstance( token.polar, PolarCoord, From 667307968759a366153bc62d109cf8a790f41dff Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Mon, 26 Feb 2018 09:25:35 +0000 Subject: [PATCH 04/10] update versions being tested against --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index dc5a5ed..b4ac2c6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,8 +24,8 @@ jobs: . venv/bin/activate - run: apt-get update -y - run: apt-get install -y libcv-dev libopencv-photo-dev libopencv-contrib-dev libusb-1.0.0-dev - - run: pip3 install git+https://github.com/sourcebots/sb-vision@44356ec0fc4738508d22bf15137bb4429ba3410f - - run: pip3 install git+https://github.com/sourcebots/robotd@4ae124ba4d75f4be64a2b0bbc3f4abd37c94726f + - run: pip3 install git+https://github.com/sourcebots/sb-vision@59e681956349805a5a9a0200a37e9c6218fd7cec + - run: pip3 install git+https://github.com/sourcebots/robotd@e0be841816d4c778e98498193f6fd7e3de35813d - run: pip3 install -r requirements.txt - run: pip3 install -r script/linting/requirements.txt - run: pip3 install -r script/typing/requirements.txt From 3906827553ef5a1a3deb90f23e588b369f1035a5 Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Mon, 26 Feb 2018 14:29:49 +0000 Subject: [PATCH 05/10] bump sb-vision to be the latest orientation branch --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b4ac2c6..1264928 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,7 +24,7 @@ jobs: . venv/bin/activate - run: apt-get update -y - run: apt-get install -y libcv-dev libopencv-photo-dev libopencv-contrib-dev libusb-1.0.0-dev - - run: pip3 install git+https://github.com/sourcebots/sb-vision@59e681956349805a5a9a0200a37e9c6218fd7cec + - run: pip3 install git+https://github.com/sourcebots/sb-vision@f69d7190543b92c2067377f8ddd8f2607e9aa2ca - run: pip3 install git+https://github.com/sourcebots/robotd@e0be841816d4c778e98498193f6fd7e3de35813d - run: pip3 install -r requirements.txt - run: pip3 install -r script/linting/requirements.txt From ca54c3e512b106c6403f138dec8c71244207237c Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Tue, 27 Feb 2018 17:49:34 +0000 Subject: [PATCH 06/10] use humans as an analogy for rotations --- robot/markers.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/robot/markers.py b/robot/markers.py index 5c26d08..c273f56 100644 --- a/robot/markers.py +++ b/robot/markers.py @@ -58,17 +58,14 @@ class Orientation(_Orientation): Represents the orientation in 3d space as rotations around x, y, and z axes. Rotations around the different axes can be thought of as follows: - - X rotation represents pitch. Positive rotation - around the X axis represents a rotation with the nearest point going downwards, - and furthest going upwards. (i.e. a bowing motion is a positive x rotation) - - Y rotation represents yaw. Positive rotation around the Y axis represents - a rotation with the nearest point going to the left, and the furthest going to the - right. - - Z rotation represents roll. Positive rotation around the Z axis represents - a rotation with the highest point going to the right, and the bottom going to the - left. + - X rotation represents pitch. A good way to think of this is a person + leaning towards you (like they're doing a bow in respect of your amazing + robot) would be a positive X rotation. + - Y rotation represents yaw. A good way to think of this is a person + spinning clockwise on the spot would be a positive Y rotation. + - Z rotation represents roll. A good way to think of this is a person + doing a cart-wheel to the right would be a positive Z rotation. """ - @property def rot_x_degrees(self) -> Degrees: """Rotation about the x-axis in degrees.""" From 4e59cbbb6d842f5e8dfe1e1561ea963dacc98b1c Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Tue, 27 Feb 2018 19:59:17 +0000 Subject: [PATCH 07/10] "a marker" -> "the marker" --- robot/markers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/robot/markers.py b/robot/markers.py index c273f56..5dae1a9 100644 --- a/robot/markers.py +++ b/robot/markers.py @@ -211,7 +211,7 @@ def orientation(self) -> Orientation: Describes a rotation as angles about the x, y, and z axes, which corresponds pitch, yaw, and roll of the marker respectively. The - angles are measured as an offset from the marker directly facing + angles are measured as an offset from a marker directly facing the camera. """ return Orientation(*self._raw_data['orientation']) From 6018425c576e63f34063727ab17e0d0b9c786e31 Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Wed, 28 Feb 2018 01:03:56 +0000 Subject: [PATCH 08/10] say in what order the rotations are applied --- robot/markers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/robot/markers.py b/robot/markers.py index 5dae1a9..6675102 100644 --- a/robot/markers.py +++ b/robot/markers.py @@ -213,6 +213,8 @@ def orientation(self) -> Orientation: corresponds pitch, yaw, and roll of the marker respectively. The angles are measured as an offset from a marker directly facing the camera. + + The rotations are applied in the order of Z, Y, X. """ return Orientation(*self._raw_data['orientation']) From 5a3e27d892950b373eca770c49f071fbef9e8dc5 Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Wed, 28 Feb 2018 09:18:39 +0000 Subject: [PATCH 09/10] fix linting error --- robot/markers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/robot/markers.py b/robot/markers.py index 6675102..df2492d 100644 --- a/robot/markers.py +++ b/robot/markers.py @@ -66,6 +66,7 @@ class Orientation(_Orientation): - Z rotation represents roll. A good way to think of this is a person doing a cart-wheel to the right would be a positive Z rotation. """ + @property def rot_x_degrees(self) -> Degrees: """Rotation about the x-axis in degrees.""" From 7535af1202c33c19a20484e90e379cde0c357f4d Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Sun, 4 Mar 2018 22:55:20 +0000 Subject: [PATCH 10/10] clarify what the transforms are made relative to --- robot/markers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/robot/markers.py b/robot/markers.py index df2492d..a5f69ff 100644 --- a/robot/markers.py +++ b/robot/markers.py @@ -215,7 +215,8 @@ def orientation(self) -> Orientation: angles are measured as an offset from a marker directly facing the camera. - The rotations are applied in the order of Z, Y, X. + The rotations are applied in the order of Z, Y, then X rotations. Each rotation + is applied relative to the marker. """ return Orientation(*self._raw_data['orientation'])