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.
Attributes:
Name | Type | Description |
---|---|---|
id |
int
|
Device id. |
type |
Model
|
Device type. |
fw_ver |
float
|
Firmware version. |
__init__(can, id_=33)
Initializes the pwm develop board.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
can |
CanBus
|
Can bus instance. |
required |
id_ |
int
|
Device id. |
33
|
Raises:
Type | Description |
---|---|
ValueError
|
If the device is not a pwm develop board. |
pwm: int
property
Gets the pwm value.
Returns:
Type | Description |
---|---|
int
|
8-bit pwm value. The range is 0-255. None if the device is in servo mode. |
servo_pos: int
property
Gets the servo position.
Returns:
Type | Description |
---|---|
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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_id |
int
|
New device id. |
required |
Raises:
Type | Description |
---|---|
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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pos |
int
|
Position value. The range is 0-255 (0-180 degree). |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the position is not in the range of 0-255. |
set_pwm(pwm)
Sets the pwm value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pwm |
int
|
8-bit pwm value. The range is 0-255. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the pwm value is not in the range of 0-255. |