com.kuka.roboticsAPI.motionModel
Class AbstractMotionContainer

java.lang.Object
  extended by com.kuka.roboticsAPI.motionModel.AbstractMotionContainer
All Implemented Interfaces:
com.kuka.common.concurrent.IWaitToken, com.kuka.common.events.IEventListener, ICommandContainer, IContainerStateListener, IExecutionContainer, IMotionContainer
Direct Known Subclasses:
SunriseMotionContainer

public abstract class AbstractMotionContainer
extends Object
implements IMotionContainer, IContainerStateListener

Represents the state of a motion execution.

Not thread-safe for callers (and not intended to be). That means, this container should only be used by one thread.

This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

Constructor Summary
protected AbstractMotionContainer(MotionInstruction motionInstruction, boolean isSynchronous, ExecutorService eventWorker, ExecutorService cleanupWorker)
          Creates an instance of the class.
 
Method Summary
 void addContainerListener(IContainerStateListener listener)
          Adds the given listener to this container.
 void addTriggerConditionObserver(ConditionObserver obs, IMotion motion)
          Adds a condition observer for a trigger to the motion container.
 void append(IMotion motion)
          Appends a motion to the executing motions.
 void await()
          Blocks the calling thread until the container has finished it's execution.
 void await(long timeout, TimeUnit unit)
          Blocks the calling thread until the container has finished it's execution.
 void cancel()
          Cancels all motions in this container.
 void cleanTriggerObservers()
          Stops all eventually running trigger handler.
protected abstract  ICommandContainer createExecutionContainerInternal(IMotion motion, boolean isSynchronous)
          Inheriting classes should create the specific execution container here.
protected abstract  void executeAppendedMotion(ICommandContainer container)
          Implementing classes should send the appended motion container to execution.
protected  MotionBatch getBatch()
          Gets the motion batch if this container is created for a batch.
protected  com.kuka.common.params.IParameterSet getBatchParams()
          Gets the batch parameters if this container is created for a batch.
 MotionInstruction getCommand()
          Gets the command which was executed within this container.
 Collection<ICommandContainer> getCommandContainers()
          Debugging/test helper method: Returns the remaining execution containers.
 IMotion getCurrentMotion()
          Returns the motion command that is being currently executed.
 String getErrorMessage()
          Gets the error message for the container.
