com.dexterind.gopigo
Class Gopigo

java.lang.Object
  extended by com.dexterind.gopigo.Gopigo

public final class Gopigo
extends java.lang.Object

The main class for the Gopigo. It instanciates all the components and behaviours and is in charge to handle the events.

Author:
marcello

Field Summary
 Board board
          The main object which handles the methods to get access to the resources connected to the board.
private  double criticalVoltage
          The critical voltage value.
private  Debug debug
          The debug object.
 Encoders encoders
          The encoders.
private static Gopigo instance
          The instance of the current object.
 IRReceiverSensor irReceiverSensor
          The IR Receiver sensor.
private  boolean isHalt
          The flag for the halted status.
private  boolean isInit
          The flag for the initialized status.
 Led ledLeft
          The left led.
 Led ledRight
          The right led.
private  java.util.concurrent.CopyOnWriteArrayList<GopigoListener> listeners
          The list of the listeners which are listening for some event.
private  double minVoltage
          The minimum voltage value.
 Motion motion
          The motion behaviour object.
 Motor motorLeft
          The left motor.
 Motor motorRight
          The right motor.
 Servo servo
          The servo motor.
 UltraSonicSensor ultraSonicSensor
          The ultrasonic sensor.
private  java.util.Timer voltageTimer
          The timer which will be in charge to check the voltage value.
private  int voltageTimerTime
          The time in milliseconds between successive task executions.
 
Constructor Summary
Gopigo()
          Instanciates the components and the behaviours of the Gopigo.
 
Method Summary
 void addListener(GopigoListener listener)
          Adds a GopigoListener to the listeners list.
protected  void fireEvent(java.util.EventObject event)
          Fires an event to the listeners.
 void free()
          Sets the GoPiGo free.
 java.lang.Double getCriticalVoltage()
          Returns the critical voltage value.
static Gopigo getInstance()
          Provides a global point of access to the Gopigo instance.
 java.lang.Double getMinVoltage()
          Returns the min. voltage value.
 void halt()
          Halts the GoPiGo if necessary.
 void init()
          Initializes the Gopigo and fires an event once the init is done.
private  void initVoltageCheck()
          Initializes a timer which will checks the voltage and will fires and event in case of low voltage.
 java.lang.Boolean isHalt()
          It returns the halt status.
 java.lang.Boolean isOperative()
          It returns the operativity status.
 void onHalt()
          Fires a "HALT" StatusEvent
 void removeListener(GopigoListener listener)
          Removes a GopigoListener from the listeners list.
 void reset()
          Resets the Gopigo.
 void setCriticalVoltage(double value)
          Sets the critical voltage value.
 void setMinVoltage(double value)
          Sets the min. voltage value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

private static Gopigo instance
The instance of the current object.


isInit

private boolean isInit
The flag for the initialized status.


isHalt

private boolean isHalt
The flag for the halted status.


voltageTimer

private java.util.Timer voltageTimer
The timer which will be in charge to check the voltage value.


voltageTimerTime

private int voltageTimerTime
The time in milliseconds between successive task executions.


minVoltage

private double minVoltage
The minimum voltage value. If the voltage drops under this value a VoltageEvent will be fired.


criticalVoltage

private double criticalVoltage
The critical voltage value. If the voltage drops under this value a VoltageEvent will be fired and the GoPiGo will be flagged as "halted".


board

public Board board
The main object which handles the methods to get access to the resources connected to the board.


encoders

public Encoders encoders
The encoders.


servo

public Servo servo
The servo motor.


ultraSonicSensor

public UltraSonicSensor ultraSonicSensor
The ultrasonic sensor.


irReceiverSensor

public IRReceiverSensor irReceiverSensor
The IR Receiver sensor.


ledLeft

public Led ledLeft
The left led.


ledRight

public Led ledRight
The right led.


motorLeft

public Motor motorLeft
The left motor.


motorRight

public Motor motorRight
The right motor.


motion

public Motion motion
The motion behaviour object.


listeners

private final java.util.concurrent.CopyOnWriteArrayList<GopigoListener> listeners
The list of the listeners which are listening for some event.


debug

private Debug debug
The debug object.

Constructor Detail

Gopigo

public Gopigo()
Instanciates the components and the behaviours of the Gopigo.

Method Detail

getInstance

public static Gopigo getInstance()
Provides a global point of access to the Gopigo instance.

Returns:
the Gopigo instance.

init

public void init()
Initializes the Gopigo and fires an event once the init is done.


reset

public void reset()
           throws java.io.IOException
Resets the Gopigo.

Throws:
java.io.IOException

addListener

public void addListener(GopigoListener listener)
Adds a GopigoListener to the listeners list.

Parameters:
listener - The GopigoListener to register.

removeListener

public void removeListener(GopigoListener listener)
Removes a GopigoListener from the listeners list.

Parameters:
listener - The GopigoListener to remove.

fireEvent

protected void fireEvent(java.util.EventObject event)
Fires an event to the listeners.

Parameters:
event - The event to fire.

initVoltageCheck

private void initVoltageCheck()
Initializes a timer which will checks the voltage and will fires and event in case of low voltage.


free

public void free()
Sets the GoPiGo free. It removes the "halted" flag if necessary.


isOperative

public java.lang.Boolean isOperative()
It returns the operativity status.

Returns:
True if operative, False if not.

halt

public void halt()
Halts the GoPiGo if necessary.


isHalt

public java.lang.Boolean isHalt()
It returns the halt status.

Returns:
True if halted, False if not.

onHalt

public void onHalt()
Fires a "HALT" StatusEvent


setMinVoltage

public void setMinVoltage(double value)
Sets the min. voltage value.

Parameters:
value - The minimum voltage value to set.

getMinVoltage

public java.lang.Double getMinVoltage()
Returns the min. voltage value.

Returns:
The min. voltage value.

setCriticalVoltage

public void setCriticalVoltage(double value)
Sets the critical voltage value. Under this value the GoPiGo will be flagged as "halted".

Parameters:
value - The critical voltage value to set.

getCriticalVoltage

public java.lang.Double getCriticalVoltage()
Returns the critical voltage value.

Returns:
The Critical voltage value.