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()
MotorRegulatorgetTachoCount in interface MotorRegulatorpublic void resetTachoCount()
MotorRegulatorresetTachoCount in interface MotorRegulatorpublic boolean isMoving()
MotorRegulatorisMoving in interface MotorRegulatorpublic float getCurrentVelocity()
MotorRegulatorgetCurrentVelocity in interface MotorRegulatorpublic void setStallThreshold(int error,
int time)
MotorRegulatorsetStallThreshold in interface MotorRegulatorprotected void updateState(int velocity,
boolean hold,
boolean stalled)
velocity - hold - stalled - public void addListener(RegulatedMotor motor, RegulatedMotorListener listener)
MotorRegulatoraddListener in interface MotorRegulatorpublic RegulatedMotorListener removeListener()
removeListener in interface MotorRegulatorpublic void setControlParamaters(int typ,
float moveP,
float moveI,
float moveD,
float holdP,
float holdI,
float holdD,
int offset)
MotorRegulatorsetControlParamaters in interface MotorRegulatortyp - 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()
MotorRegulatorwaitComplete in interface MotorRegulatorpublic int getLimitAngle()
MotorRegulatorgetLimitAngle in interface MotorRegulatorpublic boolean isStalled()
MotorRegulatorisStalled in interface MotorRegulatorprotected void reset()
public float getPosition()
getPosition in interface MotorRegulatorpublic void newMove(float speed,
int acceleration,
int limit,
boolean hold,
boolean waitComplete)
newMove in interface MotorRegulatorspeed - acceleration - limit - hold - waitComplete - public void adjustSpeed(float newSpeed)
adjustSpeed in interface MotorRegulatornewSpeed - new target speed.public void adjustAcceleration(int newAcc)
adjustAcceleration in interface MotorRegulatornewAcc - public void startSynchronization()
MotorRegulatorstartSynchronization in interface MotorRegulatorpublic void endSynchronization(boolean b)
MotorRegulatorendSynchronization in interface MotorRegulatorpublic void synchronizeWith(MotorRegulator[] rl)
MotorRegulatorsynchronizeWith in interface MotorRegulatorrl - an array of motors to synchronize with.