new Motor(forward, backward, pwmopt)
- Source:
Represents a generic motor connected to a bi-directional motor driver circuit (i.e. an `H-bridge`_).
Attach an `H-bridge`_ motor controller to your Pi; connect a power source (e.g. a battery pack or the 5V pin) to the controller; connect the outputs
of the controller board to the two terminals of the motor; connect the inputs of the controller board to two GPIO pins.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
forward |
int | The GPIO pin that the forward input of the motor driver chip is connected to. | |
backward |
int | The GPIO pin that the backward input of the motor driver chip is connected to. | |
pwm |
boolean |
<optional> |
If ``true`` (the default), construct PWMOutputDevice instances for the motor controller pins, allowing both direction and variable speed control. If ``False``, construct DigitalOutputDevice instances, allowing only direction control. |
Throws:
GPIOPinMissing - If either Forward or Backward pin is not provided.
Extends
Methods
backward(speed)
- Source:
Drive the motor backwards.
Parameters:
Name | Type | Description |
---|---|---|
speed |
float | The speed at which the motor should turn. Can be any value between 0 (stopped) and the default 1 (maximum speed) if ``pwm`` was ``true`` when the class was constructed (and only 0 or 1 if not). |
Throws:
-
ValueError - When the speed is less than 0 or greater than 1.
-
ValueError - When the speed is between 0 and 1 on non-pwm motors.
close()
- Source:
- Overrides:
Close down the output devices and release the pins.
closed() → {boolean}
- Source:
Returns:
- If true then the forward and backward devices are undefined.
- Type
- boolean
forward(speed)
- Source:
Drive the motor forwards.
Parameters:
Name | Type | Description |
---|---|---|
speed |
float | The speed at which the motor should turn. Can be any value between 0 (stopped) and the default 1 (maximum speed) if ``pwm`` was ``true`` when the class was constructed (and only 0 or 1 if not). |
Throws:
-
ValueError - When the speed is less than 0 or greater than 1.
-
ValueError - When the speed is between 0 and 1 on non-pwm motors.
is_active() → {boolean}
- Source:
- Overrides:
Returns:
- If the motor is currently running then ``true`` otherwise ``false``.
- Type
- boolean
length() → {number}
- Source:
- Inherited From:
Returns:
- The number of subordinate devices.
- Type
- number
namedtuple() → {Array}
- Source:
- Inherited From:
Returns:
- An array of subordinate device names.
- Type
- Array
reverse()
- Source:
Reverse the current direction of the motor. If the motor is currently
idle this does nothing. Otherwise, the motor's direction will be
reversed at the current speed.
stop()
- Source:
Stop the motor.
value(valueopt) → {number}
- Source:
- Overrides:
Gets and Sets the motor speed between -1 (full backwards) and 1 (full forwards).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
int |
<optional> |
Motor speed. |
Throws:
OutputDeviceBadValue - If the value is defined but not between 1 and -1.
Returns:
- If value is undefined then returns the current speed.
- Type
- number