protected  ExecutorService getEventWorker()
          Gets the worker for container events.
 IFiredConditionInfo getFiredBreakConditionInfo()
          Gets the user condition that has fired and caused the stopping of this motion container.
 ICommandContainer getFirstCommandContainer()
          Debugging/test helper method: Returns the execution container for the first motion.
 IMotion getLastExecutedMotion()
          Returns the last executed motion command, if the container is already finished.
 ICommandRuntimeData getRuntimeData()
          Gets the custom runtime data associated with this container.
 ExecutionState getState()
          Gets the current ExecutionState of the container.
 boolean hasError()
          Checks if this container is in an error state.
 boolean hasFired(ICondition condition)
          Tests whether the given condition has fired for this container. this is equivalent to
{@code getFiredConditionInfo() !
 boolean isFinished()
          Checks if the container has finished it's execution either with a successful execution or with an error.
 boolean isSynchron()
          Checks if the motion in a container has been commanded synchronously.
protected abstract  void onContainerFinishedInternal(ICommandContainer cont, CountDownLatch handlerFinished)
          Called when the specified motion container is finished.
 void onStateChanged(IExecutionContainer cont, ExecutionState state)
          Called when the state of the container changed it's state.
 void removeContainerListener(IContainerStateListener listener)
          Removes the given container from this container.
protected  void silentCancel()
          Cancels the container and ignores errors.
 String toString()
           
 void validate()
          Validates this container and throws an exception if the container is invalid or was canceled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractMotionContainer

protected AbstractMotionContainer(MotionInstruction motionInstruction,
                                  boolean isSynchronous,
                                  ExecutorService eventWorker,
                                  ExecutorService cleanupWorker)
Creates an instance of the class.

Parameters:
motionInstruction - motion instruction for which the container is created.
isSynchronous - true if container should be executed synchronously.
eventWorker - worker for container events.
cleanupWorker - worker for cleanup actions.
Method Detail

toString

public final String toString()
Overrides:
toString in class Object

getEventWorker

protected ExecutorService getEventWorker()
Gets the worker for container events.

Returns:
the worker for container events.

hasFired

public boolean hasFired(ICondition condition)
Tests whether the given condition has fired for this container. this is equivalent to
getFiredConditionInfo() != null && getFiredConditionInfo().getFiredCondition() == condition

Specified by:
hasFired in interface IExecutionContainer
Parameters:
condition - the condition to test if it has fired.
Returns:
true if the condition has fired, false otherwise.
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

createExecutionContainerInternal

protected abstract ICommandContainer createExecutionContainerInternal(IMotion motion,
                                                                      boolean isSynchronous)
Inheriting classes should create the specific execution container here.

Parameters:
motion - motion for which container should be created.
isSynchronous - true if container should be executed synchronously.
Returns:
created execution container

await

public void await()
Blocks the calling thread until the container has finished it's execution.

Specified by:
await in interface com.kuka.common.concurrent.IWaitToken
Specified by:
await in interface IExecutionContainer
Throws:
com.kuka.common.ThreadInterruptedException - if the thread was interrupted while waiting

await

public void await(long timeout,
                  TimeUnit unit)
           throws TimeoutException
Blocks the calling thread until the container has finished it's execution. Only blocks the thread until the timeout is reached.

Specified by:
await in interface com.kuka.common.concurrent.IWaitToken
Specified by:
await in interface IExecutionContainer
Parameters:
timeout - The timeout.
unit - The unit of the timeout.
Throws:
com.kuka.common.ThreadInterruptedException - if the thread was interrupted while waiting
TimeoutException - the wait timed out

validate

public void validate()
Validates this container and throws an exception if the container is invalid or was canceled.

This method will block if error handler IErrorHandler.handleError(com.kuka.roboticsAPI.deviceModel.Device, IMotionContainer, List) is called until it is finished.

Specified by:
validate in interface IExecutionContainer
Throws:
CancelledException - if container command was canceled.
CommandInvalidException - if container command goes into invalid state (controller error).
ExternalStopException - if command was stopped because of some external signal.
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

isFinished

public boolean isFinished()
Checks if the container has finished it's execution either with a successful execution or with an error. If you like to see if an error occurred, you have to check the error message or call the method hasError.

Specified by:
isFinished in interface com.kuka.common.concurrent.IWaitToken
Specified by:
isFinished in interface IExecutionContainer
Returns:
True if the container execution is finished, otherwise false.

hasError

public boolean hasError()
Checks if this container is in an error state. An error state is Invalid or ExternalStop.

Specified by:
hasError in interface IExecutionContainer
Returns:
True if this container is in an error state.

getErrorMessage

public String getErrorMessage()
Gets the error message for the container.

Specified by:
getErrorMessage in interface IExecutionContainer
Returns:
The error message.

getFiredBreakConditionInfo

public IFiredConditionInfo getFiredBreakConditionInfo()
Gets the user condition that has fired and caused the stopping of this motion container. May be null if no user defined condition has fired.

HINT regarding motion batches: if the motion contained in this container is a motion batch, only the fired condition of the batch itself shows up in the info. The stop conditions that may have fired on the motions within the batch don't stop the batch. That's why in this case the fired condition info will be null.

Specified by:
getFiredBreakConditionInfo in interface IExecutionContainer
Returns:
The user defined condition that has fired and caused the stopping of this motion. May be null.

cancel

public void cancel()
Cancels all motions in this container.

Specified by:
cancel in interface IExecutionContainer
Specified by:
cancel in interface IMotionContainer
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

silentCancel

protected void silentCancel()
Cancels the container and ignores errors.


getCurrentMotion

public IMotion getCurrentMotion()
Returns the motion command that is being currently executed. This is the part of the robot trajectory where the robot is currently moving.

If the motion consists of segments (for example spline command), the currently executed segment of the spline will be returned.

Specified by:
getCurrentMotion in interface IMotionContainer
Returns:
the commanded motion that is currently being executed. For spline commands this refers to the currently executing segment.
This is the same object that has been passed when commanding the motion.
If execution is not started yet or has been finished, returns null.

getLastExecutedMotion

public IMotion getLastExecutedMotion()
Returns the last executed motion command, if the container is already finished.

If not, the motion that is currently being executed will be returned. This is the part of the robot trajectory where the robot is currently moving.
If the motion consists of segments (for example spline command), the currently executed segment of the spline will be returned.

Specified by:
getLastExecutedMotion in interface IMotionContainer
Returns:
the last executed motion or the commanded motion that is currently being executed. For spline commands this refers to the currently executing segment.
This is the same object that has been passed when commanding the motion.
If execution is not started yet, returns null.
When the container is finished (also because of break condition or error), returns the last executed motion.

append

public void append(IMotion motion)
Appends a motion to the executing motions. Can be called as long as the motions are executing. Appended motions can be blended, if applicable.

Specified by:
append in interface IMotionContainer
Parameters:
motion - the motion to be appended

executeAppendedMotion

protected abstract void executeAppendedMotion(ICommandContainer container)
Implementing classes should send the appended motion container to execution.

Parameters:
container - appended container to execute

getFirstCommandContainer

public ICommandContainer getFirstCommandContainer()
Debugging/test helper method: Returns the execution container for the first motion.

Returns:
the execution container for the current motion
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

getCommandContainers

public Collection<ICommandContainer> getCommandContainers()
Debugging/test helper method: Returns the remaining execution containers.

Returns:
the remaining execution containers
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

onStateChanged

public void onStateChanged(IExecutionContainer cont,
                           ExecutionState state)
Called when the state of the container changed it's state. One execution container goes to a state => the whole motion container goes to the state. When there is a latch available for the state, it will be counted down only when all execution containers reached the state. Exception to this rule: the whole motion container goes to finished, only when ALL execution containers went to finished.

Specified by:
onStateChanged in interface IContainerStateListener
Parameters:
cont - The container which changed it's state.
state - The actual state of the container.
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

cleanTriggerObservers

public void cleanTriggerObservers()
Stops all eventually running trigger handler.

This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

onContainerFinishedInternal

protected abstract void onContainerFinishedInternal(ICommandContainer cont,
                                                    CountDownLatch handlerFinished)
Called when the specified motion container is finished.

Used by inheriting classes to report that container is finished to its executor.

Parameters:
cont - finished container.
handlerFinished - latch that will be count down when executer is finished with the container.

addContainerListener

public void addContainerListener(IContainerStateListener listener)
Adds the given listener to this container.

Parameters:
listener - a listener
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

removeContainerListener

public void removeContainerListener(IContainerStateListener listener)
Removes the given container from this container.

Parameters:
listener - a listener
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

getRuntimeData

public ICommandRuntimeData getRuntimeData()
Gets the custom runtime data associated with this container.

Specified by:
getRuntimeData in interface IExecutionContainer
Returns:
the custom runtime data associated with this container. Can be null.
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

getCommand

public MotionInstruction getCommand()
Description copied from interface: ICommandContainer
Gets the command which was executed within this container.

Specified by:
getCommand in interface ICommandContainer
Returns:
The command.

getState

public ExecutionState getState()
Description copied from interface: ICommandContainer
Gets the current ExecutionState of the container.

Specified by:
getState in interface ICommandContainer
Returns:
The current state of the container.

getBatchParams

protected com.kuka.common.params.IParameterSet getBatchParams()
Gets the batch parameters if this container is created for a batch.

Returns:
the batch parameters if this container is created for a batch.

getBatch

protected MotionBatch getBatch()
Gets the motion batch if this container is created for a batch.

Returns:
the motion batch if this container is created for a batch, null if no batch.

isSynchron

public boolean isSynchron()
Checks if the motion in a container has been commanded synchronously.

Returns:
true if container should be executed synchronously.
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

addTriggerConditionObserver

public void addTriggerConditionObserver(ConditionObserver obs,
                                        IMotion motion)
Adds a condition observer for a trigger to the motion container.

Parameters:
obs - the condition observer to add
motion - the motion where the trigger was added.
This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.


Copyright © 2019. All rights reserved.