public static class KartSequence.Builder
extends java.lang.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.
Modifier and Type | Method and Description |
---|---|
KartSequence |
build()
Creates and returns the actual kart sequence.
|
KartSequence.Builder |
drive(int speed)
This instruction changes the speed of the kart.
|
KartSequence.Builder |
during(int milliseconds)
This instruction will leave the Kart in the exact same state for the given amount of milliseconds.
|
KartSequence.Builder |
jump(int sequenceIndex)
This operation will jump to the instruction that is pointed by the operand.
|
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.
|
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.
|
KartSequence.Builder |
nop()
This instruction does nothing.
|
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.
|
int |
sequenceSize()
Returns the number of instructions in the sequence that is actually under construction by the builder.
|
KartSequence.Builder |
steer(int position)
This instruction changes the steering to the given position.
|
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.
|
public KartSequence.Builder nop()
This instruction does nothing. It is present for completeness.
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.
speed
- Speed to set (-15..15).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.
position
- Position to set steering (0..4095, but depends steering geometry).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.
values
- Value to set the four outputs (LED) to.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.
index
- Index of the LED/digital output to turn on (0..4).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.
index
- Index of the LED/digital output to turn off (0..4).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...
pulseCount
- Number of hall sensor 1 pulses to wait until the next action (0..4095).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.
milliseconds
- Number of milliseconds to wait before executing the next instruction.public KartSequence.Builder jump(int sequenceIndex)
This operation will jump to the instruction that is pointed by the operand.
sequenceIndex
- Index of the instruction to jump to.public KartSequence build()
public int sequenceSize()
Returns the number of instructions in the sequence that is actually under construction by the builder.