edu.cmu.ri.createlab.hummingbird
Class HummingbirdRobot

java.lang.Object
  extended by edu.cmu.ri.createlab.hummingbird.HummingbirdRobot

public class HummingbirdRobot
extends java.lang.Object


Constructor Summary
HummingbirdRobot()
          Creates the Hummingbird object and automatically connects to a Hummingbird (if no Hummingbird is attached, this will hang until you attach one)
 
Method Summary
 void disconnect()
          Disconnects the Hummingbird from your program.
 boolean emergencyStop()
          Turns off all motors, vibrations motors, LEDs, and full-color LEDs.
 java.lang.Integer getSensorValue(int analogInputPortId)
          Returns the value of the given port id; returns -1 if an error occurred while trying to read the value.
 int[] getSensorValues()
          Gets all of the sensor values state.
 byte[] getSpeech(java.lang.String whatToSay)
          Converts the given text into speech, and returns the resulting WAV sound clip as a byte array.
 boolean isMotorPowerEnabled()
          Returns true if motor power is plugged in; false otherwise.
 void playClip(byte[] data)
          Plays the sound clip contained in the given byte array.
 void playTone(int frequency, int volume, int duration)
          Plays a tone having the given frequency, volume, and duration.
 boolean setFullColorLED(int ledId, int red, int green, int blue)
          Sets the full-color LED specified by the given ledId to the given red, green, and blue intensities.
 java.awt.Color[] setFullColorLEDs(boolean[] mask, java.awt.Color[] colors)
          Sets the full-color LEDs specified by the given mask to the given colors.
 boolean setLED(int ledId, int intensity)
          Sets the LED specified by the given ledId to the given intensity.
 int[] setLEDs(boolean[] mask, int[] intensities)
          Sets the LEDs specified by the given mask to the given intensities.
 int[] setMotorVelocities(boolean[] mask, int[] velocities)
          Sets the motors specified by the given mask to the given velocities.
 boolean setMotorVelocity(int motorId, int velocity)
          Sets the motor specified by the given motorId to the given (signed) velocity.
 boolean setServoPosition(int servoId, int position)
          Sets the servo specified by the given servoId to the given position.
 int[] setServoPositions(boolean[] mask, int[] positions)
          Sets the servo motors specified by the given mask to the given positions.
 boolean setVibrationMotorSpeed(int motorId, int intensity)
          Sets the vibration motor specified by the given motorId to the given intensity.
 int[] setVibrationMotorSpeeds(boolean[] mask, int[] intensities)
          Sets the vibration motors specified by the given mask to the given intensities.
 void speak(java.lang.String whatToSay)
          Converts the given text into audio and plays it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HummingbirdRobot

public HummingbirdRobot()
Creates the Hummingbird object and automatically connects to a Hummingbird (if no Hummingbird is attached, this will hang until you attach one)

Method Detail

setLEDs

public int[] setLEDs(boolean[] mask,
                     int[] intensities)
Sets the LEDs specified by the given mask to the given intensities. Returns the current intensities as an array of integers if the command succeeded, null otherwise.

Parameters:
mask - boolean array signifying which LEDs to activate (array element 0 is servo port 1)
intensities - array signifying LED intensity (range is 0 to 255)

isMotorPowerEnabled

public boolean isMotorPowerEnabled()
Returns true if motor power is plugged in; false otherwise.


setMotorVelocities

public int[] setMotorVelocities(boolean[] mask,
                                int[] velocities)
Sets the motors specified by the given mask to the given velocities. Returns the current velocities as an array of integers if the command succeeded, null otherwise.

Parameters:
mask - boolean array signifying which motors to activate (array element 0 is motor port 1)
velocities - array signifying motor velocity (range is -255 to 255)

setServoPositions

public int[] setServoPositions(boolean[] mask,
                               int[] positions)
Sets the servo motors specified by the given mask to the given positions. Returns the current positions as an array of integers if the command succeeded, null otherwise.

Parameters:
mask - boolean array signifying which servos to activate (array element 0 is servo port 1)
positions - array signifying servo position (range is 0 to 255)

playClip

public void playClip(byte[] data)
Plays the sound clip contained in the given byte array.

