## How to get a lot of data from CoppeliaSim with remote API

Typically: "How do I... ", "How can I... " questions
Zhuang
Posts: 28
Joined: 02 Aug 2017, 14:43

### How to get a lot of data from CoppeliaSim with remote API

1.
I tried to quickly get a lot of data from Vrep with remoteApi(B0-based remote API, python and matlab).
First, using sim.packFloatTable() to pack data;
Then, using sim.setStringSignal() to send data to Matlab(or python);
it is true that I can get data quickly, but There is no function like sim.unpackFloatTable() for remoteApi.

(1)So are there some easy methods to obtain a lot of data from Vrep?
(2)If there is no, how to make a function like sim.unpackFloatTable() using python?

2.
Anyway, In CoppeliaSim(CoppeliaSim Edu V4.0.0 rev1), I tried to see the string to decode the pack, but ...

> a = {-1.6175812482834, -0.039899371564388, 1.6150631904602}
> sim.packFloatTable(a)
"?????m#?d???"
> sim.unpackFloatTable("?????m#?d???")
{0.7470588088, 0.6383857131, 0.7470610142}
> b = sim.packFloatTable(a)
> sim.unpackFloatTable(b)
{-1.617581248, -0.03989937156, 1.61506319}

(1)How to solve the problem?

coppelia
Posts: 7527
Joined: 14 Dec 2012, 00:25

### Re: How to get a lot of data from CoppeliaSim with remote API

Hello,

you said you are using the B0-based remote API... why don't you simply use simxCallScriptFunction?

something like:

Code: Select all

client.simxCallScriptFunction('myFunction@DefaultCamera','sim.scripttype_childscript',anyTypeOfData,client.simxServiceCall())
With above function, you can transmit and receive any type of data, via a script function.

Cheers

Zhuang
Posts: 28
Joined: 02 Aug 2017, 14:43

### Re: How to get a lot of data from CoppeliaSim with remote API

Hello,
Yes, using simxCallScriptFunction() is a good method, and I can use the function to call sim.unpackFloatTable() to decode data. indeed, I do not have to use python to reproduce the function.

But will this way reduce its transmission speed?
It's very similar to transferring floating-point numbers directly from vrep to the outside
Thank you
Cheers

Zhuang
Posts: 28
Joined: 02 Aug 2017, 14:43

### Re: How to get a lot of data from CoppeliaSim with remote API

Hello,
This approach does not work. It does slow down the transmission, so that there is an error:terminate called after throwing an instance of 'zmq::error_t' (python) ．

So I have to know how to unpack the data outside.

If I know sim.unpackFloatTable source code, I can reproduce the function with python.

Cheers

coppelia
Posts: 7527
Joined: 14 Dec 2012, 00:25

### Re: How to get a lot of data from CoppeliaSim with remote API

In the Python legacy remote API you have those packing/unpacking functions:

Code: Select all

def simxPackInts(intList):
'''
Please have a look at the function description/documentation in the CoppeliaSim user manual
'''

if sys.version_info[0] == 3:
s=bytes()
for i in range(len(intList)):
s=s+struct.pack('<i',intList[i])
s=bytearray(s)
else:
s=''
for i in range(len(intList)):
s+=struct.pack('<i',intList[i])
return s

def simxUnpackInts(intsPackedInString):
'''
Please have a look at the function description/documentation in the CoppeliaSim user manual
'''
b=[]
for i in range(int(len(intsPackedInString)/4)):
b.append(struct.unpack('<i',intsPackedInString[4*i:4*(i+1)])[0])
return b

def simxPackFloats(floatList):
'''
Please have a look at the function description/documentation in the CoppeliaSim user manual
'''

if sys.version_info[0] == 3:
s=bytes()
for i in range(len(floatList)):
s=s+struct.pack('<f',floatList[i])
s=bytearray(s)
else:
s=''
for i in range(len(floatList)):
s+=struct.pack('<f',floatList[i])
return s

def simxUnpackFloats(floatsPackedInString):
'''
Please have a look at the function description/documentation in the CoppeliaSim user manual
'''
b=[]
for i in range(int(len(floatsPackedInString)/4)):
b.append(struct.unpack('<f',floatsPackedInString[4*i:4*(i+1)])[0])
return b

Cheers