NAOqi Sensors - Overview | API
See also
ALsonar module retrieves ultrasonic sensor value from ALMemory, process it and raises events according to the situation.
In order to save battery power, ultrasonic sensors are not activated by default.
There are 4 different ultrasonic events: SonarLeftDetected, SonarRightDetected, SonarLeftNothingDetected, SonarRightNothingDetected.
Case | Raised event | Description |
---|---|---|
SonarLeftDetected | There is something in front of NAO (left side) at less than 0.5m. This means that NAO can’t go forward and has to stop and turn right to avoid the obstacle. | |
SonarRightDetected | There is something in front of NAO (right side) at less than 0.5m. This means that NAO can’t go forward and has to stop and turn left to avoid the obstacle. | |
SonarLeftNothingDetected | There is nothing in front of NAO nor on his left side, this means NAO can go forward or turn left. An obstacle is present on the right side at less than 0.5m but it is not a problem if NAO goes forward. | |
SonarRightNothingDetected | There is nothing in front of NAO nor on his right side, this means NAO can go forward or turn left. An obstacle is present on the left side at less than 0.5m but it is not a problem if NAO goes forward. | |
SonarLeftNothingDetected and SonarRightNothingDetected | There is no obstacle, both SonarLeftNothingDetected and SonarRightNothingDetected are raised at the same time. |
Note
If you want to perform your own detection with sonars you can also retrieve ultrasonic sensor values from ALMemory (find corresponding keys in Accessing value using ALMemory keys). If you are not familiar with this consult getData function of ALMemory API.
The obstacle detection threshold is 0.5m (it is a software threshold). Detected obstacles are seen only if the distance is less than this threshold.
Only one sonar event is raised at the same time. This is because at a given time we use both left and right ultrasonic sensor data, to determine in which situation we are so as to raise the corresponding event.
Starting ultrasonic hardware
Ultrasonic sensor hardware is not started by default. To start it, subscribe to ALSonar module (ALSonarProxy::subscribe()). Doing so starts the ultrasonic sensor hardware automatically.
Checking the hardware
To check that your ultrasonic sensor works properly you can start Choregraphe and launch a Sonar box. First ensure that you are connected to your real NAO hardware. Then drag and drop a sonar box in your diagram and run the behavior.
Observing the signal
When a Sonar box is launched, you can watch the signal of the ultrasonic sensor with Monitor.
Stopping ultrasonic hardware
To stop it, unsubscribe from the ALSonar module (ALSonarProxy::unsubscribe()). If there are multiple subscribers, the ultrasonic sensor hardware will remain active as long as remains at least one subscriber.
# -*- encoding: UTF-8 -*-
# Before running this command please check your PYTHONPATH is set correctly to the folder of your pynaoqi sdk.
from naoqi import ALProxy
# Set the IP address of your NAO.
ip = "10.0.252.97"
# Connect to ALSonar module.
sonarProxy = ALProxy("ALSonar", ip, 9559)
# Subscribe to sonars, this will launch sonars (at hardware level) and start data acquisition.
sonarProxy.subscribe("myApplication")
#Now you can retrieve sonar data from ALMemory.
memoryProxy = ALProxy("ALMemory", ip, 9559)
# Get sonar left first echo (distance in meters to the first obstacle).
memoryProxy.getData("Device/SubDeviceList/US/Left/Sensor/Value")
# Same thing for right.
memoryProxy.getData("Device/SubDeviceList/US/Right/Sensor/Value")
# Please read Sonar ALMemory keys section if you want to know the other values you can get.
You can use ultrasonic sensor to perform obstacle detection.
How can I start and stop my ultrasonic senors
Please see Getting started section.
When connected to choregraphe, sonar box returns only left or nothing
Check that you are connected to your real NAO and not to the local NAOqi provided by Choregraphe.