Skip to content

Commit 5fd524a

Browse files
Merge pull request #577 from srobo/chore/fix-simulator-ultrasound-range
Fix ultrasound units
2 parents 25d0460 + ec162bc commit 5fd524a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

simulator/simulated_robot.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,17 @@ Analogous to [ultrasound sensors](https://robocraze.com/blogs/post/what-is-ultra
8686
| A4 | Front | `INPUT` |
8787
| A5 | Back | `INPUT` |
8888

89-
These are shown as blue boards with silver transceivers on the robot. They can see in a narrow cone up to a maximum of about 5m away.
89+
These are shown as blue boards with silver transceivers on the robot. They can see in a narrow cone up to a maximum of about 2m away.
9090
Since these sensors rely on echoes being reflected back from objects, if the angle of incidence between the sensor's pulse and the contacted surface exceeds 22.5 degrees then the sensor will be unable to detect the object.
9191

92-
You can access the ultrasound sensors using `robot.arduino.pins[AX]`, where '`AX`' is between `A0` and `A5`. Make sure you set the pin mode to `INPUT`. The `analog_read` method will return the distance in metres. You can read more in the [arduino programming docs page][arduino-programming].
92+
You can access the ultrasound sensors using `robot.arduino.pins[AX]`, where '`AX`' is between `A0` and `A5`. Make sure you set the pin mode to `INPUT`. The `analog_read` method will return a voltage (0-5V) proportional to the distance. You can read more in the [arduino programming docs page][arduino-programming].
93+
94+
```python
95+
reading = R.arduino.pins[A5].analog_read()
96+
# convert reading from volts to meters
97+
measurement = reading / (5/2)
98+
print(f"Rear ultrasound distance {measurement:.2f} meters")
99+
```
93100

94101
### LEDs
95102

0 commit comments

Comments
 (0)