PwmDriver
robodyno.components.can_bus.pwm_driver
Pwm develop board driver.
The pwm develop board has a 8-bit pwm output or servo output on the signal pin. It can be used to control the servo or pwm device.
Examples:
>>> from robodyno.components import PwmDriver
>>> from robodyno.interfaces import CanBus
>>> can = CanBus()
>>> pwm = PwmDriver(can)
>>> pwm.set_pwm(100)
>>> pwm.set_servo(100)
>>> can.disconnect()
PwmDriver
Bases: CanBusDevice
Pwm develop board driver.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
id |
int
|
Device id. |
type |
Model
|
Device type. |
fw_ver |
float
|
Firmware version. |
__init__(can, id_=33)
Initializes the pwm develop board.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
can
|
CanBus
|
Can bus instance. |
必需 |
id_
|
int
|
Device id. |
33
|
引发:
| 类型 | 描述 |
|---|---|
ValueError
|
If the device is not a pwm develop board. |
pwm
property
Gets the pwm value.
返回:
| 类型 | 描述 |
|---|---|
int
|
8-bit pwm value. The range is 0-255. None if the device is in servo mode. |
servo_pos
property
Gets the servo position.
返回:
| 类型 | 描述 |
|---|---|
int
|
Position value. The range is 0-255 (0-180 degree). None if the device is in pwm mode. |
config_can_bus(new_id)
Configures the can bus.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
new_id
|
int
|
New device id. |
必需 |
引发:
| 类型 | 描述 |
|---|---|
ValueError
|
If the new id is not in the range of 0x01-0x3f. |
on()
Turns on the pwm output.
off()
Turns off the pwm output.
set_servo(pos)
Sets the servo position.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
pos
|
int
|
Position value. The range is 0-255 (0-180 degree). |
必需 |
引发:
| 类型 | 描述 |
|---|---|
ValueError
|
If the position is not in the range of 0-255. |
set_pwm(pwm)
Sets the pwm value.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
pwm
|
int
|
8-bit pwm value. The range is 0-255. |
必需 |
引发:
| 类型 | 描述 |
|---|---|
ValueError
|
If the pwm value is not in the range of 0-255. |