-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic setup for Python interface using SWIG #216
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
02c1b08
Basic setup for Python interface using SWIG
WagnerMarcos 3e31a3a
Fixes install path and name math instead of pymath.
francocipollone f0ad4df
Adds py examples
francocipollone fab308e
Fixes ruby_TEST set up.
francocipollone 5fa9264
Support both Swig3 and Swig4 versions.
francocipollone 4d09fe6
Changes in cmake to run python tests with colcon
WagnerMarcos 5f3d676
Adds line in the src/CMakeLists.txt file to solve CI error. Adds pyth…
LolaSegura 6522274
Adding Vector3 and Vector4 python interface tests
WagnerMarcos 9e443c9
Addressed comments.
LolaSegura f3c457f
Address comments.
LolaSegura e8a7e6c
Changing from a single ign_math.i file to a ruby.i and a python.i
WagnerMarcos 440a6d1
Update CMakeLists.txt
francocipollone be29035
Remove Marya from CODEOWNERS (#217)
mjcarroll 4a1b193
Fixes ABI break.
francocipollone 4b02a9d
Avoid recompiling sources for the bindings.
francocipollone 02e065a
Use FAKE_INSTALL_PREFIX for PYTHONPATH in tests
scpeters 3fca80f
Set LD_LIBRARY_PATH for python tests
scpeters e6373fb
Addresses nit
francocipollone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Validating CODEOWNERS rules …
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit for the future (not this pull request): I find
f""
strings are more readable than using.format()
for example: