Package api.advanced

Class 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 parallel

    All 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
    • Constructor Summary

      Constructors 
      Constructor Description
      Bundle​(int time)
      Create a new Bundle with the specified default execution time
    • 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()
      Like ExecutableCommands.exec() but blocks the Thread until the Command has been executed
      void execBlocking​(int time)
      Like ExecutableCommands.exec(int) but blocks the Thread until the Command has been executed
      java.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 in setTime
      java.lang.String getTree()
      Alias for getCommand
      void printTree()
      Prints the result of getTree
      void remove​(int servo)
      Remove all instructions to the specified servo from the Bundle
      void setTime​(int newTime)
      Set a new default execution time
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Bundle

        public Bundle​(int time)
        Create a new Bundle with the specified default execution time
        Parameters:
        time - The default execution time, used when invoking exec()
    • 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 Bundle
        position - 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 interface ExecutableCommands
        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 interface ExecutableCommands
        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 in setTime
        Specified by:
        getTime in interface ExecutableCommands
        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().
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object