ch.hei.kart
Class Kart

java.lang.Object
  extended by ch.hei.kart.Kart

public class Kart
extends java.lang.Object

Kart model. Once connected, the kart model allows to manipulate the kart developed during the first year's summer school remotely.

Version:
2.0 - 2014
Author:
Nils Chatton (chn@hevs.ch), Christopher Metrailler (mei@hevs.ch), Michael Clausen (clm@hevs.ch)

Field Summary
static int MAXIMAL_SPEED
          Maximal drive speed.
static int MINIMAL_SPEED
          Minimal drive speed (maximal backwards).
 
Constructor Summary
Kart()
          Constructs a new unconnected kart object with the default setup values.
Kart(KartSetup setup)
          Constructs a new kart object with the given setup.
 
Method Summary
 void addKartListener(KartListener listener)
          Adds the given kart listener to the kart.
 void addStatusRegisterListener(KartStatusRegisterListener listener)
          Adds the given status listener to the kart.
 void connect(ch.hei.kart.comm.discovery.DiscoveryEntity entity)
          Tries to establish a connection to the given kart entity.
 void decreaseDriveSpeed()
          Decreases the drive speed (throttle) by the smallest possible increment.
 void disconnect()
          Disconnects from the kart.
 float getBatteryLevel()
          Returns the battery level from 0.0 (empty) to 1.0 (full).
 int getControlRegister(KartControlRegister register)
          Returns the actual value of the control register.
 int getControlRegisterUnsigned(KartControlRegister register)
          Returns the actual value of the control register.
 int getDriveSpeed()
          Returns the actual absolute drive speed (throttle) in the range [-15, 15].
 float getDriveSpeedNormalized()
          Returns the actual normalized drive speed (throttle) in the range [-1.0, 1.0].
 boolean getLed(int index)
          Gets the status if the led at the given index.
 int getStatusRegister(KartStatusRegister register)
          Returns the actual value of the status register.
 int getStatusRegisterUnsigned(KartStatusRegister register)
          Returns the actual value of the status register.
 int getSteeringControlPosition()
          Returns the actual absolute steering control position.
 float getSteeringControlPositionNormalized()
          Returns the actual normalized steering control position.
 int getSteeringPosition()
          Returns the actual absolute steering position (not the setpoint).
 float getSteeringPositionNormalized()
          Returns the actual normalized steering position (not the setpoint) in the range [-1.0, 1.0].
 void increaseDriveSpeed()
          Increases the drive speed (throttle) by the smallest possible increment.
 boolean isSteeringEndContactTriggered()
          Returns true if the steering end contact is closed, false otherwise.
 boolean isSteeringPositionReached()
          Returns true if the kart has reached the target steering position, false otherwise.
 void removeKartListener(KartListener listener)
          Removes the kart listener.
 void removeStatusRegisterListener(KartStatusRegisterListener listener)
          Removes the given status register listener.
 void setControlRegister(KartControlRegister register, int value)
          Sets the given control register to the given value.
 void setDriveSpeed(int speed)
          Sets the drive speed (throttle) to the given absolute value.
 void setDriveSpeedNormalized(float speed)
          Sets the drive speed (throttle) to the given normalized value.
 void setLed(int index, boolean on)
          Sets the LED at the give index [0,3] to the given value (true=on).
 void setSteeringPosition(int position)
          Sets the steering position on the kart to the given absolute value.
 void setSteeringPositionNormalized(float position)
          Sets the steering position on the kart to the given normalized value.
 KartSetup setup()
          Returns a reference to the kart setup.
 void toggleLed(int index)
          Toggles the LED at the given index.
 void turnSteeringBy(int amount)
          Turns the steering position by the given absolute amount of steps, but not further as the left and right end positions.
 void turnSteeringNormalizedBy(float amount)
          Turns the steering position by the given normalized amount, but not further as the left and right end positions, whereas 1.0 would match the complete steering range.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAXIMAL_SPEED

