Package ch.hevs.kart

Class KartSequence.Builder

java.lang.Object
ch.hevs.kart.KartSequence.Builder
Enclosing class:
KartSequence

public static class KartSequence.Builder extends Object

Builder which has to be used in order to construct new KartSequences. Every method returns a reference back to the builder himself, this makes it possible to create sequences in just one line of code.

KartSequence seq = KartSequence.Builder().steer(0).drive(3).during(5000);

The example above lets the Kart drive in a circle for about 3 seconds.

  • Method Details

    • nop

      @NonNull public KartSequence.Builder nop()

      This instruction does nothing. It is present for completeness.

      Returns:
      Reference to the builder object.
    • drive

      @NonNull public KartSequence.Builder drive(int speed)

      This instruction changes the speed of the kart. Valid values for the speed are -15..15, whereas 0 means stop, -15 is the fastest speed backwards and 15 is the fastest speed in the forward direction.

      Parameters:
      speed - Speed to set (-15..15).
      Returns:
      Reference to the builder object.
    • steer

      @NonNull public KartSequence.Builder steer(int position)

      This instruction changes the steering to the given position. Valid values for the command are 0..4095, but the highest value depends the actual geometry of the Kart. There is no control at all if the given parameter is compatible with the steering mechanism, so it is your duty to ensure that the values are acceptable.

      Parameters:
      position - Position to set steering (0..4095, but depends steering geometry).
      Returns:
      Reference to the builder object.
    • outputs

      @NonNull public KartSequence.Builder outputs(int values)

      This instruction sets the four LED outputs to the values of the four least significant bytes of the given value. All other bits are ignored.

      Parameters:
      values - Value to set the four outputs (LED) to.
      Returns:
      Reference to the builder object.
    • ledOn

      @NonNull public KartSequence.Builder ledOn(int index)

      This instruction will turn the LED at the given index (0..3) on or generally spoken, the digital output will be activated.

      Parameters:
      index - Index of the LED/digital output to turn on (0..4).
      Returns:
      Reference to the builder object.
    • ledOff

      @NonNull public KartSequence.Builder ledOff(int index)

      This instruction will turn the LED at the given index (0..3) off or generally spoken, the digital output will be deactivated.

      Parameters:
      index - Index of the LED/digital output to turn off (0..4).
      Returns:
      Reference to the builder object.
    • travel

      @NonNull public KartSequence.Builder travel(int pulseCount)

      This instruction will leave the Kart in the exact same state until the given amount of pulses are counted on hall sensor 1. If the hall sensor counter register corresponds to the number of rotations the axis has made, you can make the kart traveling a certain distance with the current steering position and speed. The number of instructions can be between 0 and 4095.

      Setting the speed drive(int) to 0 before this instruction might not be a smart move...

      Parameters:
      pulseCount - Number of hall sensor 1 pulses to wait until the next action (0..4095).
      Returns:
      Reference to the builder object.
    • during

      @NonNull public KartSequence.Builder during(int milliseconds)

      This instruction will leave the Kart in the exact same state for the given amount of milliseconds. This method of waiting is certainly less exact in terms of the absolute position than the travel(int) instruction, but might be still useful for simple tasks.

      Note that the actual resolution of the times is 10ms. A delay of 0ms up to about 41s can be achieved by providing values from 0 (0ms) to 40950 (40.95s). If the passed value is bigger than 40950, the delay will be limited to 41s.

      Parameters:
      milliseconds - Number of milliseconds to wait before executing the next instruction.
      Returns:
      Reference to the builder object.
    • jump

      @NonNull public KartSequence.Builder jump(int sequenceIndex)

      This operation will jump to the instruction that is pointed by the operand.

      Parameters:
      sequenceIndex - Index of the instruction to jump to.
      Returns:
      Reference to the builder object.
    • build

      @NonNull public KartSequence build()
      Creates and returns the actual kart sequence. Note that the builder can be reused in order to create a new sequence.
      Returns:
      Built kart sequence.
    • sequenceSize

      public int sequenceSize()

      Returns the number of instructions in the sequence that is actually under construction by the builder.

      Returns:
      Number of instructions in the sequence.