Python Remote Api - Error with simxCheckDistance call

Typically: "How do I... ", "How can I... " questions
Post Reply
ask4jubad
Posts: 5
Joined: 21 Sep 2021, 07:46

Python Remote Api - Error with simxCheckDistance call

Post by ask4jubad »

I am trying to the get the distance between two objects, a robot gripper and a human arm through the python api thus:

Code: Select all

_,_, distance_left,_,_= client.simxCheckDistance(gripperHandle, human_hand_left, 0, client.simxServiceCall())
I believe that this is the right way to call the function if I am only
interested in getting the minimum distance.

It doesn't work.

I get this error: ** Leaving... if this is unexpected, you might have to adjust the timeout argument ** at this point.

What's the fix, please? I can't seem to find any helpful detail online.
Last edited by ask4jubad on 26 Sep 2021, 23:27, edited 1 time in total.

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

Re: Python Remote Api - Error with sim call

Post by coppelia »

Hello,

can you tell me what version of CoppeliaSim you are using, and also what platform?

Cheers

ask4jubad
Posts: 5
Joined: 21 Sep 2021, 07:46

Re: Python Remote Api - Error with simxCheckDistance call

Post by ask4jubad »

Hi,

Here are the setup details:
  • CoppeliaSim Edu, Version 4.2.0
  • Linux Ubuntu 20.04.3 LTS

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

Re: Python Remote Api - Error with simxCheckDistance call

Post by coppelia »

Do you also have the information about the revision number?

With CoppeliaSim V4.2.0 rev5 I can run simxCheckDistance fine.

Cheers

ask4jubad
Posts: 5
Joined: 21 Sep 2021, 07:46

Re: Python Remote Api - Error with simxCheckDistance call

Post by ask4jubad »

Hello,

I am using v4 but now downloaded v6 and it's still the same issue.

Note that I am using python api and not C.

ask4jubad
Posts: 5
Joined: 21 Sep 2021, 07:46

Re: Python Remote Api - Error with simxCheckDistance call

Post by ask4jubad »

This is what my basic program looks like:

Code: Select all

with b0RemoteApi.RemoteApiClient('b0RemoteApi_V-REP-addOn','b0RemoteApiAddOn', 60) as client:
	_, gripperHandle = client.simxGetObjectHandle("RG2_openCloseJoint",client.simxServiceCall())
	_,humanHandle = client.simxGetObjectHandle("Bill", client.simxServiceCall())
	_,human_hand_left = client.simxGetObjectHandle("Bill_leftHand_tip", client.simxServiceCall())#client to get left hand tip handle
	_,human_hand_right = client.simxGetObjectHandle("Bill_rightHand_tip", client.simxServiceCall())#client to get left hand tip handle
	client.simxStartSimulation(client.simxServiceCall()) #use client to start the simulation
	try:
		while(True):
			_,gripperpose = client.simxGetObjectPosition(gripperHandle, 0, client.simxServiceCall())
			print(gripperpose)
			_,humanpose = client.simxGetObjectPosition(humanHandle, 0, client.simxServiceCall())
			print(humanpose)

			""" placeholders """
			R = gripperpose
			H = humanpose

			calulated_distance = math.sqrt(pow((H[0] - R[0]), 2) + pow((H[1] - R[1]), 2) + pow((H[2] - R[2]), 2))
			print("The calcuated distance between human and robot arm is: ", calulated_distance,  "m")
			
			#distance between gripper joint and left hand
			check,_,distance_left,_,_ = client.simxCheckDistance(gripperHandle, human_hand_left, -1, client.simxServiceCall())
			print(check)
			print(distance_left)
			
	except:
		client.simxStopSimulation(client.simxServiceCall()) 

And this is the output:
importing successful!

Running B0 Remote API client with channel name [b0RemoteApiAddOn]
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!

[1.727636456489563, -0.005904495716094971, 4.065587520599365]
[0.38225793838500977, -0.7649074196815491, 5.134829521179199]
The calcuated distance between human and robot arm is: 1.878671672051633 m
*************************************************************************************
** Leaving... if this is unexpected, you might have to adjust the timeout argument **
*************************************************************************************

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

Re: Python Remote Api - Error with simxCheckDistance call

Post by coppelia »

not sure what is going on in your case, but here everything runs fine with the latest CoppeliaSim V4.2.0rev5

But: I see that you are trying to measure a distance between two objects, where the first object is a joint... of course that won't work, because a joint is not a measurable object. Not sure what your second object is (Bill_leftHand_tip) though.

Additionally, you might want to try the ZeroMQ-based remote API instead, which is much easier to use, and gives you access to all of the CoppeliaSim regular API.

Cheers

ask4jubad
Posts: 5
Joined: 21 Sep 2021, 07:46

Re: Python Remote Api - Error with simxCheckDistance call

Post by ask4jubad »

Thanks for feedback.

I have selected a dummy object that is measurable on the robot side and it works.

However, for the ZeroMQ api that you recommended, how do I ensure that it running in my simulation window?

Regards

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

Re: Python Remote Api - Error with simxCheckDistance call

Post by coppelia »

Not sure what you mean... the Zmq remote APi add-on is the server side (loaded by coppeliaSim automatically at start-up, if placed in the same folder), and your python client is simply your python script in the zmqRemoteApi/clients/python folder. On the client side all you have to additionally do, is install zmq and cbor via:

Code: Select all

$ python3 -m pip install pyzmq
$ python3 -m pip install cbor
Cheers

Post Reply