Ask Your Question
0

publish numpy matrix to topic

asked 2016-08-01 09:03:31 -0500

Bant gravatar image

Hello together,

I would like to publish a 10x10x10 numpy-Matrix in one publishing step. Therefore I would like to know how I can declare the numpy.ndarray as a message type like

matrix.msg:

numpy.ndarray matrix

Is that even possible? What do I have to add to the CMakeLists.txt to get that running? Is there maybe a better way?

Thanks in advance!

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2016-08-01 12:34:17 -0500

emielke gravatar image

I've tried this before, the simplest way I could find was to put the matrix into row-major order and publish the data as an array. In essence, I just used the Float64MultiArray msg type and filled up that array with the matrix information and then published it. I don't know if there is a way to make a "matrix" msg type that would make this more simple, but this worked for me and I was able to get all the info passed around pretty easily.

edit flag offensive delete link more

Comments

Even though I posted the numpy tutorial I do agree that this might be the easiest solution.

Chrissi gravatar imageChrissi ( 2016-08-01 13:25:36 -0500 )edit

Thank you. I will do it like this for now. If I find a different approach I will add an answer here.

Bant gravatar imageBant ( 2016-08-02 04:43:41 -0500 )edit
0

answered 2016-08-01 09:42:32 -0500

Chrissi gravatar image

The ros numpy tutorial might help.

edit flag offensive delete link more

Comments

I think the tutorial only covers arrays, as they are using the "Floats" msg from rospy_tutorials. (Floats.msg: float32[] data)

Bant gravatar imageBant ( 2016-08-02 04:45:55 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-08-01 09:03:31 -0500

Seen: 809 times

Last updated: Aug 01 '16