-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic setup for Python interface using SWIG (#216)
* Basic setup for Python interface using SWIG * Changes in cmake to run python tests with colcon * Adding Vector3 and Vector4 python interface tests * Changing from a single ign_math.i file to a ruby.i and a python.i Signed-off-by: Marcos Wagner <[email protected]> * Fixes install path and name math instead of pymath. * Adds py examples * Fixes ruby_TEST set up. * Support both Swig3 and Swig4 versions. Signed-off-by: Franco Cipollone <[email protected]> * Adds line in the src/CMakeLists.txt file to solve CI error. Adds python test files to some of the classes that had an associated .i file. Signed-off-by: LolaSegura <[email protected]> * Remove Marya from CODEOWNERS (#217) Signed-off-by: Michael Carroll <[email protected]> * Use FAKE_INSTALL_PREFIX for PYTHONPATH in tests and move the variable definition to the root CMakeLists.txt * Set LD_LIBRARY_PATH for python tests Point to fake install lib folder. Signed-off-by: Steve Peters <[email protected]> Co-authored-by: Franco Cipollone <[email protected]> Co-authored-by: LolaSegura <[email protected]> Co-authored-by: Louise Poubel <[email protected]> Co-authored-by: Michael Carroll <[email protected]> Co-authored-by: Steve Peters <[email protected]>
- Loading branch information
1 parent
cf6d052
commit 2330061
Showing
17 changed files
with
1,368 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright (C) 2021 Open Source Robotics Foundation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# This example will only work if the Python interface library was compiled and | ||
# installed. | ||
# | ||
# Modify the PYTHONPATH environment variable to include the ignition math | ||
# library install path. For example, if you install to /user: | ||
# | ||
# $ export PYTHONPATH=/usr/lib/python:$PYTHONPATH | ||
# | ||
|
||
import ignition.math | ||
|
||
print("PI in degrees = {}\n".format(ignition.math.Angle.Pi.Degree())) | ||
|
||
a1 = ignition.math.Angle(1.5707) | ||
a2 = ignition.math.Angle(0.7854) | ||
print("a1 = {} radians, {} degrees\n".format(a1.Radian(), a1.Degree())) | ||
print("a2 = {} radians, {} degrees\n".format(a2.Radian(), a2.Degree())) | ||
print("a1 * a2 = {} radians, {} degrees\n".format((a1 * a2).Radian(), | ||
(a1 * a2).Degree())) | ||
print("a1 + a2 = {} radians, {} degrees\n".format((a1 + a2).Radian(), | ||
(a1 + a2).Degree())) | ||
print("a1 - a2 = {} radians, {} degrees\n".format((a1 - a2).Radian(), | ||
(a1 - a2).Degree())) | ||
|
||
a3 = ignition.math.Angle(15.707) | ||
print("a3 = {} radians, {} degrees\n".format(a3.Radian(), a3.Degree())) | ||
a3.Normalize() | ||
print("a3.Normalize = {} radians, {} degrees\n".format(a3.Radian(), | ||
a3.Degree())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright (C) 2021 Open Source Robotics Foundation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# This example will only work if the Python interface library was compiled and | ||
# installed. | ||
# | ||
# Modify the PYTHONPATH environment variable to include the ignition math | ||
# library install path. For example, if you install to /user: | ||
# | ||
# $ export PYTHONPATH=/usr/lib/python:$PYTHONPATH | ||
# | ||
import ignition.math | ||
|
||
va = ignition.math.Vector2d(1, 2) | ||
vb = ignition.math.Vector2d(3, 4) | ||
vc = ignition.math.Vector2d(vb) | ||
|
||
print("va = {} {}\n".format(va.X(), va.Y())) | ||
print("vb = {} {}\n".format(vb.X(), vb.Y())) | ||
print("vc = {} {}\n".format(vc.X(), vc.Y())) | ||
|
||
vb += va | ||
print("vb += va: {} {}\n".format(vb.X(), vb.Y())) | ||
|
||
vb.Normalize() | ||
print("vb.Normalize = {} {}\n".format(vb.X(), vb.Y())) | ||
|
||
print("vb.Distance(va) = {}\n".format(vb.Distance(va))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright (C) 2021 Open Source Robotics Foundation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# This example will only work if the Python interface library was compiled and | ||
# installed. | ||
# | ||
# Modify the PYTHONPATH environment variable to include the ignition math | ||
# library install path. For example, if you install to /user: | ||
# | ||
# $ export PYTHONPATH=/usr/lib/python:$PYTHONPATH | ||
# | ||
import ignition.math | ||
|
||
v1 = ignition.math.Vector3d(0, 0, 3) | ||
print("v =: {} {} {}\n".format(v1.X(), v1.Y(), v1.Z())) | ||
|
||
v2 = ignition.math.Vector3d(4, 0, 0) | ||
print("v2 = {} {} {}\n".format(v2.X(), v2.Y(), v2.Z())) | ||
|
||
v3 = v1 + v2 | ||
print("v1 + v2 = {} {} {}\n".format(v3.X(), v3.Y(), v3.Z())) | ||
|
||
print("v1.Distance(v2) = {}\n".format(v1.Distance(v2))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Copyright (C) 2021 Open Source Robotics Foundation | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
|
||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
import math | ||
from ignition.math import Angle | ||
|
||
|
||
class TestAngle(unittest.TestCase): | ||
|
||
def test_angle(self): | ||
|
||
angle1 = Angle() | ||
self.assertEqual(0.0, angle1.Radian()) | ||
|
||
angle1.SetDegree(90.0) | ||
self.assertTrue(angle1 == Angle.HalfPi) | ||
|
||
angle1.SetDegree(180.0) | ||
self.assertTrue(angle1 == Angle.Pi) | ||
self.assertFalse(angle1 == Angle.Pi + Angle(0.1)) | ||
self.assertTrue(angle1 == Angle.Pi + Angle(0.0001)) | ||
self.assertTrue(angle1 == Angle.Pi - Angle(0.0001)) | ||
self.assertTrue(Angle(0) == Angle(0)) | ||
self.assertTrue(Angle(0) == Angle(0.001)) | ||
|
||
angle1 = Angle(0.1) - Angle(0.3) | ||
self.assertAlmostEqual(angle1.Radian(), -0.2) | ||
|
||
angle = Angle(0.5) | ||
self.assertEqual(0.5, angle.Radian()) | ||
|
||
angle.SetRadian(math.pi/2) | ||
self.assertAlmostEqual(math.degrees(math.pi/2), angle.Degree()) | ||
|
||
angle.SetRadian(math.pi) | ||
self.assertAlmostEqual(math.degrees(math.pi), angle.Degree()) | ||
|
||
def test_normalized_angles(self): | ||
|
||
angle = Angle(Angle.Pi) | ||
normalized = angle.Normalized() | ||
|
||
angle.Normalized() | ||
self.assertEqual(math.degrees(math.pi), angle.Degree()) | ||
self.assertEqual(normalized, angle) | ||
|
||
def test_angle_operations(self): | ||
|
||
angle = Angle(0.1) + Angle(0.2) | ||
self.assertAlmostEqual(0.3, angle.Radian()) | ||
|
||
angle = Angle(0.1) * Angle(0.2) | ||
self.assertAlmostEqual(0.02, angle.Radian()) | ||
|
||
angle = Angle(0.1) / Angle(0.2) | ||
self.assertAlmostEqual(0.5, angle.Radian()) | ||
|
||
angle -= Angle(0.1) | ||
self.assertAlmostEqual(0.4, angle.Radian()) | ||
|
||
angle += Angle(0.2) | ||
self.assertAlmostEqual(0.6, angle.Radian()) | ||
|
||
angle *= Angle(0.5) | ||
self.assertAlmostEqual(0.3, angle.Radian()) | ||
|
||
angle /= Angle(0.1) | ||
self.assertAlmostEqual(3.0, angle.Radian()) | ||
self.assertTrue(angle == Angle(3)) | ||
self.assertTrue(angle != Angle(2)) | ||
self.assertTrue(angle < Angle(4)) | ||
self.assertTrue(angle > Angle(2)) | ||
self.assertTrue(angle >= Angle(3)) | ||
self.assertTrue(angle <= Angle(3)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.