ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ros2-foxy-angles from_degrees Python example?

asked 2021-07-13 16:33:27 -0600

RobotDreams gravatar image

updated 2021-07-14 08:39:39 -0600

ROS nub

I found https://index.ros.org/p/angles/ and ros2-foxy-angles got installed by rosdep from my package.xml:

  <exec_depend>angles</exec_depend>

The git says it hasn't changed but there are no foxy "API Docs" and the ROS1 docs only show C++.

Where can I find a Python example for what to import?

# get degrees to radians func
from ??? import from_degrees

        self.msg_field_of_view = from_degrees(25.0)     # +/- 12.5 degree FOV (~60cm at max range)

I'm starting to think Foxy does not support angles in Python. (the ROS2 setup.py refers to catkin ) My temp workaround since I only need the degrees to radians func at the moment:

# get degrees to radians func
from math import radians

        self.msg_field_of_view = radians(25.0)     # +/- 12.5 degree FOV (~60cm at max range)
edit retag flag offensive close merge delete

Comments

If all else fails, it's easiest to look at the source code.

Given that angles isn't really that complex (it's essentially a single file) and all functions are pretty well documented, that should provide you with the information you're looking for.

gvdhoorn gravatar image gvdhoorn  ( 2021-07-14 04:57:41 -0600 )edit

Thank you for responding, but nowhere in the source code does anything tell me where ROS2 installs the source code.

Case in point: looking at the source for std_msgs.msg.Float32 nowhere does it say to:
- place <exec_depends>std_msgs</exec_depends> in package.xml
- run rosdep install -i --from-path src in your ros2 workspace root
- place "from std_msgs.msg import Float32" in your Python program
and life will be great, but I figured that out from the source code AND the similarity to the ROS2 pub/sub tutorial which publishes a "String" by "from std_msgs.msg import String"

ROS2 angles python setup codeseems to indicate the Python package is "angles", and suggest "from angles import from_degrees" BUT - build succeeds - execution says:

from angles import from_degrees
ModuleNotFoundError: No module named 'angles'
RobotDreams gravatar image RobotDreams  ( 2021-07-14 08:27:00 -0600 )edit

but nowhere in the source code does anything tell me where ROS2 installs the source code.

Not the specific link I referred you to, no.

But angles/CMakeLists.txt does. And so does angles/setup.py, but that's indeed pre-ROS 2.

But in any case: I did not point you "the source code" to figure out where things are installed. I understood your question as asking "what functionality is offered by this package?".

gvdhoorn gravatar image gvdhoorn  ( 2021-07-14 09:07:04 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2021-07-14 08:59:26 -0600

gvdhoorn gravatar image

I'm not sure I understand what you're asking in this case. From your question it appeared you were wondering how to use the angles package, once you've installed it (you wrote "ros2-foxy-angles got installed by rosdep from my package.xml").

I don't understand how std_msgs.msg.Float32 is related.

The link to the source repository is displayed on the ROS Index page you already linked. See #q381559.

but nowhere in the source code does anything tell me where ROS2 installs the source code. [..] I'm starting to think Foxy does not support angles in Python.

While there is nothing in the package itself (ie: the actual business code) that would make it impossible to use this package on ROS 2, it does currently not install the Python-side. The setup.py is indeed pre-ament (meaning: catkin).

The angles package installed by rosdep for you is the C++ side.

If you have a need to use functionality right now, you could copy the relevant function(s) from the __init__.py and use them like that.

It would be nicer however if the Python side could be included in the next release.

I would recommend you open an issue on the tracker to discuss what would be needed to get it released. I would expect it would only take an update of the setup.py and perhaps the CMakeLists.txt.

It could also be the maintainers would like to split the Python and C++ versions of the packages. That would require slightly more changes, but would still not be too much work.

edit flag offensive delete link more

Comments

Thank you for looking deeper into my original question: "Where can I find a Python example for what to import? (after installing ros2-angles-foxy)"

Indeed - the answer is "there is no example, and ros2 foxy does not support Python interface to angles"

As a ROS2 nub, tackling the port of ROS1 gopigo3_node to ROS2 seems to be exposing me to some ROS2 bleeding edges (migrating launch arguments documentation, and now Python angles not yet.)

RobotDreams gravatar image RobotDreams  ( 2021-07-14 09:24:16 -0600 )edit

"Where can I find a Python example for what to import? (after installing ros2-angles-foxy)"

just to be extra clear: there would be nothing special about angles necessarily. It would just be another Python package. The fact it's used with ROS (1 or 2) does not really matter.

gvdhoorn gravatar image gvdhoorn  ( 2021-07-14 09:37:22 -0600 )edit

And it seems you opened an issue on the tracker: ros/angles#26.

gvdhoorn gravatar image gvdhoorn  ( 2021-07-14 09:38:14 -0600 )edit
0

answered 2021-07-14 08:12:03 -0600

BTables gravatar image

updated 2021-07-14 10:17:52 -0600

Your question seems to indicate you're only looking to use a single function from the angles package. If that's the case it's really simpler, and better design, to just implement the function yourself.

def from_degrees(degrees):  
    return degrees * math.pi / 180.0;
edit flag offensive delete link more

Comments

Would you say that re-implementing something which already exists somewhere else in the form of a reusable library is better design?

gvdhoorn gravatar image gvdhoorn  ( 2021-07-14 10:01:23 -0600 )edit

Sorry, by M_PI do you mean import math.pi as M_PI?

I prefer the workaround:
from math import radians
var_rads = radians(var_degrees)

RobotDreams gravatar image RobotDreams  ( 2021-07-14 10:14:11 -0600 )edit

Because the entire package package now depends on a single one-line function that does 2 operations. This makes the package uselessly and needlessly less portable for no reason.

BTables gravatar image BTables  ( 2021-07-14 10:17:13 -0600 )edit

@RobotDreams you're correct. I've been writing c++ all morning and it apparently leaked over here. I've edited my reply.

BTables gravatar image BTables  ( 2021-07-14 10:19:39 -0600 )edit

Because the entire package package now depends on a single one-line function that does 2 operations. This makes the package uselessly and needlessly less portable for no reason.

angles is a very lightweight dependency. And I was referring to the general case.

Your answer -- pre-edit -- was easily understood as "just write something yourself, that's always better design".

And re: your suggestion: if you're going to write something custom for this, at the very least just use math.radians(..). math is part of the Python standard runtime environment.

gvdhoorn gravatar image gvdhoorn  ( 2021-07-14 10:22:29 -0600 )edit

Lightweight or not, that package is now tied to a version of ros that has a release of angles. I also never meant to imply it's always better to design to write something yourself. That's why I said I was referencing this specific situation.

BTables gravatar image BTables  ( 2021-07-14 10:36:31 -0600 )edit

angles does much more than from_degrees(..). There's functionality in there which you don't want to duplicate, if only for the fact it has been hardened by years of use.

I'm not really sure I understand how depending on angles is different than rclcpp or anything else. The whole point of ROS is the component based development it allows. If we start to copy / reimplement things everywhere, we negate it.

gvdhoorn gravatar image gvdhoorn  ( 2021-07-14 10:42:33 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2021-07-13 16:33:27 -0600

Seen: 696 times

Last updated: Jul 14 '21