Page 1 of 1

Calculating distance and printing it

Posted: 10 Jul 2014, 10:55
by cena
Hello,

Can anyone tell me what do i have to do if i want to calculate the distance between a moving robot for example the pioneer p3dx and any obstacle around it for example a wall. Also how can i see the value on the simulation ?

I am guessing i need to use proximity sensors or already built in sensors in the robots for example pioneer p3dx has 16 ultrasonic sensors i think. Also what do i need to add in the code ? Please help.

Kind regards
Maruf

Re: Calculating distance and printing it

Posted: 10 Jul 2014, 21:04
by coppelia
Hello Maruf,

to compute the minimum distance between your robot and the environment, use the distance calculation module. Once you have registered a distance object, you can access it, read it and print the distance from a child script with:

Code: Select all

handle=simGetDistanceHandle('myDistanceObjectName')
result,distance=simReadDistance(handle)
print(distance) -- prints the distance to the console
Of course you can do something similar with proximity sensors.

Cheers

Re: Calculating distance and printing it

Posted: 14 Feb 2018, 08:48
by rohanp
hello,
so i am trying to obtain similar data and i tried using the above steps as specified. But I am receiving error at the below statement (correct me if i am wrong):

DistHandle = simGetDistanceHandle('FrontLeg') --statement executed during initialization

What I think, the error is due to the use of wrong distanceobject name: 'FrontLeg'
In such a scenario, how to know which is the correct name and whether the name used is a legal name?

Re: Calculating distance and printing it

Posted: 15 Feb 2018, 09:09
by coppelia
Hello,

I see two potential problems:
  • either you have misspelled the object name (it is case sensitive)
  • either you have not understood how object handles are retrieved. Make sure to read this page
Cheers

Re: Calculating distance and printing it

Posted: 02 Apr 2018, 05:19
by Sagar Kalburgi
Hey, How do I calculate the distance that my bot has moved and display the distance so that I can use this data for future applications? I'm unable to get it done using simxGetDistanceHandle.

Re: Calculating distance and printing it

Posted: 03 Apr 2018, 06:53
by coppelia
You need to give us more information. Where are you trying to get and display the distance? In V-REP or in an external application?

Cheers