B0 Remote API: destroyed all streaming functions for client after detection of inactivity

Report crashes, strange behaviour, or apparent bugs
Post Reply
ayushpatel14
Posts: 3
Joined: 11 Jun 2020, 06:13

B0 Remote API: destroyed all streaming functions for client after detection of inactivity

Post by ayushpatel14 »

I am creating a python script that uses BlueZero Remote API to start the
simulator and stream the vision sensor image, I am on windows and was
successful in getting the image but after about 30sec of simulation time the
script hangs and this message appears in the simulator:

"B0 Remote API: destroyed all streaming functions for client '13gy5Zgaeg' after detection of inactivity"

I would like my user to decide when to stop the simulator and hence stops streaming by a Keyboard Interrupt.
How do I stop this thing from happening?

here is my code snippet:

Code: Select all

# python 
with b0RemoteApi.RemoteApiClient('b0_Vision', 'b0RemoteApi', 60, False,100) as client:
      img = None

      def time_callback(msg):
          global sim_time
          sim_time = round(float(msg[1]),2)

      def imageCallback(msg):
          img= np.frombuffer(msg[2], dtype=np.uint8)
          img.resize([msg[1][1], msg[1][0], 1])
          sender.send_image(sim_time, img)
         
      ret, visionSensorHandle = client.simxGetObjectHandle('Vision_sensor',
client.simxServiceCall())
      if not ret:
          sys.exit(' No Object named "Vision_sensor" found!!')
      print(' *Starting simulator*')
      print(' *Press ctrl+c to Stop*\n')
     
      dedicatedSub=client.simxCreateSubscriber(imageCallback,1,True)
      t1=time.time()
      if client.simxStartSimulation(client.simxServiceCall()):  # Starting simulator
          client.simxGetSimulationTime(client.simxDefaultSubscriber(time_callback))
          client.simxGetVisionSensorImage(visionSensorHandle, True,dedicatedSub)
          #client.simxGetVisionSensorImage(visionSensorHandle, True,client.simxDefaultSubscriber(imageCallback))
          while True:
              try:
                  client.simxSpinOnce()  # to get data from waiting queue
              except KeyboardInterrupt:
                  break
          client.simxSpinOnce()  # Dumping the waiting queue data
          client.simxStopSimulation(client.simxServiceCall())  # stopping simulator
          print(' *Stopped Simulator*\n')
      else:
          sys.exit('***Simulator Error!***')
P.S I went through one similar post, but that didn't work out.

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

Re: B0 Remote API: destroyed all streaming functions for client after detection of inactivity

Post by coppelia »

Hello,

what about setting a larger inactivityTolerance argument? Currently the value is set at 60 seconds, which means that if CoppeliaSim doesn't hear from the client within 60 seconds, it will stop streaming data.
Alternatively, you could also send some dummy value to fake some activity, e.g. with

Code: Select all

client.simxSetIntSignal('a',0,client.simxDefaultPublisher())
In next release the CoppeliaSim side will disable inactivity checking if the inactivityTolerance argument is set to zero. You can also adjust this yourself in lua/b0RemoteApiServer.lua, function hasClientReachedMaxInactivityTime:

Code: Select all

function hasClientReachedMaxInactivityTime(clientId)
    local val=allClients[clientId]
    if val.maxInactivityTimeMs==0 then
        return false
    end
    return sim.getSystemTimeInMs(val.lastActivityTimeMs)>val.maxInactivityTimeMs
end
Cheers

Post Reply