synchronousImageTransmission.py Example Runs Properly only onetime/boot(ubuntu 16.04)

Report crashes, strange behaviour, or apparent bugs
Post Reply
shadowzone
Posts: 16
Joined: 17 Feb 2020, 22:49

synchronousImageTransmission.py Example Runs Properly only onetime/boot(ubuntu 16.04)

Post by shadowzone »

Hello im using ubuntu 16.04 and coppeliaSim V4.0
i was testing Synchronous mode Example of imageTransmission using the remote api(Python), and the script on ubuntu runs properly the first time only then on restarting the script the code says / prints that it is connected but it doesn't run the simulation until i restart my pc

If i try the same thing on windows it works fine

Few Test Cases:
1
1-Run script then it runs the scene
2-Run the script again(after it ends) it says connected but it doesn't open the simulation

2
1-Run Script then it runs the scene
2-Close coppeliaSim
3-Run the script(it says connected meaning it doesn't detect the coppeliaSim is closed)

so what i noticed that after running the script example first time and the simulation starts and ends on the coppeliaSim side, somehow there is a sort of connection open even if coppeliaSim is closed

i tried killing the b0_resolver as someone suggested to me but it didn't do anything

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

Re: synchronousImageTransmission.py Example Runs Properly only onetime/boot(ubuntu 16.04)

Post by coppelia »

Hello,

can you confirm that you are running CoppeliaSim V4.0.0, revision 4?
Does below script give you the same result?

Code: Select all

# Make sure to have CoppeliaSim running, with followig scene loaded:
#
# scenes/synchronousImageTransmissionViaRemoteApi.ttt
#
# Do not launch simulation, and make sure that the B0 resolver
# is running. Then run this script
#
# The client side (i.e. this script) depends on:
#
# b0RemoteApi (Python script), which depends several libraries present
# in the CoppeliaSim folder

import b0RemoteApi
import time

with b0RemoteApi.RemoteApiClient('b0RemoteApi_pythonClient','b0RemoteApi') as client:    
    client.doNextStep=True
    client.runInSynchronousMode=True

    def simulationStepStarted(msg):
        simTime=msg[1][b'simulationTime'];
        print('Simulation step started. Simulation time: ',simTime)
        
    def simulationStepDone(msg):
        simTime=msg[1][b'simulationTime'];
        print('Simulation step done. Simulation time: ',simTime);
        client.doNextStep=True
        
    def imageCallback(msg):
        print('Received image.',msg[1])
        client.simxSetVisionSensorImage(passiveVisionSensorHandle[1],False,msg[2],client.simxDefaultPublisher())
        
    def stepSimulation():
        if client.runInSynchronousMode:
            while not client.doNextStep:
                client.simxSpinOnce()
            client.doNextStep=False
            client.simxSynchronousTrigger()
        else:
            client.simxSpinOnce()
    
    client.simxAddStatusbarMessage('Hello world!',client.simxDefaultPublisher())
    visionSensorHandle=client.simxGetObjectHandle('VisionSensor',client.simxServiceCall())
    passiveVisionSensorHandle=client.simxGetObjectHandle('PassiveVisionSensor',client.simxServiceCall())

    if client.runInSynchronousMode:
        client.simxSynchronous(True)
    
    #dedicatedSub=client.simxCreateSubscriber(imageCallback,1,True)
    #client.simxGetVisionSensorImage(visionSensorHandle[1],False,dedicatedSub)
    client.simxGetVisionSensorImage(visionSensorHandle[1],False,client.simxDefaultSubscriber(imageCallback))

    client.simxGetSimulationStepStarted(client.simxDefaultSubscriber(simulationStepStarted));
    client.simxGetSimulationStepDone(client.simxDefaultSubscriber(simulationStepDone));
    client.simxStartSimulation(client.simxDefaultPublisher())
    
    startTime=time.time()
    while time.time()<startTime+5:
        stepSimulation()
        
    client.simxStopSimulation(client.simxDefaultPublisher())
Cheers

shadowzone
Posts: 16
Joined: 17 Feb 2020, 22:49

Re: synchronousImageTransmission.py Example Runs Properly only onetime/boot(ubuntu 16.04)

Post by shadowzone »

The Version is indeed 4.0.0(this is the name of the folder CoppeliaSim_Edu_V4_0_0_Ubuntu16_04)

i tried the following code in the b0api bindings folder and after downloading the dependancies
Using 2.7 Python i get :

Code: Select all

this is the result from the python script side:
('Received image.', [256, 256])
('Received image.', [256, 256])
('Received image.', [256, 256])
('Received image.', [256, 256])
('Received image.', [256, 256])
('Received image.', [256, 256])
('Simulation step started. Simulation time: ', 0)
*************************************************************************************
** Leaving... if this is unexpected, you might have to adjust the timeout argument **
*************************************************************************************
('Simulation step done. Simulation time: ', 0.05000000074505806)
The simulation doesnt close automatically nor it does it jobs as it do on windows

after a few times of closing the simulation automatically and opening the simulation using the python script i now get this

Code: Select all

  Running B0 Remote API client with channel name [b0RemoteApi]
  make sure that: 1) the B0 resolver is running
                  2) CoppeliaSim is running the B0 Remote API server with the same channel name
  Initializing...


  Connected!

