How to appear object in V-rep- Poppy?

français
english
Tags: #<Tag:0x00007f5e050e9448> #<Tag:0x00007f5e050e9308>

#1

Hello everybody!

I started tp use VREP and IP Python Notebook a few weeks ago so I don’t know to much of this kind of programms. The last week I try to appear a cube in front of poppy, but I can’t do that because of a ‘str’ trouble.

io = poppy._controllers[0].io

*# Création du cube devant Poppy

name = 'cube’
position = [0.2, 0, 0.8] # X, Y, Z
sizes = [0.1, 0.1, 0.1] # in meters
mass = 0.5 # in kg
io.add_cube((name, position, sizes, mass)

When I execute thats lines the program send me a Type Error message.


TypeError Traceback (most recent call last)
in ()
3 sizes = [0.1, 0.1, 0.1] # in meters
4 mass = 0.5 # in kg
----> 5 io.add_cube(name, position, sizes, mass)

C:\Users\Me\Anaconda3\lib\site-packages\pypot\vrep\io.py in add_cube(self, name, position, sizes, mass)
228 def add_cube(self, name, position, sizes, mass):
229 “”" Add Cube “”"
–> 230 self._create_pure_shape(0, 239, sizes, mass, [0, 0])
231 self.set_object_position(“Cuboid”, position)
232 self.change_object_name(“Cuboid”, name)

C:\Users\Me\Anaconda3\lib\site-packages\pypot\vrep\io.py in _create_pure_shape(self, primitive_type, options, sizes, mass, precision)
261 “”" Create Pure Shape “”"
262 lua_code = “simCreatePureShape({}, {}, {{{}, {}, {}}}, {}, {{{}, {}}})”.format(primitive_type, options, sizes[0], sizes[1], sizes[2], mass, precision[0], precision[1])
–> 263 self._inject_lua_code(lua_code)
264
265 def _inject_lua_code(self, lua_code):

C:\Users\Me\Anaconda3\lib\site-packages\pypot\vrep\io.py in _inject_lua_code(self, lua_code)
265 def _inject_lua_code(self, lua_code):
266 “”" Sends raw lua code and evaluate it wihtout any checking! “”"
–> 267 msg = (ctypes.c_ubyte * len(lua_code)).from_buffer_copy(lua_code)
268 self.call_remote_api(‘simxWriteStringStream’, ‘my_lua_code’, msg)
269

TypeError: ‘str’ does not support the buffer interface


I don’t understand what I have to do, before exposing you this problem I have read something similar, they say that it’s a ‘str’ problem because we have to convert string to bytes.

Can everybody could help me please?

thanks


#2

Can you try to replace:

name = 'cube'

with:

name = b'cube'

and let me know if it’s work.


#3

I guess you are using python 3.4. I have the same issue with python 3.x
I didn’t investigate a lot but I thought that the code “.from_buffer_copy” is not compatible with Py3 ??

@Pierre just tested with b’cube’ and it doesn’t work better.

Maybe someone know a python 3 compatible syntax for :

msg = (ctypes.c_ubyte * len(lua_code)).from_buffer_copy(lua_code)

#4

Thanks you Pierre, that doesn’t works , when I replace it sends me an error message.


#5

Yes I’m using Python 3 and as you say in the message error it appears something about the buffer. I’ll keep searching a solution. If I find it I’ll tell you :wink:


#6

with something like that :

msg = (ctypes.c_ubyte * len(lua_code)).from_buffer_copy(bytes(lua_code, 'utf-8')) 

the error message disappear, but I don’t know if the lua injection still works.


#7

@Pierre I made a pull request to fix the issue. Tested on python 2.7 and 3.4

from_buffer_copy(lua_code.encode())

#8

#9

Merged in https://github.com/poppy-project/pypot/pull/117