ros2-numpy


Nameros2-numpy JSON
Version 0.0.4 PyPI version JSON
download
home_pagehttps://github.com/nitesh-subedi/ros2_numpy
SummaryConvert ROS2 messages to and from numpy arrays
upload_time2023-03-24 16:34:56
maintainerNitesh Subedi
docs_urlNone
authorTom
requires_python>=3.10
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ros2_numpy

Note: This is the same as the original ros_numpy package by eric-wieser and ros2_numpy package by box-robotics just edited to be OS independent and installable using pip.

### Pointcloud manipulation is updated `ros2_numpy.pointcloud2` to be compatible with ROS2. It now gives a structured numpy array with the fields `x`, `y`, `z`, `rgb`, `intensity`. The `rgb` field is a 3-tuple of uint8 values. The `intensity` field is a float32 value. The `x`, `y`, `z` fields are float32 values.

<br>

This project is a fork of [ros2_numpy](https://github.com/Box-Robotics/ros2_numpy) to work with ROS 2. It provides tools for converting ROS messages to and from numpy arrays. In the ROS 2 port, the module has been renamed to
`ros2_numpy`. Users are encouraged to update their application code to import
the module as shown below.

```
pip install ros2-numpy
import ros2_numpy as rnp
```

Prefacing your calls like `rnp.numpify(...)` or `rnp.msgify(...)` should help
future proof your codebase while the ROS 2 ports are API compatible.

This module contains two core functions:

* `arr = numpify(msg, ...)` - try to get a numpy object from a message
* `msg = msgify(MessageType, arr, ...)` - try and convert a numpy object to a message

Currently supports:

* `sensor_msgs.msg.PointCloud2` &harr; structured `np.array`:

   ```python
   data = np.zeros(100, dtype=[
     ('x', np.float32),
     ('y', np.float32),
     ('vectors', np.float32, (3,))
   ])
   data['x'] = np.arange(100)
   data['y'] = data['x']*2
   data['vectors'] = np.arange(100)[:,np.newaxis]

   msg = ros2_numpy.msgify(PointCloud2, data)
   ```

   ```
   data = ros2_numpy.numpify(msg)
   ```

* `sensor_msgs.msg.Image` &harr; 2/3-D `np.array`, similar to the function of `cv_bridge`, but without the dependency on `cv2`
* `nav_msgs.msg.OccupancyGrid` &harr; `np.ma.array`
* `geometry.msg.Vector3` &harr; 1-D `np.array`. `hom=True` gives `[x, y, z, 0]`
* `geometry.msg.Point` &harr; 1-D `np.array`. `hom=True` gives `[x, y, z, 1]`
* `geometry.msg.Quaternion` &harr; 1-D `np.array`, `[x, y, z, w]`
* `geometry.msg.Transform` &harr; 4&times;4 `np.array`, the homogeneous transformation matrix
* `geometry.msg.Pose` &harr; 4&times;4 `np.array`, the homogeneous transformation matrix from the origin

Support for more types can be added with:

```python
@ros2_numpy.converts_to_numpy(SomeMessageClass)
def convert(my_msg):
    return np.array(...)

@ros2_numpy.converts_from_numpy(SomeMessageClass)
def convert(my_array):
    return SomeMessageClass(...)
```

Any extra args or kwargs to `numpify` or `msgify` will be forwarded to your conversion function


## Future work

* Add simple conversions for:

  * `geometry_msgs.msg.Inertia`

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nitesh-subedi/ros2_numpy",
    "name": "ros2-numpy",
    "maintainer": "Nitesh Subedi",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "074bme624.nitesh@pcampus.edu.np",
    "keywords": "",
    "author": "Tom",
    "author_email": "tom@boxrobotics.ai",
    "download_url": "https://files.pythonhosted.org/packages/3a/b9/44a3f46051bb11c41ca502341d86a345dbc0a3181ce9fc2df6da0a2855c2/ros2_numpy-0.0.4.tar.gz",
    "platform": null,
    "description": "# ros2_numpy\n\nNote: This is the same as the original ros_numpy package by eric-wieser and ros2_numpy package by box-robotics just edited to be OS independent and installable using pip.\n\n### Pointcloud manipulation is updated `ros2_numpy.pointcloud2` to be compatible with ROS2. It now gives a structured numpy array with the fields `x`, `y`, `z`, `rgb`, `intensity`. The `rgb` field is a 3-tuple of uint8 values. The `intensity` field is a float32 value. The `x`, `y`, `z` fields are float32 values.\n\n<br>\n\nThis project is a fork of [ros2_numpy](https://github.com/Box-Robotics/ros2_numpy) to work with ROS 2. It provides tools for converting ROS messages to and from numpy arrays. In the ROS 2 port, the module has been renamed to\n`ros2_numpy`. Users are encouraged to update their application code to import\nthe module as shown below.\n\n```\npip install ros2-numpy\nimport ros2_numpy as rnp\n```\n\nPrefacing your calls like `rnp.numpify(...)` or `rnp.msgify(...)` should help\nfuture proof your codebase while the ROS 2 ports are API compatible.\n\nThis module contains two core functions:\n\n* `arr = numpify(msg, ...)` - try to get a numpy object from a message\n* `msg = msgify(MessageType, arr, ...)` - try and convert a numpy object to a message\n\nCurrently supports:\n\n* `sensor_msgs.msg.PointCloud2` &harr; structured `np.array`:\n\n   ```python\n   data = np.zeros(100, dtype=[\n     ('x', np.float32),\n     ('y', np.float32),\n     ('vectors', np.float32, (3,))\n   ])\n   data['x'] = np.arange(100)\n   data['y'] = data['x']*2\n   data['vectors'] = np.arange(100)[:,np.newaxis]\n\n   msg = ros2_numpy.msgify(PointCloud2, data)\n   ```\n\n   ```\n   data = ros2_numpy.numpify(msg)\n   ```\n\n* `sensor_msgs.msg.Image` &harr; 2/3-D `np.array`, similar to the function of `cv_bridge`, but without the dependency on `cv2`\n* `nav_msgs.msg.OccupancyGrid` &harr; `np.ma.array`\n* `geometry.msg.Vector3` &harr; 1-D `np.array`. `hom=True` gives `[x, y, z, 0]`\n* `geometry.msg.Point` &harr; 1-D `np.array`. `hom=True` gives `[x, y, z, 1]`\n* `geometry.msg.Quaternion` &harr; 1-D `np.array`, `[x, y, z, w]`\n* `geometry.msg.Transform` &harr; 4&times;4 `np.array`, the homogeneous transformation matrix\n* `geometry.msg.Pose` &harr; 4&times;4 `np.array`, the homogeneous transformation matrix from the origin\n\nSupport for more types can be added with:\n\n```python\n@ros2_numpy.converts_to_numpy(SomeMessageClass)\ndef convert(my_msg):\n    return np.array(...)\n\n@ros2_numpy.converts_from_numpy(SomeMessageClass)\ndef convert(my_array):\n    return SomeMessageClass(...)\n```\n\nAny extra args or kwargs to `numpify` or `msgify` will be forwarded to your conversion function\n\n\n## Future work\n\n* Add simple conversions for:\n\n  * `geometry_msgs.msg.Inertia`\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Convert ROS2 messages to and from numpy arrays",
    "version": "0.0.4",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "75392079d3c97580991dd40d1b58f7df4418f23a10688d9349e44c7cef55ef6e",
                "md5": "2d7f4b34b909a99e58e2a4de4de21c47",
                "sha256": "29bddf902231eac560659408649a9ed4a8925926daa7346f7a50584d020bb658"
            },
            "downloads": -1,
            "filename": "ros2_numpy-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2d7f4b34b909a99e58e2a4de4de21c47",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 8540,
            "upload_time": "2023-03-24T16:34:54",
            "upload_time_iso_8601": "2023-03-24T16:34:54.470116Z",
            "url": "https://files.pythonhosted.org/packages/75/39/2079d3c97580991dd40d1b58f7df4418f23a10688d9349e44c7cef55ef6e/ros2_numpy-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3ab944a3f46051bb11c41ca502341d86a345dbc0a3181ce9fc2df6da0a2855c2",
                "md5": "a2ae2d91941df4ec33b6c8a228794622",
                "sha256": "752aaae7a42a8ad7e2e8ff687bfd131207f16cc634e9d5d279b8ad1e54ca4595"
            },
            "downloads": -1,
            "filename": "ros2_numpy-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "a2ae2d91941df4ec33b6c8a228794622",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 10466,
            "upload_time": "2023-03-24T16:34:56",
            "upload_time_iso_8601": "2023-03-24T16:34:56.239079Z",
            "url": "https://files.pythonhosted.org/packages/3a/b9/44a3f46051bb11c41ca502341d86a345dbc0a3181ce9fc2df6da0a2855c2/ros2_numpy-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-24 16:34:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "nitesh-subedi",
    "github_project": "ros2_numpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "ros2-numpy"
}
        
Tom
Elapsed time: 0.07862s