Skip to content
This repository was archived by the owner on Aug 15, 2019. It is now read-only.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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@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
- run: pip3 install -r script/typing/requirements.txt
Expand Down
52 changes: 52 additions & 0 deletions robot/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,43 @@ 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the order of application of the angles, and/or do they always apply to the cartesian axes of the camera?

A camera-relative interpretation of (45°, 90°, 0) is as follows: consider a marker which is leaning forwards by 45° but placed on a horizontal rotating platform (like a "lazy susan"); then rotate the platform by 90°.

A marker-relative interpretation is as follows: consider a marker perpendicular to a rotating platform which is angled 45° towards the observer (like a lazy susan on the surface of a table which has been half-pushed over); then rotate the platform by 90°.

In both scenarios the marker is now facing off to the side, however in the former its baseline is still horizontal while in the latter its baseline is at a 45° to the horizontal.

I'm not sure which of the two systems is easier to think about, nor which we've got data for. We should find out and document this however.

Note that if we apply the angles in the reverse order (z then y then x) then the two scenarios above change roles.

Copy link
Contributor

@PeterJCLaw PeterJCLaw Mar 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Adimote I see this is partially resolved by 6018425, thanks for that, though we still don't describe whether the rotations are relative to the marker or the camera.

I think I hope that they're relative to the fixed frame of the camera (I'm expecting that that would make the angles for a pair of markers more easily comparable), though I've not explore enough examples to know which is better/easier to think about.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took me a while to figure this out, but I'm pretty sure the rotations are actually applied relative to the marker. I've added this detail in 7535af1 This means an upside-down marker would report inverse rot_y. We might want to investigate how to make this easier for the students to use in a later update.


Rotations around the different axes can be thought of as follows:
- 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."""
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.
Expand Down Expand Up @@ -168,6 +205,21 @@ def spherical(self) -> SphericalCoord:
"""
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 a marker directly facing
the camera.

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'])

def __str__(self):
bearing = self.spherical.rot_y_degrees
return "<Marker {}: {:.0f}° {}, {:.2f}m away>".format(
Expand Down
8 changes: 7 additions & 1 deletion tests/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down