public class JavaMotorRegulator extends java.lang.Object implements MotorRegulator
Modifier and Type | Class and Description |
---|---|
protected static class |
JavaMotorRegulator.Controller
This class provides a single thread that drives all of the motor regulation
process.
|
Modifier and Type | Field and Description |
---|---|
protected static JavaMotorRegulator.Controller |
cont |
int |
power |
protected int |
stallLimit |
protected int |
stallTime |
protected TachoMotorPort |
tachoPort |
NO_LIMIT
Constructor and Description |
---|
JavaMotorRegulator(TachoMotorPort p) |
Modifier and Type | Method and Description |
---|---|
void |
addListener(RegulatedMotor motor,
RegulatedMotorListener listener)
Add a motor listener.
|
void |
adjustAcceleration(int newAcc)
The target acceleration has been changed.
|
void |
adjustSpeed(float newSpeed)
The target speed has been changed.
|
void |
endSynchronization(boolean b)
Complete a set of synchronized motor operations.
|
float |
getCurrentVelocity()
Return the current velocity (in degrees/second) that the motor is currently
running at.
|
int |
getLimitAngle()
Return the angle that this Motor is rotating to.
|
float |
getPosition()
return the regulations models current position.
|
int |
getTachoCount()
Get the current hardware tachometer reading for the motor,
|
boolean |
isMoving()
Return true if the motor is currently active
|
boolean |
isStalled()
Return true if the motor is currently stalled.
|
void |
newMove(float speed,
int acceleration,
int limit,
boolean hold,
boolean waitComplete)
Initiate a new move and optionally wait for it to complete.
|
RegulatedMotorListener |
removeListener() |
protected void |
reset()
Reset the tachometer readings
|
void |
resetTachoCount()
Reset the tachometer base value, after this call the tachometer will return
zero for the current position.
|
void |
setControlParamaters(int typ,
float moveP,
float moveI,
float moveD,
float holdP,
float holdI,
float holdD,
int offset)
Set the motion control parameters used by the regulator.
|
void |
setStallThreshold(int error,
int time)
Set the stall detection parameters.
|
void |
startSynchronization()
Begin a set of synchronized motor operations
|
void |
synchronizeWith(MotorRegulator[] rl)
Specify a set of motors that should be kept in synchronization with this one.
|
protected void |
updateState(int velocity,
boolean hold,
boolean stalled)
Update the internal state of the motor.
|
void |
waitComplete()
Wait until the current movement operation is complete (this can include
the motor stalling).
|
public int power
protected int stallLimit
protected int stallTime
protected TachoMotorPort tachoPort
protected static final JavaMotorRegulator.Controller cont
public JavaMotorRegulator(TachoMotorPort p)
public int getTachoCount()
MotorRegulator
getTachoCount
in interface MotorRegulator
public void resetTachoCount()
MotorRegulator
resetTachoCount
in interface MotorRegulator
public boolean isMoving()
MotorRegulator
isMoving
in interface MotorRegulator
public float getCurrentVelocity()
MotorRegulator
getCurrentVelocity
in interface MotorRegulator
public void setStallThreshold(int error, int time)
MotorRegulator
setStallThreshold
in interface MotorRegulator
protected void updateState(int velocity, boolean hold, boolean stalled)
velocity
- hold
- stalled
- public void addListener(RegulatedMotor motor, RegulatedMotorListener listener)
MotorRegulator
addListener
in interface MotorRegulator
public RegulatedMotorListener removeListener()
removeListener
in interface MotorRegulator
public void setControlParamaters(int typ, float moveP, float moveI, float moveD, float holdP, float holdI, float holdD, int offset)
MotorRegulator
setControlParamaters
in interface MotorRegulator
typ
- The type of motormoveP
- The Proportional control value used while movingmoveI
- The integral control parameter used while movingmoveD
- The differential control parameter used while movingholdP
- The Proportional control value used while holding positionholdI
- The integral control value used while holding positionholdD
- The differential control value used while holding positionoffset
- Motor PWM offset value range 0-10000.public void waitComplete()
MotorRegulator
waitComplete
in interface MotorRegulator
public int getLimitAngle()
MotorRegulator
getLimitAngle
in interface MotorRegulator
public boolean isStalled()
MotorRegulator
isStalled
in interface MotorRegulator
protected void reset()
public float getPosition()
getPosition
in interface MotorRegulator
public void newMove(float speed, int acceleration, int limit, boolean hold, boolean waitComplete)
newMove
in interface MotorRegulator
speed
- acceleration
- limit
- hold
- waitComplete
- public void adjustSpeed(float newSpeed)
adjustSpeed
in interface MotorRegulator
newSpeed
- new target speed.public void adjustAcceleration(int newAcc)
adjustAcceleration
in interface MotorRegulator
newAcc
- public void startSynchronization()
MotorRegulator
startSynchronization
in interface MotorRegulator
public void endSynchronization(boolean b)
MotorRegulator
endSynchronization
in interface MotorRegulator
public void synchronizeWith(MotorRegulator[] rl)
MotorRegulator
synchronizeWith
in interface MotorRegulator
rl
- an array of motors to synchronize with.