Calculating distance and printing it

Typically: "How do I... ", "How can I... " questions
Post Reply
cena
Posts: 7
Joined: 14 Jun 2014, 11:08

Calculating distance and printing it

Post by cena » 10 Jul 2014, 10:55

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

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

Re: Calculating distance and printing it

Post by coppelia » 10 Jul 2014, 21:04

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

rohanp
Posts: 3
Joined: 09 Feb 2018, 14:43

Re: Calculating distance and printing it

Post by rohanp » 14 Feb 2018, 08:48

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?

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

Re: Calculating distance and printing it

Post by coppelia » 15 Feb 2018, 09:09

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

Sagar Kalburgi
Posts: 1
Joined: 18 Feb 2018, 15:00

Re: Calculating distance and printing it

Post by Sagar Kalburgi » 02 Apr 2018, 05:19

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.

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

Re: Calculating distance and printing it

Post by coppelia » 03 Apr 2018, 06:53

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

Post Reply