Parameters:
data - array of bytes containing sound date

setMotorVelocity

public boolean setMotorVelocity(int motorId,
                                int velocity)
Sets the motor specified by the given motorId to the given (signed) velocity. Returns true if the command succeeded, false otherwise.

Parameters:
motorId - the motor to control [1 or 2]
velocity - the signed velocity [-255 to 255]
Throws:
java.lang.IllegalArgumentException - if the motorId specifies an invalid port

getSensorValues

public int[] getSensorValues()
Gets all of the sensor values state. Returns null if an error occurred while getting the state.

Returns:
array containing all four sensor values, array element 0 corresponds to port 1

playTone

public void playTone(int frequency,
                     int volume,
                     int duration)
Plays a tone having the given frequency, volume, and duration.

Parameters:
frequency - the frequency in Hertz to play the tone
volume - how loud to play the clip, range is 1 to 10
duration - how long to play the clip in milliseconds

setFullColorLED

public boolean setFullColorLED(int ledId,
                               int red,
                               int green,
                               int blue)
Sets the full-color LED specified by the given ledId to the given red, green, and blue intensities. Returns true if the command succeeded, false otherwise.

Parameters:
ledId - the LED to control [1 or 2]
red - the intensity of the LED's red component [0 to 255]
green - the intensity of the LED's green component [0 to 255]
blue - the intensity of the LED's blue component [0 to 255]
Throws:
java.lang.IllegalArgumentException - if the ledId specifies an invalid port

disconnect

public void disconnect()
Disconnects the Hummingbird from your program. Call at the end of your program.


setVibrationMotorSpeed

public boolean setVibrationMotorSpeed(int motorId,
                                      int intensity)
Sets the vibration motor specified by the given motorId to the given intensity. Returns true if the command succeeded, false otherwise.

Parameters:
motorId - the motor to control [1 or 2]
intensity - the intensity of vibration [0 to 255]
Throws:
java.lang.IllegalArgumentException - if the motorId specifies an invalid port

speak

public void speak(java.lang.String whatToSay)
Converts the given text into audio and plays it.

Parameters:
whatToSay - a String specifying what should be set

setVibrationMotorSpeeds

public int[] setVibrationMotorSpeeds(boolean[] mask,
                                     int[] intensities)
Sets the vibration motors specified by the given mask to the given intensities. Returns the current intensities as an array of integers if the command succeeded, null otherwise.

Parameters:
mask - boolean array signifying which motors to activate (array element 0 is vibration motor port 1)
intensities - array signifying motor intensities position (range is 0 to 255)

setServoPosition

public boolean setServoPosition(int servoId,
                                int position)
Sets the servo specified by the given servoId to the given position. Returns true if the command succeeded, false otherwise.

Parameters:
servoId - the servo to control [0 to 3]
position - the position [0 to 255]
Throws:
java.lang.IllegalArgumentException - if the servoId specifies an invalid port

getSensorValue

public java.lang.Integer getSensorValue(int analogInputPortId)
Returns the value of the given port id; returns -1 if an error occurred while trying to read the value.

Returns:
the value of the sensor, range is 0 to 255

setFullColorLEDs

public java.awt.Color[] setFullColorLEDs(boolean[] mask,
                                         java.awt.Color[] colors)
Sets the full-color LEDs specified by the given mask to the given colors. Returns the current colors as an array of colors if the command succeeded, null otherwise.

Returns:
an array of current LED colors.

getSpeech

public byte[] getSpeech(java.lang.String whatToSay)
Converts the given text into speech, and returns the resulting WAV sound clip as a byte array.

Parameters:
whatToSay - String to convert into a wav file
Returns:
a byte array that is ready to be played as a wav file

setLED

public boolean setLED(int ledId,
                      int intensity)
Sets the LED specified by the given ledId to the given intensity. Returns true if the command succeeded, false otherwise.

Parameters:
ledId - the LED to control [1, 2, 3, or 4]
intensity - the intensity [0 to 255]
Throws:
java.lang.IllegalArgumentException - if the ledId specifies an invalid port

emergencyStop

public boolean emergencyStop()
Turns off all motors, vibrations motors, LEDs, and full-color LEDs. Returns true if the command succeeded, false otherwise.