Package com.diozero.devices.motor
Interface MotorInterface
-
- All Superinterfaces:
AutoCloseable
,DeviceInterface
- All Known Implementing Classes:
AnalogOutputMotor
,MotorBase
,PiconZeroMotor
,PwmMotor
,TB6612FNGMotor
public interface MotorInterface extends DeviceInterface
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
addListener(MotorEventListener listener)
default void
backward()
Backward at full speedvoid
backward(float speed)
Set the motor direction to backward at the given speed.default void
forward()
Forward at full speedvoid
forward(float speed)
Set the motor direction to forward at the given speed.float
getValue()
Get the relative output speed of the motor in the range -1..1boolean
isActive()
Is this motor currently active?void
removeListener(MotorEventListener listener)
default void
reverseDirection()
Reverse direction of the motorsdefault void
setValue(float value)
Set the relative speed of the motor as a floating point value between -1 (full speed backward) and 1 (full speed forward)void
stop()
Stop the motorvoid
whenBackward(Action action)
Perform the given action when the direction of the motor is changed to backwardsvoid
whenForward(Action action)
Perform the given action when the direction of the motor is changed to forwardsvoid
whenStop(Action action)
Perform the given action when the motor is stopped-
Methods inherited from interface com.diozero.api.DeviceInterface
close
-
-
-
-
Method Detail
-
forward
void forward(float speed) throws RuntimeIOException
Set the motor direction to forward at the given speed.- Parameters:
speed
- normalised speed value, range 0..1- Throws:
RuntimeIOException
- if an I/O error occurs
-
backward
void backward(float speed) throws RuntimeIOException
Set the motor direction to backward at the given speed.- Parameters:
speed
- normalised speed value, range 0..1- Throws:
RuntimeIOException
- if an I/O error occurs
-
forward
default void forward() throws RuntimeIOException
Forward at full speed- Throws:
RuntimeIOException
- if an I/O error occurs
-
backward
default void backward() throws RuntimeIOException
Backward at full speed- Throws:
RuntimeIOException
- if an I/O error occurs
-
stop
void stop() throws RuntimeIOException
Stop the motor- Throws:
RuntimeIOException
- if an I/O error occurs
-
reverseDirection
default void reverseDirection() throws RuntimeIOException
Reverse direction of the motors- Throws:
RuntimeIOException
- if an I/O error occurs
-
getValue
float getValue() throws RuntimeIOException
Get the relative output speed of the motor in the range -1..1- Returns:
- -1 for full reverse, 1 for full forward, 0 for stop
- Throws:
RuntimeIOException
- if an I/O error occurs
-
setValue
default void setValue(float value) throws RuntimeIOException
Set the relative speed of the motor as a floating point value between -1 (full speed backward) and 1 (full speed forward)- Parameters:
value
- Range -1..1. Positive numbers = forward, negative numbers = backward- Throws:
RuntimeIOException
- if an I/O error occurs
-
isActive
boolean isActive() throws RuntimeIOException
Is this motor currently active?- Returns:
- true if speed != 0
- Throws:
RuntimeIOException
- if an I/O error occurs
-
whenForward
void whenForward(Action action)
Perform the given action when the direction of the motor is changed to forwards- Parameters:
action
- action to perform
-
whenBackward
void whenBackward(Action action)
Perform the given action when the direction of the motor is changed to backwards- Parameters:
action
- action to perform
-
whenStop
void whenStop(Action action)
Perform the given action when the motor is stopped- Parameters:
action
- action to perform
-
addListener
void addListener(MotorEventListener listener)
-
removeListener
void removeListener(MotorEventListener listener)
-
-