com.dexterind.gopigo.behaviours
Class Motion

java.lang.Object
  extended by com.dexterind.gopigo.behaviours.Motion

public class Motion
extends java.lang.Object

Handles all the methods related to the movement of the GoPigo.

Author:
marcello

Field Summary
private static Board board
          The main object which handles the methods to get access to the resources connected to the board.
private  Debug debug
          The debug object.
 java.util.Map<java.lang.String,java.lang.Integer> directions
          The HashMap of the directions.
private static Motion instance
          The instance of the current object.
 
Constructor Summary
Motion()
           
 
Method Summary
 int backward(boolean usePid)
          Moves backward the Gopigo.
 int decreaseSpeed()
          Decreases the speed of both the motors.
 int disableCommunicationTimeout()
          Disables the communication timeout.
 int enableCommunicationTimeout(int timeout)
          Enables the communication timeout.
 int forward(boolean usePid)
          Moves forward the Gopigo.
static Motion getInstance()
          Provides a global point of access to the Motion instance.
 int increaseSpeed()
          Increases the speed of both the motors.
 int left()
          Moves the Gopigo to the left.
 int leftWithRotation()
          Rotates the Gopigo to the left.
 int readTimeoutStatus()
          Reads the timeout status.
 int right()
          Moves the Gopigo to the right.
 int rightWithRotation()
          Rotates the Gopigo to the right.
 int setLeftSpeed(int speed)
          Sets the speed only for the left motor.
 int setRightSpeed(int speed)
          Sets the speed only for the right motor.
 int setSpeed(int speed)
          Sets the speed for both the motors.
 int stop()
          Stops any kind of movement.
 double trimRead()
          Reads the current Trim value.
 double trimTest(int value)
          Executes a Trim test.
 double trimWrite(int value)
          Sets the Trim value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

board

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


instance

private static Motion instance
The instance of the current object.


directions

public java.util.Map<java.lang.String,java.lang.Integer> directions
The HashMap of the directions. It could be useful as helper for rotating the servo motor or the GoPiGo itself.


debug

private Debug debug
The debug object.

Constructor Detail

Motion

public Motion()
       throws java.io.IOException,
              java.lang.InterruptedException
Throws:
java.io.IOException
java.lang.InterruptedException
Method Detail

getInstance

public static Motion getInstance()
                          throws java.io.IOException,
                                 java.lang.InterruptedException
Provides a global point of access to the Motion instance.

Returns:
the Motion instance.
Throws:
java.io.IOException
java.lang.InterruptedException

forward

public int forward(boolean usePid)
            throws java.io.IOException
Moves forward the Gopigo.

Parameters:
usePid - A boolean flag which defines if it's needed to use or not the PID.
Returns:
A status code.
Throws:
java.io.IOException

backward

public int backward(boolean usePid)
             throws java.io.IOException
Moves backward the Gopigo.

Parameters:
usePid - A boolean flag which defines if it's needed to use or not the PID.
Returns:
A status code.
Throws:
java.io.IOException

left

public int left()
         throws java.io.IOException
Moves the Gopigo to the left.

Returns:
A status code.
Throws:
java.io.IOException

leftWithRotation

public int leftWithRotation()
                     throws java.io.IOException
Rotates the Gopigo to the left.

Returns:
A status code.
Throws:
java.io.IOException

right

public int right()
          throws java.io.IOException
Moves the Gopigo to the right.

Returns:
A status code.
Throws:
java.io.IOException

rightWithRotation

public int rightWithRotation()
                      throws java.io.IOException
Rotates the Gopigo to the right.

Returns:
A status code.
Throws:
java.io.IOException

stop

public int stop()
         throws java.io.IOException
Stops any kind of movement.

Returns:
A status code.
Throws:
java.io.IOException

increaseSpeed

public int increaseSpeed()
                  throws java.io.IOException
Increases the speed of both the motors.

Returns:
A status code.
Throws:
java.io.IOException

decreaseSpeed

public int decreaseSpeed()
                  throws java.io.IOException
Decreases the speed of both the motors.

Returns:
A status code.
Throws:
java.io.IOException

setLeftSpeed

public int setLeftSpeed(int speed)
                 throws java.io.IOException
Sets the speed only for the left motor.

Parameters:
speed - A speed value between 0 and 255
Returns:
A status code.
Throws:
java.io.IOException

setRightSpeed

public int setRightSpeed(int speed)
                  throws java.io.IOException
Sets the speed only for the right motor.

Parameters:
speed - A speed value between 0 and 255.
Returns:
A status code.
Throws:
java.io.IOException

setSpeed

public int setSpeed(int speed)
             throws java.io.IOException
Sets the speed for both the motors.

Parameters:
speed - A speed value between 0 and 255
Returns:
A status code.
Throws:
java.io.IOException

trimTest

public double trimTest(int value)
                throws java.io.IOException
Executes a Trim test.

Parameters:
value - The value to test between -100 and 100.
Returns:
A status code.
Throws:
java.io.IOException

trimRead

public double trimRead()
                throws java.io.IOException
Reads the current Trim value.

Returns:
The current Trim value between -100 and 100.
Throws:
java.io.IOException

trimWrite

public double trimWrite(int value)
                 throws java.io.IOException
Sets the Trim value.

Parameters:
value - The Trim value between -100 and 100.
Returns:
A status code.
Throws:
java.io.IOException

readTimeoutStatus

public int readTimeoutStatus()
                      throws java.io.IOException
Reads the timeout status.

Returns:
The timeout value.
Throws:
java.io.IOException

enableCommunicationTimeout

public int enableCommunicationTimeout(int timeout)
                               throws java.io.IOException
Enables the communication timeout.

Parameters:
timeout - The value of the timout.
Returns:
A status code.
Throws:
java.io.IOException

disableCommunicationTimeout

public int disableCommunicationTimeout()
                                throws java.io.IOException
Disables the communication timeout.

Returns:
A status code.
Throws:
java.io.IOException