Python remote API crashing after getStringSignal.

Typically: "How do I... ", "How can I... " questions
Post Reply
camillebruckmann
Posts: 3
Joined: 29 May 2020, 00:56

Python remote API crashing after getStringSignal.

Post by camillebruckmann »

Hello,

I'm using the fast3DLaserScanner in my coppeliaSim scene and I would like to send the measured data to my python script in the remote API so that I can eventually create a point cloud. I am using Spyder as well as the bluezero remote API on MacOSX. I am encountering issues when I try to pack and send the data obtained from the scanner as a string signal. Here is a snippet of the LUA code.

Code: Select all


stop = false

function sysCall_sensing() 
    measuredData={}
    
    if notFirstHere then
        sim.addDrawingObjectItem(points,nil)
        showPoints=sim.getScriptSimulationParameter(sim.handle_self,'showPoints')
        r,t1,u1=sim.readVisionSensor(visionSensorHandle)
    
        m1=sim.getObjectMatrix(visionSensorHandle,-1)
        m01=simGetInvertedMatrix(sim.getObjectMatrix(sensorBaseHandle,-1))
        m01=sim.multiplyMatrices(m01,m1)
        if u1 then
            for j=0,u1[2]-1,1 do
                for i=0,u1[1]-1,1 do
                    w=2+4*(j*u1[1]+i)
                    v1=u1[w+1]
                    v2=u1[w+2]
                    v3=u1[w+3]
                    v4=u1[w+4]
                    if (v4<maxScanDistance_) then
                        p={v1,v2,v3}
                        p=sim.multiplyVector(m01,p)
                        table.insert(measuredData,p[1]) 
                        table.insert(measuredData,p[2]) 
                        table.insert(measuredData,p[3])
                    end
                    if showPoints then
                        p={v1,v2,v3}
                        p=sim.multiplyVector(m1,p)
                        sim.addDrawingObjectItem(points,p)
                    end
                end
            end
        end
    end
    notFirstHere=true
    if sim.getStringSignal('signal') == 'received' then
        if stop == false then
            data=sim.packFloatTable(measuredData)
            sim.setStringSignal("measuredDataAtThisTime",data) -- CAUSES ERROR
            sim.setStringSignal('testing','received') -- TEST CASE
            stop = true
        end
    end
Here is a snippet of the python code in Spyder:

Code: Select all

import b0RemoteApi
import time

with b0RemoteApi.RemoteApiClient('b0RemoteApi_pythonClient','b0RemoteApi',60) as client:    

    def callb(msg):
        print(msg)
    
    client.simxAddStatusbarMessage('We are Connected',client.simxDefaultPublisher())
    client.simxAddDrawingObject_cubes(0.03, [0,0,30], [0,30,0], client.simxDefaultPublisher())
    time.sleep(1)
    client.simxAddStatusbarMessage('Connected to remote API', client.simxServiceCall())
    time.sleep(1)
    print(client.simxGetStringSignal('testing', client.simxServiceCall())) #This works
    data = client.simxGetStringSignal("measuredDataAtThisTime", client.simxServiceCall()) #This does not
    client.simxCloseScene(client.simxServiceCall())
I am able to receive the test string signal I had set in the LUA code, however, when I try to obtain the actual string signal with my data I receive the following error:

Code: Select all

Traceback (most recent call last):

  File "/Users/camillebruckmann/Desktop/Python V-Rep/testing.py", line 16, in <module>
    data = client.simxGetStringSignal("measuredDataAtThisTime", client.simxServiceCall())

  File "/Users/camillebruckmann/Desktop/Python V-Rep/b0RemoteApi.py", line 285, in simxGetStringSignal
    return self._handleFunction('GetStringSignal',reqArgs,topic)

  File "/Users/camillebruckmann/Desktop/Python V-Rep/b0RemoteApi.py", line 74, in _handleFunction
    rep = msgpack.unpackb(self._serviceClient.call(packedData))

  File "msgpack/_unpacker.pyx", line 195, in msgpack._cmsgpack.unpackb

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcc in position 0: invalid continuation byte
Any ideas on how to address this issue? Or alternatives ways of sending the data between the regular and remote APIs?

Thanks.

coppelia
Site Admin
Posts: 7966
Joined: 14 Dec 2012, 00:25

Re: Python remote API crashing after getStringSignal.

Post by coppelia »

Hello,

can you try to run with the CoppeliaSim V4.1.0 version (beta is available here)?
Or check if this commit helps?

Cheers

Post Reply