public static final int MAXIMAL_SPEED
Maximal drive speed.

See Also:
Constant Field Values

MINIMAL_SPEED

public static final int MINIMAL_SPEED
Minimal drive speed (maximal backwards).

See Also:
Constant Field Values
Constructor Detail

Kart

public Kart()
Constructs a new unconnected kart object with the default setup values.


Kart

public Kart(KartSetup setup)
Constructs a new kart object with the given setup.

Parameters:
setup - Kart setup to apply.
Method Detail

setup

public KartSetup setup()
Returns a reference to the kart setup. Note that when you change settings on the kart setup object, these are applied immediately to the kart.

Returns:
Kart setup object for the kart instance.

connect

public void connect(ch.hei.kart.comm.discovery.DiscoveryEntity entity)
Tries to establish a connection to the given kart entity. The operation is asynchronous and returns control direct to the caller. The status of the connection attempt is returned via the kart listener interface, method connectionStatusChanged().

Parameters:
entity - Kart communication entity to connect to, a such entity can be found using the method startDiscovery() on the class CommunicationSetup.

disconnect

public void disconnect()
Disconnects from the kart.


setDriveSpeed

public void setDriveSpeed(int speed)
Sets the drive speed (throttle) to the given absolute value. Valid values are [-15, 15], whereas negative values mean backward and positive values mean forward.

Parameters:
speed - Absolute drive speed (throttle).

setDriveSpeedNormalized

public void setDriveSpeedNormalized(float speed)
Sets the drive speed (throttle) to the given normalized value. Valid values are [-1.0, 1.0], whereas negative values mean backward and positive values mean forward.

Parameters:
speed - Normalized drive speed (throttle).

increaseDriveSpeed

public void increaseDriveSpeed()
Increases the drive speed (throttle) by the smallest possible increment.


decreaseDriveSpeed

public void decreaseDriveSpeed()
Decreases the drive speed (throttle) by the smallest possible increment.


getDriveSpeed

public int getDriveSpeed()
Returns the actual absolute drive speed (throttle) in the range [-15, 15].

Returns:
Actual absolute drive speed.

getDriveSpeedNormalized

public float getDriveSpeedNormalized()
Returns the actual normalized drive speed (throttle) in the range [-1.0, 1.0].

Returns:
Actual normalized drive speed.

setSteeringPosition

public void setSteeringPosition(int position)
Sets the steering position on the kart to the given absolute value. Note that this is the setpoint of the steering control system on the kart. It may take some time for the steering system to actually reach the given position. The position is limited to the valid range from 0 to the maximal steering position in the kart setup.

Parameters:
position - Absolute steering position.

setSteeringPositionNormalized

public void setSteeringPositionNormalized(float position)
Sets the steering position on the kart to the given normalized value. Note that this is the setpoint of the steering control system on the kart. It may take some time for the steering system to actually reach the given position. The position is limited to [-1, 1] whereas -1 and 1 are the left, respective right end positions.

Parameters:
position - Normalized steering position.

getSteeringControlPosition

public int getSteeringControlPosition()
Returns the actual absolute steering control position. This is not the steering position the kart actually has, it is the position that the kart is instructed to reach.

Returns:
Absolute steering position setpoint.

getSteeringControlPositionNormalized

public float getSteeringControlPositionNormalized()
Returns the actual normalized steering control position. This is not the steering position the kart actually has, it is the position that the kart is instructed to reach.

Returns:
Normalized steering position setpoint [-1.0, 1.0].

turnSteeringBy

public void turnSteeringBy(int amount)
Turns the steering position by the given absolute amount of steps, but not further as the left and right end positions. Negative numbers signal opposite direction.

Parameters:
amount - Absolute number of steps to turn.

turnSteeringNormalizedBy

public void turnSteeringNormalizedBy(float amount)
Turns the steering position by the given normalized amount, but not further as the left and right end positions, whereas 1.0 would match the complete steering range. Negative numbers signal opposite direction.

