UltrasonicSensor
robodyno.components.can_bus.ultrasonic_sensor
Ultrasonic sensor driver
The Ultrasonic sensor can be used to get the distance.
Examples:
>>> from robodyno.components import UltrasonicSensor
>>> from robodyno.interfaces import CanBus
>>> can = CanBus()
>>> ultrasonic_sensor = UltrasonicSensor(can)
>>> print(ultrasonic_sensor.get_distance())
57.646400451660156
UltrasonicSensor
Bases: CanBusDevice
Ultrasonic sensor driver
Attributes:
Name | Type | Description |
---|---|---|
id(int) |
Device id. |
|
type(Model) |
Device type. |
|
fw_ver(float) |
Firmware version. |
__init__(can, id_=53)
Initializes the ultrasonic sensor driver. Args: can(CanBus):Can bus instance. id_(int):Device id.
Raises:
Type | Description |
---|---|
ValueError
|
If the device id is invalid. |
config_can_bus(new_id=None, bitrate=1000000)
Configures the can bus.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_id |
int
|
New device id. |
None
|
bitrate |
int
|
Can bus bitrate. |
1000000
|
Raises:
Type | Description |
---|---|
ValueError
|
If the new id is invalid. |
get_distance(timeout=0.15)
Reads the distance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
float
|
Timeout in seconds. |
0.15
|
Returns:
Type | Description |
---|---|
float | 250.0
|
The distance value read by the ultrasonic sensor. Returns 250.0 if the read times out. Unit: centimeters. |