Package com.diozero.devices.motor
Class PwmMotor
- java.lang.Object
-
- com.diozero.devices.motor.MotorBase
-
- com.diozero.devices.motor.PwmMotor
-
- All Implemented Interfaces:
DeviceInterface
,FloatConsumer
,MotorInterface
,AutoCloseable
public class PwmMotor extends MotorBase
Generic bi-directional motor controlled by separate forward / backward PWM output GPIOs
-
-
Constructor Summary
Constructors Constructor Description PwmMotor(int forwardPwmGpio, int backwardPwmGpio)
PwmMotor(PwmOutputDeviceFactoryInterface deviceFactory, int forwardPwmGpio, int backwardPwmGpio)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
backward()
Backward at full speedvoid
backward(float speed)
void
close()
Close this devicevoid
forward()
Forward at full speedvoid
forward(float speed)
float
getValue()
Represents the speed of the motor as a floating point value between -1 (full speed backward) and 1 (full speed forward).boolean
isActive()
void
stop()
-
Methods inherited from class com.diozero.devices.motor.MotorBase
accept, addListener, removeListener, reverse, setValue, whenBackward, whenForward, whenStop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.diozero.api.function.FloatConsumer
andThen
-
-
-
-
Constructor Detail
-
PwmMotor
public PwmMotor(int forwardPwmGpio, int backwardPwmGpio) throws RuntimeIOException
- Throws:
RuntimeIOException
-
PwmMotor
public PwmMotor(PwmOutputDeviceFactoryInterface deviceFactory, int forwardPwmGpio, int backwardPwmGpio) throws RuntimeIOException
- Throws:
RuntimeIOException
-
-
Method Detail
-
close
public void close()
Description copied from interface:DeviceInterface
Close this device
-
forward
public void forward() throws RuntimeIOException
Forward at full speed- Throws:
RuntimeIOException
- if an I/O error occurs
-
forward
public void forward(float speed) throws RuntimeIOException
- Parameters:
speed
- Range 0..1- Throws:
RuntimeIOException
- if an I/O error occurs
-
backward
public void backward() throws RuntimeIOException
Backward at full speed- Throws:
RuntimeIOException
- if an I/O error occurs
-
backward
public void backward(float speed) throws RuntimeIOException
- Parameters:
speed
- Range 0..1- Throws:
RuntimeIOException
- if an I/O error occurs
-
stop
public void stop() throws RuntimeIOException
- Throws:
RuntimeIOException
-
getValue
public float getValue() throws RuntimeIOException
Represents the speed of the motor as a floating point value between -1 (full speed backward) and 1 (full speed forward).- Returns:
- current relative motor speed
- Throws:
RuntimeIOException
- if an I/O error occurs
-
isActive
public boolean isActive() throws RuntimeIOException
- Throws:
RuntimeIOException
-
-