Parameters:
amount - Normalized amount to turn.

getSteeringPosition

public int getSteeringPosition()
Returns the actual absolute steering position (not the setpoint). This is the position the steering system actually has and does not necessarily has to match the setpoint as the system needs some time to reach the requested positions.

Returns:
Actual absolute steering position.

getSteeringPositionNormalized

public float getSteeringPositionNormalized()
Returns the actual normalized steering position (not the setpoint) in the range [-1.0, 1.0]. This is the position the steering system actually has and does not necessarily has to match the setpoint as the system needs some time to reach the requested positions.

Returns:
Actual normalized steering position from [-1.0, 1.0].

isSteeringPositionReached

public boolean isSteeringPositionReached()
Returns true if the kart has reached the target steering position, false otherwise.

Returns:
True if the kart has reached the target steering position, false otherwise.

isSteeringEndContactTriggered

public boolean isSteeringEndContactTriggered()
Returns true if the steering end contact is closed, false otherwise.

Returns:
True if steering end contact is closed, false otherwise.

getBatteryLevel

public float getBatteryLevel()
Returns the battery level from 0.0 (empty) to 1.0 (full).

Returns:
Battery level [0.0, 1.0].

setLed

public void setLed(int index,
                   boolean on)
Sets the LED at the give index [0,3] to the given value (true=on).

Parameters:
index - LED index [0, 3].
on - If true the LED is set on, if false the LED is set off.

getLed

public boolean getLed(int index)
Gets the status if the led at the given index.

Parameters:
index - LED index [0, 3]
Returns:
True if the LED is on, false if the LED is off.

toggleLed

public void toggleLed(int index)
Toggles the LED at the given index.

Parameters:
index - LED index [0, 3]

setControlRegister

public void setControlRegister(KartControlRegister register,
                               int value)
Sets the given control register to the given value. Note that control registers hold only 16 bit values, so not the whole range of integer values is applicable.

Parameters:
register - The register to set.
value - The value to set for the register.
See Also:
KartControlRegister

getControlRegister

public int getControlRegister(KartControlRegister register)
Returns the actual value of the control register. The value is casted signed to an int, so if you like to read the register value rather unsigned, use the getControlRegisterUnsigned() method.

Parameters:
register - The control register to read.
Returns:
The actual SIGNED register value.

getControlRegisterUnsigned

public int getControlRegisterUnsigned(KartControlRegister register)
Returns the actual value of the control register. The value is casted unsigned to an int.

Parameters:
register - The control register to read.
Returns:
The actual UNSIGNED register value.

getStatusRegister

public int getStatusRegister(KartStatusRegister register)
Returns the actual value of the status register. The value is casted signed to an int, so if you like to read the register value rather unsigned, use the getStatusRegisterUnsigned() method.

Parameters:
register - The status register to read.
Returns:
The actual SIGNED register value.

getStatusRegisterUnsigned

public int getStatusRegisterUnsigned(KartStatusRegister register)
Returns the actual value of the status register. The value is casted unsigned to an int.

Parameters:
register - The status register to read.
Returns:
The actual UNSIGNED register value.

addStatusRegisterListener

public void addStatusRegisterListener(KartStatusRegisterListener listener)
Adds the given status listener to the kart. The listener will be notified about the change of any status register on the kart.

Parameters:
listener - Reference to the listener to add.

removeStatusRegisterListener

public void removeStatusRegisterListener(KartStatusRegisterListener listener)
Removes the given status register listener.

Parameters:
listener - Reference to the listener to remove.

addKartListener

public void addKartListener(KartListener listener)
Adds the given kart listener to the kart.

Parameters:
listener - Reference to the object implementing the kart listener interface.

removeKartListener

public void removeKartListener(KartListener listener)
Removes the kart listener.

Parameters:
listener - Reference to the object implementing the kart listener interface to remove.