|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectshady.common.ShadyCommon
shady.sim.ShadySim
public class ShadySim
Shady simulator implementation.
Copyright (C) 2006 Marsette A. Vona, III
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
| Nested Class Summary | |
|---|---|
protected class |
ShadySim.BarrelMotion
Specializes ShadySim.Motion for a barrel motion. |
protected class |
ShadySim.GripperMotion
A motion that moves a gripper. |
protected class |
ShadySim.Motion
Generic code for performing a motion in ShadySim.Motion.step()s. |
protected class |
ShadySim.RotateMotion
A motion that rotates a barrel. |
protected class |
ShadySim.ShadeMotion
A motion that rotates the shade. |
protected class |
ShadySim.SimultaneousMotion
A simultaneous barrel rotation and shade motion. |
| Field Summary | |
|---|---|
private static java.lang.String |
cvsid
CVS id. |
protected boolean |
discreteMode
Whether we're in discrete mode. |
static double |
SLEEP_GRANULARITY
Minimum time to sleep the sim thread in wall-clock seconds. |
static double |
STEP_TIME
Simulated motion step time, in sim seconds. |
| Fields inherited from interface shady.common.ShadyCommonAPI |
|---|
CLOSED_STATE, COLLISION, ESTOP, GRIPPER_CLOSE, GRIPPER_OPEN, GRIPPER_OPERATION_TARGET_STATE, IMPLEMENTATION_FAULT, LEFT, LOW_BATTERY, MOTION_LIMIT, OPEN_STATE, OVER_CURRENT, OVER_TEMP, RIGHT, TILT, TIMEOUT, UNALIGNED, UNKNOWN, WOULD_COLLIDE, WOULD_DUEL, WOULD_MOTION_LIMIT, WOULD_TILT |
| Constructor Summary | |
|---|---|
ShadySim()
Create a ShadySim with no pose. |
|
ShadySim(ShadyPose pose)
Create a ShadySim with a given pose. |
|
| Method Summary | |
|---|---|
void |
chargeBattery(double newBatteryLevel)
Simulate charging the battery. |
protected double |
doSimultaneousMotion(double leftBarrelDT,
double rightBarrelDT,
double shadeDT)
Implementation of ShadyCommon.simultaneousMotion(double, double, double). |
double |
getAccel()
Get the simulation time acceleration factor. |
boolean |
getDiscreteMode()
Check whether this ShadySim is in discrete mode. |
protected double |
getGripperTime(double ds)
Get the time in seconds it will take to actuate a gripper. |
protected double |
getRotateBarrelTime(double dt)
Get the time in seconds it will take to rotate a barrel differential amount dt in degrees at ShadyCommon.NOMINAL_BARREL_ROTATION_SPEED. |
protected double |
getRotateShadeTime(double dt)
Get the time in seconds it will take to rotate the shade differential amount dt in degrees at ShadyCommon.NOMINAL_SHADE_ROTATION_SPEED. |
double |
getShadyTime()
Get the acceltime in accelseconds relative to an arbitrary epoch. |
protected vona.time.Clock |
makeClock()
Instantiate ShadyCommon.clock. |
protected ShadySim.GripperMotion |
makeGripperMotion(int barrel,
double ds)
Make a GripperMotion for reallySetGripper(int, double). |
protected ShadySim.RotateMotion |
makeRotateMotion(int barrel,
double dt)
Make a RotateMotion for reallyRotateBarrel(int, double). |
void |
pause()
Pause this ShadySim. |
protected double |
reallyRotateBarrel(int barrel,
double dt)
Really rotates the barrel. |
protected double |
reallyRotateShade(double dt)
Really rotates the shade. |
protected double |
reallySetGripper(int barrel,
double targetState)
Really actuates the gripper. |
void |
rechargeBattery()
Convenience method to fully ShadySimAPI.chargeBattery(double). |
int |
reset()
Attempt to reset the mechanism. |
protected void |
rotateBarrel(int barrel,
double dt,
double[] resource)
Second part of ShadyCommon.rotateBarrel(int, double). |
int |
rotateShade(double dt)
Incrementally rotate the shade. |
void |
setAccel(double accel)
Set the simulation time acceleration factor. |
void |
setDiscreteMode(boolean discreteMode)
Set whether this ShadySim is in discrete mode. |
protected void |
setGripper(int barrel,
double targetState,
double[] resource)
Second part of ShadyCommon.setGripper(int, int). |
void |
shadySleep(double seconds)
Sleep the current thread for the requested number of accelseconds. |
void |
stop(boolean estop)
Stop all ongoing motion. |
void |
unPause()
Un- ShadySimAPI.pause() this ShadySim. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private static final java.lang.String cvsid
CVS id.
public static final double STEP_TIME
Simulated motion step time, in sim seconds.
public static final double SLEEP_GRANULARITY
Minimum time to sleep the sim thread in wall-clock seconds.
protected boolean discreteMode
Whether we're in discrete mode.
See the class header doc for a description of discrete mode.
| Constructor Detail |
|---|
public ShadySim(ShadyPose pose)
Create a ShadySim with a given pose.
pose - the posepublic ShadySim()
Create a ShadySim with no pose.
| Method Detail |
|---|
public int reset()
Attempt to reset the mechanism.
A call to this method will not change the mechanism state, however if
any motion was ongoing it will be stopped and an ShadyCommonAPI.ESTOP fault will
occur.
The current barrel angles and gripper states are be re-determined.
Any current fault condition will be cleared. However, implementations may subsequently check for any ongoing fault. The first such fault that is found is then set as the current fault and the return value from this method is false.
This is intended to be a relatively lightweight operation to clear a fault condition. I.e. is does not necessarily entail a reboot.
This method does not ShadyCommonAPI.resetAccounting().
Default impl clears and
ShadyCommon.state.faultstate.faultDetails, then ShadyCommonAPI.stop(boolean), ShadyCommon.reestablishState() and ShadyCommon.checkFault().
This impl clears thread interrupt state, then chains to super.
reset in interface ShadyCommonAPIreset in class ShadyCommonpublic void stop(boolean estop)
Stop all ongoing motion.
Has no effect if there is no ongoing motion.
Sets an ShadyCommonAPI.ESTOP fault iff estop is true, there was
ongoing motion, and there was no prior fault condition.
This impl sets and ShadyCommonAPI.ESTOP fault only if there are any
, and always sets
ShadyCommon.state.numActiveActuatorsnumActiveActuators to zero.
stop in interface ShadyCommonAPIestop - whether to enable ESTOP fault generationprotected double getRotateBarrelTime(double dt)
Get the time in seconds it will take to rotate a barrel differential
amount dt in degrees at ShadyCommon.NOMINAL_BARREL_ROTATION_SPEED.
dt - the differential rotation in degrees
dt degrees at nominal speed
protected double reallyRotateBarrel(int barrel,
double dt)
Really rotates the barrel.
Implementations should have this method do whatever is necessary to
rotate the barrel the requested amount, updating ShadyCommon.state
appropriately. Motion limit checking will have already been performed
(based on the prior ShadyCommon.state) in ShadyCommon.rotateBarrel(int, double).
All accounting info management is also done in
rotateBarrel(). This method must simply
state with the current barrel angle as often as
possible as the rotation occurs, and always before returnstate.fault and state.faultDetails if
a fault is detectedArguments are the same as ShadyCommon.rotateBarrel(int, double).
This impl blocks for abs(dt)/ while moving the requested barrel
at intervals of ShadyCommon.NOMINAL_BARREL_ROTATION_SPEEDSTEP_TIME.
is increased by ShadyCommon.state.currentPowerShadyCommon.NOMINAL_BARREL_ROTATE_POWER and is incremented during the motion.ShadyCommon.state.numActiveActuators
is checked at each step,
and if it's zero the motion is aborted.ShadyCommon.state.numActiveActuators
reallyRotateBarrel in class ShadyCommon
protected ShadySim.RotateMotion makeRotateMotion(int barrel,
double dt)
Make a RotateMotion for reallyRotateBarrel(int, double).
This is a hook so subclasses can also subclass RotateMotion.
Params same as the ShadySim.RotateMotion constr.
barrel and
dt
protected void rotateBarrel(int barrel,
double dt,
double[] resource)
Second part of ShadyCommon.rotateBarrel(int, double).
Short circuits if dt epsilon equals 0.0, otherwise
executes motion and collects resource usage.
Defaults to super (which calls reallyRotateBarrel(int, double)) iff we're
not in discrete mode or if motion accumulation is enabled.
See the class header doc for a description of discrete mode.
If we are in discrete mode, the motion is executed as a single discrete step. Energy is not tallied (set to -1.0) and the expired time is 0.0.
rotateBarrel in class ShadyCommonbarrel - same as for ShadyCommon.rotateBarrel(int, double)dt - same as for ShadyCommon.rotateBarrel(int, double)resource - a two-element array into which ShadyCommon.ENERGY and ShadyCommon.TIME are recorded on returnprotected double getGripperTime(double ds)
Get the time in seconds it will take to actuate a gripper.
ds - the differential change in state of the gripper
ds
protected double reallySetGripper(int barrel,
double targetState)
Really actuates the gripper.
Implementations should have this method do whatever is necessary to
actuate the requested gripper, updating ShadyCommon.state appropriately.
Checking if the gripper is already closed/open would have already happened
in ShadyCommon.setGripper(int, int). All accounting info management is also
done in setGripper(). This method must simply
state with the current gripper state as often as
possible as the motion occurs, and always before returnstate.fault and state.faultDetails if
a fault is detectedThis impl blocks for {CLOSE/OPEN}_TIME while moving the
requested paddles at intervals of STEP_TIME.
is increased by
ShadyCommon.state.currentPower{CLOSE/OPEN}_POWER and is incremented during the motion.ShadyCommon.state.numActiveActuators
is checked at each step,
and if it's zero the motion is aborted.ShadyCommon.state.numActiveActuators
reallySetGripper in class ShadyCommonbarrel - the barrel containing the gripper to actuatetargetState - state the target state of the gripper
protected ShadySim.GripperMotion makeGripperMotion(int barrel,
double ds)
Make a GripperMotion for reallySetGripper(int, double).
This is a hook so subclasses can also subclass GripperMotion.
Params same as the ShadySim.GripperMotion constr.
barrel and
ds
protected void setGripper(int barrel,
double targetState,
double[] resource)
Second part of ShadyCommon.setGripper(int, int).
Executes motion and collects resource usage.
Defaults to super iff we're not in discrete mode, which calls reallySetGripper(int, double).
See the class header doc for a description of discrete mode.
If we are in discrete mode, the motion is executed as a single discrete step. Energy is not tallied (set to -1.0) and the expired time is 0.0.
setGripper in class ShadyCommonbarrel - same as for ShadyCommon.setGripper(int, int)targetState - target gripper stateresource - a two-element array into which ShadyCommon.ENERGY and ShadyCommon.TIME are recorded on returnpublic int rotateShade(double dt)
Incrementally rotate the shade.
This impl chains to ShadyCommon.reallyRotateShade(double) unless there is a fault
or motion accumulation is turned on.
Defaults to super (which calls reallySetGripper(int, double)) iff we're not
in discrete mode or motion accumulation is enabled.
See the class header doc for a description of discrete mode.
If we are in discrete mode, the motion is executed as a single discrete
step. Otherwise, makes and executes a ShadySim.ShadeMotion.
rotateShade in interface ShadyCommonAPIrotateShade in class ShadyCommondt - a positive or negative real number giving the incremental
rotation in degreesprotected double reallyRotateShade(double dt)
Really rotates the shade.
Implementations should have this method do whatever is necessary to
rotate the shade the requested amount, updating ShadyCommon.state
appropriately. This method must simply
state with the current shade angle as often as
possible as the rotation occurs, and always before returnstate.fault and state.faultDetails if
a fault is detectedArguments are the same as ShadyCommon.rotateShade(double).
This impl blocks for the appropriate time while moving the shade at
intervals of STEP_TIME.
is increased by 0 and
ShadyCommon.state.currentPower is incremented during the
motion.ShadyCommon.state.numActiveActuators
is checked at each step,
and if it's zero the motion is aborted.ShadyCommon.state.numActiveActuators
reallyRotateShade in class ShadyCommonprotected double getRotateShadeTime(double dt)
Get the time in seconds it will take to rotate the shade differential
amount dt in degrees at ShadyCommon.NOMINAL_SHADE_ROTATION_SPEED.
dt - the differential rotation in degrees
dt degrees at nominal speed
protected double doSimultaneousMotion(double leftBarrelDT,
double rightBarrelDT,
double shadeDT)
Implementation of ShadyCommon.simultaneousMotion(double, double, double).
doSimultaneousMotion in class ShadyCommonpublic void setDiscreteMode(boolean discreteMode)
Set whether this ShadySim is in discrete mode.
See the class header doc for a description of discrete mode.
setDiscreteMode in interface ShadySimAPIdiscreteMode - true iff this ShadySim should be in discrete modepublic boolean getDiscreteMode()
Check whether this ShadySim is in discrete mode.
See the class header doc for a description of discrete mode.
getDiscreteMode in interface ShadySimAPIpublic void rechargeBattery()
Convenience method to fully ShadySimAPI.chargeBattery(double).
rechargeBattery in interface ShadySimAPIpublic void chargeBattery(double newBatteryLevel)
Simulate charging the battery.
This impl sets to
ShadyCommon.accountingInfo.currentBatteryEnergynewBatteryLevel.
chargeBattery in interface ShadySimAPInewBatteryLevel - the new battery level, in Joulespublic void setAccel(double accel)
Set the simulation time acceleration factor.
A factor of 2.0 means the simulation runs twice as fast as reality would.
setAccel in interface ShadySimAPIaccel - the simulation time acceleration factorpublic double getAccel()
Get the simulation time acceleration factor.
getAccel in interface ShadySimAPIpublic double getShadyTime()
Get the acceltime in accelseconds relative to an arbitrary epoch.
getShadyTime in interface ShadySimAPI
public void shadySleep(double seconds)
throws java.lang.InterruptedException
Sleep the current thread for the requested number of accelseconds.
shadySleep in interface ShadySimAPIseconds - how long to sleep in accelseconds, non-negative
java.lang.InterruptedExceptionpublic void pause()
Pause this ShadySim.
This ShadySim will act like time has stopped until it is ShadySimAPI.unPause()d. Any ongoing non-discrete motions or ShadySimAPI.shadySleep(double)s will
stop, and the threads that were blocked for them will remain blocked. Any
future non-discrete motions or ShadySimAPI.shadySleep(double)s will not start and the
calling threads will block until the pause is removed and the motion
completes.
pause in interface ShadySimAPIpublic void unPause()
Un-ShadySimAPI.pause() this ShadySim.
unPause in interface ShadySimAPIprotected vona.time.Clock makeClock()
Instantiate ShadyCommon.clock.
This is a hook to allow subclasses to implement the clock differently.
This impl just returns a new Clock.
This impl returns a new SuperClock.
makeClock in class ShadyCommon
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||