('Received image.', [256, 256])
('Received image.', [256, 256])
('Received image.', [256, 256])
('Received image.', [256, 256])
('Received image.', [256, 256])
('Received image.', [256, 256])
('Simulation step started. Simulation time: ', 0)
*************************************************************************************
** Leaving... if this is unexpected, you might have to adjust the timeout argument **
*************************************************************************************
Traceback (most recent call last):
  File "/home/ahmed/Downloads/CoppeliaSim_Edu_V4_0_0_Ubuntu16_04/programming/b0RemoteApiBindings/python/test.py", line 61, in <module>
    client.simxStopSimulation(client.simxDefaultPublisher())
  File "/home/ahmed/Downloads/CoppeliaSim_Edu_V4_0_0_Ubuntu16_04/programming/b0RemoteApiBindings/python/b0RemoteApi.py", line 49, in __exit__
    self.simxSpinOnce();
  File "/home/ahmed/Downloads/CoppeliaSim_Edu_V4_0_0_Ubuntu16_04/programming/b0RemoteApiBindings/python/b0RemoteApi.py", line 179, in simxSpinOnce
    self._handleReceivedMessage(readData)
  File "/home/ahmed/Downloads/CoppeliaSim_Edu_V4_0_0_Ubuntu16_04/programming/b0RemoteApiBindings/python/b0RemoteApi.py", line 62, in _handleReceivedMessage
    msg=msgpack.unpackb(msg)
  File "/home/ahmed/.local/lib/python2.7/site-packages/msgpack/fallback.py", line 129, in unpackb
    ret = unpacker._unpack()
  File "/home/ahmed/.local/lib/python2.7/site-packages/msgpack/fallback.py", line 643, in _unpack
    ret.append(self._unpack(EX_CONSTRUCT))
  File "/home/ahmed/.local/lib/python2.7/site-packages/msgpack/fallback.py", line 643, in _unpack
    ret.append(self._unpack(EX_CONSTRUCT))
  File "/home/ahmed/.local/lib/python2.7/site-packages/msgpack/fallback.py", line 680, in _unpack
    obj = obj.decode("utf_8", self._unicode_errors)
  File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xc4 in position 0: invalid continuation byte
The reponse on coppeliaSimSide was:

Code: Select all

Hello world!
[18:27:02] B0 Remote API: registering streaming function 'GetVisionSensorImage' for client 'UMptxtRIyV' on topic 'b0RemoteApiPub2UMptxtRIyV' (default publisher) 
[18:27:02] B0 Remote API: registering streaming function 'GetSimulationStepStarted' for client 'UMptxtRIyV' on topic 'b0RemoteApiPub3UMptxtRIyV' (default publisher) 
[18:27:02] B0 Remote API: registering streaming function 'GetSimulationStepDone' for client 'UMptxtRIyV' on topic 'b0RemoteApiPub4UMptxtRIyV' (default publisher) 
Simulation started.
[01:00:00.00] B0 Remote API: registering streaming function 'Ping' for client 'UMptxtRIyV' on topic 'b0RemoteApiPub5UMptxtRIyV' (default publisher) 
[01:00:00.00] B0 Remote API: destroyed all streaming functions for client '13gy5Zgaeg' after detection of inactivity  
Using Python 3.5.2
i get this :

Code: Select all

  Running B0 Remote API client with channel name [b0RemoteApi]
  make sure that: 1) the B0 resolver is running
                  2) CoppeliaSim is running the B0 Remote API server with the same channel name
  Initializing...


  Connected!

