CliffSensor
robodyno.components.can_bus.cliff_sensor
Cliff sensor driver
The cliff sensor can be used to get the distance.
Examples:
>>> from robodyno.components import CliffSensor
>>> from robodyno.interfaces import CanBus
>>> can = CanBus()
>>> cliff_sensor = CliffSensor(can)
>>> print(cliff_sensor.get_distance())
32
CliffSensor
Bases: CanBusDevice
Cliff sensor driver
Attributes:
Name | Type | Description |
---|---|---|
id(int) |
Device id. |
|
type(Model) |
Device type. |
|
fw_ver(float) |
Firmware version. |
__init__(can, id_=48)
Initializes the cliff 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.02)
Reads the distance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
float
|
Timeout in seconds. |
0.02
|
Returns:
Type | Description |
---|---|
float | None
|
The distance value read by the cliff sensor. Returns None if the read times out. Unit: centimeters. |