Ask Your Question
0

How to use Float32MultiArray (Publisher)

asked 2019-06-03 09:06:47 -0500

Shanika gravatar image

updated 2019-06-03 10:10:33 -0500

Hello,
I am trying to write a python code using the Float32MultiArray to run my robot's motors.

The code is below:

motor = rospy.Publisher('encoder', Float32MultiArray, queue_size = 2)

while not rospy is shutdown():

    arg = Float32MultiArray()
    arg.layout.dim[0].label ="x"
    arg.layout.dim[0].size = 1
    arg.layout.dim[0].stride = 1

    arg.layout.dim[1].label ="y"
    arg.layout.dim[1].size = 1
    arg.layout.dim[1].stride = 1

    arg.layout.data_offset = 1
    arg.data = [100, 100]

    motor.publish(arg)

However, I have the error below:

TypeError: Invalid number of arguments, arg should be ['layout','data'] args are(0.0)

Could you please help me ?

Thank you in advance,

Shanika

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-06-03 11:21:43 -0500

updated 2019-06-03 11:22:09 -0500

You have to allocate the arrays, when you're trying to access dim[] and data[] you haven't yet allocated it to have any size or inserted something into it.

E.i.

thing = MultiArrayDimension()
thing.label = "x"
thing.size = 1
thing.stride = 1
arg.layout.dim.append(thing)
edit flag offensive delete link more

Comments

Thank you, I will try this right now

Shanika gravatar imageShanika ( 2019-06-04 02:21:11 -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

2 followers

Stats

Asked: 2019-06-03 09:06:47 -0500

Seen: 112 times

Last updated: Jun 03