## Calculating distance and printing it

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

### Calculating distance and printing it

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
Posts: 7594
Joined: 14 Dec 2012, 00:25

### Re: Calculating distance and printing it

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')
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

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
Posts: 7594
Joined: 14 Dec 2012, 00:25

### Re: Calculating distance and printing it

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

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