*************************************************************************************
** Leaving... if this is unexpected, you might have to adjust the timeout argument **
*************************************************************************************
Traceback (most recent call last):
  File "/home/ahmed/Downloads/CoppeliaSim_Edu_V4_0_0_Ubuntu16_04/programming/b0RemoteApiBindings/python/test.py", line 59, in <module>
    stepSimulation()
  File "/home/ahmed/Downloads/CoppeliaSim_Edu_V4_0_0_Ubuntu16_04/programming/b0RemoteApiBindings/python/test.py", line 36, in stepSimulation
    client.simxSpinOnce()
  File "/home/ahmed/Downloads/CoppeliaSim_Edu_V4_0_0_Ubuntu16_04/programming/b0RemoteApiBindings/python/b0RemoteApi.py", line 179, in simxSpinOnce
    self._handleReceivedMessage(readData)
  File "/home/ahmed/Downloads/CoppeliaSim_Edu_V4_0_0_Ubuntu16_04/programming/b0RemoteApiBindings/python/b0RemoteApi.py", line 63, in _handleReceivedMessage
    msg[0]=msg[0].decode('ascii')
AttributeError: 'str' object has no attribute 'decode'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ahmed/Downloads/CoppeliaSim_Edu_V4_0_0_Ubuntu16_04/programming/b0RemoteApiBindings/python/test.py", line 61, in <module>
    client.simxStopSimulation(client.simxDefaultPublisher())
  File "/home/ahmed/Downloads/CoppeliaSim_Edu_V4_0_0_Ubuntu16_04/programming/b0RemoteApiBindings/python/b0RemoteApi.py", line 49, in __exit__
    self.simxSpinOnce();
  File "/home/ahmed/Downloads/CoppeliaSim_Edu_V4_0_0_Ubuntu16_04/programming/b0RemoteApiBindings/python/b0RemoteApi.py", line 179, in simxSpinOnce
    self._handleReceivedMessage(readData)
  File "/home/ahmed/Downloads/CoppeliaSim_Edu_V4_0_0_Ubuntu16_04/programming/b0RemoteApiBindings/python/b0RemoteApi.py", line 63, in _handleReceivedMessage
    msg[0]=msg[0].decode('ascii')
AttributeError: 'str' object has no attribute 'decode'
2020-04-03 18:21:01 [��Api_pythonClient] error: HB: Context was terminated
and the coppeliaSim Resonpse was

Code: Select all

Hello world!
[18:26:08] B0 Remote API: registering streaming function 'GetVisionSensorImage' for client '13gy5Zgaeg' on topic 'b0RemoteApiPub213gy5Zgaeg' (default publisher) 
[18:26:08] B0 Remote API: registering streaming function 'GetSimulationStepStarted' for client '13gy5Zgaeg' on topic 'b0RemoteApiPub313gy5Zgaeg' (default publisher) 
[18:26:08] B0 Remote API: registering streaming function 'GetSimulationStepDone' for client '13gy5Zgaeg' on topic 'b0RemoteApiPub413gy5Zgaeg' (default publisher) 
Simulation started.
[01:00:00.00] B0 Remote API: registering streaming function 'Ping' for client '13gy5Zgaeg' on topic 'b0RemoteApiPub513gy5Zgaeg' (default publisher)

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

Re: synchronousImageTransmission.py Example Runs Properly only onetime/boot(ubuntu 16.04)

Post by coppelia »

is it possible that you have a slow system and that the timeout threshold is always reached? (default is 3 seconds). What happens if you replace line 16 with following?

Code: Select all

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

shadowzone
Posts: 16
Joined: 17 Feb 2020, 22:49

Re: synchronousImageTransmission.py Example Runs Properly only onetime/boot(ubuntu 16.04)

Post by shadowzone »

First of all thanks for your reply!

i tried this but it didnt work , but i dont think that has to do anything with my system being slow because it successfully activtes all the time the first time iboot my laptop, or to be more accurate the first time i open the scene with vrep and run the script , the following times it feels like it latches to an old session that is already closed

i tried your proposal but it didnt work

Code: Select all

File "/home/ahmed/Downloads/CoppeliaSim_Edu_V4_0_0_Ubuntu16_04/programming/b0RemoteApiBindings/python/b0RemoteApi.py", line 63, in _handleReceivedMessage
    msg[0]=msg[0].decode('ascii')
AttributeError: 'str' object has no attribute 'decode'
i think this is the line that explains the error but i dont understand it , this is on 3.5 python

Code: Select all

  File "/home/ahmed/.local/lib/python2.7/site-packages/msgpack/fallback.py", line 680, in _unpack
    obj = obj.decode("utf_8", self._unicode_errors)
  File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xc4 in position 0: invalid continuation byte
and this on 2.7 python



i tried the same example on a college's laptop and i got the same behaviour,
we installed msgpack and added libb0.so to the folder , idk if there is any extra steps we are missing, he also have 16.04 ubuntu

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

Re: synchronousImageTransmission.py Example Runs Properly only onetime/boot(ubuntu 16.04)

Post by coppelia »

this is a more or less random guess, does following change anything?

Code: Select all

ulimit -n 65535
Cheers

Post Reply