Giter Club home page Giter Club logo

ros_np_multiarray's Introduction

ros_np_multiarray

Convert between numpy ndarray and ros multiarray message.

Usage

This is a simple example.

from ros_np_multiarray import ros_np_multiarray as rnm
import numpy as np

print(rnm.to_multiarray_f32(np.array([[[1.0, 2.0], [3.0, 4.0]]], dtype=np.float32)))

We get the data converted to 'std_msgs/Float32MultiArray'.

layout: 
  dim: 
    - 
      label: "dim0"
      size: 1
      stride: 4
    - 
      label: "dim1"
      size: 2
      stride: 8
    - 
      label: "dim2"
      size: 2
      stride: 8
  data_offset: 0
data: [1.0, 2.0, 3.0, 4.0]

ros_np_multiarray's People

Contributors

neka-nat avatar luca-pozzi avatar

Stargazers

ichigo avatar Matthieu M avatar Zhengtong Xu avatar chingwen avatar Jamy Chahal avatar  avatar Mustafa Bayrak avatar  avatar Arun Muraleedharan avatar Keenan Albee avatar Saif Sidhik avatar Vincent Mayer avatar paul avatar  avatar Xuefeng avatar  avatar

Watchers

James Cloos avatar  avatar

ros_np_multiarray's Issues

Python3 compatibility

Hi,
first of all, thanks for this super-useful package!

I would like to highlight some compatibility issue with Python3 and how I managed to solve them.

Import statement

The import statement shown in the README causes an AttributeError, specifically:

AttributeError: module 'ros_np_multiarray' has no attribute 'to_multiarray_f32'

Instead, one should use

from ros_np_multiarray import ros_np_multiarray as rnm

and everything works fine.

Conversion to NumPy

When running one of the to_numpy, a TypeError occurs, specifically:

TypeError: expected sequence object with len >= 0 or a single integer

The issue can be solved by modifying the first line of the _multiarray_to_numpy function to convert dims to a tuple, i.e.

dims = tuple(map(lambda x: x.size, multiarray.layout.dim))


As the mentioned changes seem to work in Python2.7 as well, it could be useful to update the code in order to achieve Python3 compatibility.

System's info:

  • Ubuntu 18.04-LTS
  • ROS Melodic

ROS2 compatibility

Hi,
I am trying to use this package to send np arrays using ROS2 but got this error:

[inference.py-1]   File "/home/docker_gnn/colcon_ws/install/_gnn/lib/_gnn/inference.py", line 363, in lidar_callback
[inference.py-1]     cur_msg.array = rnm.to_multiarray_f32(cur_traj.astype('float32'))
[inference.py-1]   File "/home/docker_gnn/.local/lib/python3.10/site-packages/ros_np_multiarray/ros_np_multiarray.py", line 11, in _numpy_to_multiarray
[inference.py-1]     multiarray.layout.dim = [MultiArrayDimension('dim%d' % i,
[inference.py-1]   File "/home/docker_gnn/.local/lib/python3.10/site-packages/ros_np_multiarray/ros_np_multiarray.py", line 11, in <listcomp>
[inference.py-1]     multiarray.layout.dim = [MultiArrayDimension('dim%d' % i,
[inference.py-1] TypeError: MultiArrayDimension.__init__() takes 1 positional argument but 4 were given

PS: Everything works fine with ROS1
Any suggestions?
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.