Package api.advanced
Class Bundle
- java.lang.Object
-
- api.advanced.Bundle
-
- All Implemented Interfaces:
ExecutableCommands
public class Bundle extends java.lang.Object implements ExecutableCommands
A powerful tool to combine instructions to multiple servos and execute them in parallelAll instructions inside a Bundle have the same execution time. To combine instructions with multiple execution times, you can combine multiple Bundles into a
Collection
.Tip: There also is a convenience class to easily create Bundles for the most common use cases. It's named
BundleCreator
.- See Also:
Example2
,BundleCreator
,ExecutableCommands
,Collection
-
-
Method Summary
Modifier and Type Method Description void
add(int servo, int position)
Add an instruction to a servo to the Bundle
Note: This method does not throw or warn you if this Bundle already contains an instruction to this servo.
Note: This method does not throw or warn you if the targeted position is out of range.void
add(Bundle bundle)
Adds all instructions from the specified Bundle to this Bundle.
Note: This method does not throw or warn you if both Bundles contain instructions to the same servo(s).
Note: This method retains the default execution time of the Bundle.boolean
equals(java.lang.Object obj)
void
exec()
Execute the Bundle for the default time specified in the constructor
This method does not block the Thread when invoked.void
exec(int customTime)
Execute the Command(s) for a given time
This method does not block the Thread when invoked.void
execBlocking()
LikeExecutableCommands.exec()
but blocks the Thread until the Command has been executedvoid
execBlocking(int time)
LikeExecutableCommands.exec(int)
but blocks the Thread until the Command has been executedjava.lang.String
getCommand()
Get the command represented by this Bundle.java.lang.String
getRawCommand()
Get the command currently represented by this bundle (without time).int
getTime()
Get the default execution time specified in the constructor or insetTime
java.lang.String
getTree()
Alias forgetCommand
void
printTree()
Prints the result ofgetTree
void
remove(int servo)
Remove all instructions to the specified servo from the Bundlevoid
setTime(int newTime)
Set a new default execution time
-
-
-
Method Detail
-
add
public void add(int servo, int position)
Add an instruction to a servo to the Bundle
Note: This method does not throw or warn you if this Bundle already contains an instruction to this servo.
Note: This method does not throw or warn you if the targeted position is out of range.- Parameters:
servo
- The pin of the servo which should be added to the Bundleposition
- The targeted position of the servo ranging from 0 to 1500- See Also:
add(Bundle)
-
add
public void add(Bundle bundle)
Adds all instructions from the specified Bundle to this Bundle.
Note: This method does not throw or warn you if both Bundles contain instructions to the same servo(s).
Note: This method retains the default execution time of the Bundle.- Parameters:
bundle
- The Bundle whose instructions should be added to this Bundle- See Also:
add(int, int)
-
remove
public void remove(int servo)
Remove all instructions to the specified servo from the Bundle- Parameters:
servo
- The pin of the servo which should be removed
-
exec
public void exec(int customTime)
Execute the Command(s) for a given time
This method does not block the Thread when invoked.- Specified by:
exec
in interfaceExecutableCommands
- Parameters:
customTime
- The execution time in milliseconds
-
exec
public void exec()
Execute the Bundle for the default time specified in the constructor
This method does not block the Thread when invoked.- Specified by:
exec
in interfaceExecutableCommands
- See Also:
exec(int)
,setTime(int)
-
setTime
public void setTime(int newTime)
Set a new default execution time- Parameters:
newTime
- The new default execution time in milliseconds- See Also:
getTime()
-
getTime
public int getTime()
Get the default execution time specified in the constructor or insetTime
- Specified by:
getTime
in interfaceExecutableCommands
- Returns:
- The default execution time of this Bundle
- See Also:
setTime(int)
-
getRawCommand
public java.lang.String getRawCommand()
Get the command currently represented by this bundle (without time).- Returns:
- The raw command
-
getCommand
public java.lang.String getCommand()
Get the command represented by this Bundle.- Returns:
- The command that will be executed by
exec()
.
-
printTree
public void printTree()
Prints the result ofgetTree
- Specified by:
printTree
in interfaceExecutableCommands
- See Also:
getCommand()
-
getTree
public java.lang.String getTree()
Alias forgetCommand
- Specified by:
getTree
in interfaceExecutableCommands
- Returns:
- The command tree
- See Also:
getCommand()
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
execBlocking
public void execBlocking()
Description copied from interface:ExecutableCommands
LikeExecutableCommands.exec()
but blocks the Thread until the Command has been executed- Specified by:
execBlocking
in interfaceExecutableCommands
-
execBlocking
public void execBlocking(int time)
Description copied from interface:ExecutableCommands
LikeExecutableCommands.exec(int)
but blocks the Thread until the Command has been executed- Specified by:
execBlocking
in interfaceExecutableCommands
- Parameters:
time
- The execution time in milliseconds
-
-