CliffSensor
robodyno.components.can_bus.cliff_sensor
Cliff sensor driver
The cliff sensor can be used to get the distance.
示例:
>>> 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
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
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.
引发:
| 类型 | 描述 |
|---|---|
ValueError
|
If the device id is invalid. |
config_can_bus(new_id=None, bitrate=1000000)
Configures the can bus.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
new_id
|
int
|
New device id. |
None
|
bitrate
|
int
|
Can bus bitrate. |
1000000
|
引发:
| 类型 | 描述 |
|---|---|
ValueError
|
If the new id is invalid. |
get_distance(timeout=0.02)
Reads the distance.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
timeout
|
float
|
Timeout in seconds. |
0.02
|
返回:
| 类型 | 描述 |
|---|---|
float | None
|
The distance value read by the cliff sensor. Returns None if the read times out. Unit: centimeters. |