RoboJDETM v2.0

com.ridgesoft.handyboard
Class HandyBoard

java.lang.Object
  extended by com.ridgesoft.handyboard.HandyBoard

public class HandyBoard
extends Object

Handy Board support class.


Field Summary
static int DIGITAL_IN
          Address of the digital input port.
static int PORTA
          Address of port A on the 68HC11.
static byte TYPE_HANDY_BOARD
          Used in setBoardType method to denote a standard Handy Board.
static byte TYPE_SUMO11
          Used in setBoardType method to denote a Sumo11 board.
 
Method Summary
static int analog(int portNumber)
          Samples the analog input for portNumber specified.
static void beep()
          Beeps the buzzer.
static void clearDigitalOutput(int portNumber)
          Clears the specified digital output bit.
static void click()
          Click the buzzer.
static void enableEncoder(int encoder)
          Enables the specified shaft encoder.
static void enablePulseMeasurement(int port, boolean enabled)
          Initializes digital input 7 or 8 for pulse measurement.
static AnalogInput getAnalogInput(int portNumber)
          Gets the AnalogInput object for the specified input port.
static byte getBoardType()
          Returns the board type.
static Speaker getBuzzer()
          Gets the Speaker object for the buzzer.
static DigitalInput getDigitalInput(int portNumber)
          Gets the DigitalInput object for the specified input port.
static DigitalOutput getDigitalOutput(int output)
          Gets the DigitalOutput object for the specified output number.
static int getEncoderCounts(int encoder)
          Read the counts for the particular encoder.
static int getEncoderRate(int encoder)
          Read the current rate of the encoder counter.
static IrReceiver getIrReceiver()
          Gets the IrReceiver object for the infrared receiver.
static Display getLcdDisplay()
          Gets the Display object for the LCD.
static Motor getMotor(int motor)
          Gets the Motor object for the specified motor.
static OutputStream getOutputStream()
          Gets the OutputStream for the LCD.
static Servo getServo(int servo)
          Gets the Servo object for a particular Handy Board servo.
static ShaftEncoder getShaftEncoder(int encoder)
          Gets the ShaftEncoder object for a particular quadrature shaft encoder.
static PushButton getStartButton()
          Returns the PushButton object for the START button.
static PushButton getStopButton()
          Returns the PushButton object for the STOP button.
static AnalogInput getThumbWheel()
          Gets the AnalogInput object for the thumbwheel.
static int irRead()
          Reads a waiting character from the infrared receiver.
static void irRxInitialize(int startMin, int startMax, int shortMin, int threshold, int longMax, int numberOfBits, boolean invertBits, boolean reverseBits)
          Initializes the receiver.
static boolean isDigitalInputSet(int portNumber)
          Reads a digital input bit.
static boolean isDigitalOutputSet(int portNumber)
          Returns the state of the specified digital output bit.
static void play(int frequency, int duration)
          Plays the specified tone (frequency) using the buzzer.
static void pulseDigitalOutput(int portNumber, int duration)
          Pulses the specified digital output bit.
static int readEdgeCount(int port)
          Returns the count of rising and falling edges detected on this input since pulse measurement was enabled by the enablePulseMeasurement method.
static int readPulseDuration(int port)
          Returns the duration of the last pulse, the value -1 will be returned if no pulse has completed since pulse intput was enabled or since the last read.
static int readPulseDuration(int port, boolean highPulse)
          Returns the duration of the last high pulse.
static int readThumbWheel()
          Samples the thumbwheel analog input.
static void setBoardType(byte type)
          Tells the virtual machine what type of controller it is running on.
static void setDigital9Direction(boolean isOutput)
          Sets the direction for digital port 9.
static void setDigitalOutput(int portNumber)
          Set the specified digital output bit.
static void setMotorPower(int motor, int power)
          Sets a motor's power.
static void setServoPosition(int servo, int position)
          Sets the position of the specified servo.
static void setTerminateOnStop(boolean terminateOnStop)
          Configures whether the virtual machine terminates the program when the STOP button is pressed.
static boolean startPressed()
          Returns true if the START button is pressed.
static boolean stopPressed()
          Returns true if the STOP button is pressed.
static void toggleDigitalOutput(int portNumber)
          Toggles the specified digital output bit.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Field Detail

DIGITAL_IN

public static final int DIGITAL_IN
Address of the digital input port.

See Also:
Constant Field Values

PORTA

public static final int PORTA
Address of port A on the 68HC11.

See Also:
Constant Field Values

TYPE_HANDY_BOARD

public static final byte TYPE_HANDY_BOARD
Used in setBoardType method to denote a standard Handy Board.

See Also:
Constant Field Values

TYPE_SUMO11

public static final byte TYPE_SUMO11
Used in setBoardType method to denote a Sumo11 board.

See Also:
Constant Field Values
Method Detail

analog

public static int analog(int portNumber)
Samples the analog input for portNumber specified.

Parameters:
portNumber - number of the input
  • 0 thru 6 - general purpose analog inputs
  • 7 - thumbwheel
  • 16 thru 31 - Handy Board expansion board general purpose analog inputs
Returns:
sampled value between 0 and 255, inclusive

beep

public static void beep()
Beeps the buzzer.

Doesn't return until the beep is finished.


clearDigitalOutput

public static void clearDigitalOutput(int portNumber)
Clears the specified digital output bit.

Parameters:
portNumber - digital output bit to clear
  • Handy Board: 9 (digital input 9 may be used as an output)
  • Handy Board w/expansion: 0 - 9
  • Sumo11: 8, 9
  • setDigital9Direction(true) method must be called to configure digital 9 as an output

click

public static void click()
Click the buzzer.

Doesn't return until the click is finished.


enableEncoder

public static void enableEncoder(int encoder)
Enables the specified shaft encoder.

Parameters:
encoder - encoder to enable (0 to 2)

enablePulseMeasurement

public static void enablePulseMeasurement(int port,
                                          boolean enabled)
Initializes digital input 7 or 8 for pulse measurement.

Parameters:
port - digital input port to initialize (7 or 8)
enabled - true enables pulse measurement, false disables pulse measurement

getAnalogInput

public static AnalogInput getAnalogInput(int portNumber)
Gets the AnalogInput object for the specified input port.

Parameters:
portNumber - input pin number
  • 0 thru 6 - general purpose analog inputs
  • 7 - thumbwheel
Returns:
AnalogInput for the port

getBoardType

public static byte getBoardType()
Returns the board type.

Returns:
board type (TYPE_HANDY_BOARD or TYPE_SUMO11)

getBuzzer

public static Speaker getBuzzer()
Gets the Speaker object for the buzzer. The buzzer on the Handy Board can play frequencies from 20 Hz to about 2 kHz.

Returns:
Speaker object for the peizo buzzer

getDigitalInput

public static DigitalInput getDigitalInput(int portNumber)
Gets the DigitalInput object for the specified input port.

Parameters:
portNumber - input pin number on the Handy Board
  • 7 thru 15 are general purpose inputs
  • 7 and 8 implement the PulseInput interface
  • 16 is the STOP button
  • 17 is the START button
Returns:
DigitalInput for the port

getDigitalOutput

public static DigitalOutput getDigitalOutput(int output)
Gets the DigitalOutput object for the specified output number.

Parameters:
output - output pin number
  • Handy Board: 9 (digital input 9 may be used as an output)
  • Handy Board w/expansion: 0 - 9
  • Sumo11: 8, 9
Returns:
DigitalOutput object

getEncoderCounts

public static int getEncoderCounts(int encoder)
Read the counts for the particular encoder.

Shaft encoders on the Handy Board are sampled once per millisecond. Therefore, the maximum rate which is supported is 500 counts per second.

Parameters:
encoder - encoder to read (0 to 2)
Returns:
encoder counts

getEncoderRate

public static int getEncoderRate(int encoder)
Read the current rate of the encoder counter.

Shaft encoders on the Handy Board are sampled once per millisecond. Therefore, the maximum rate which is supported is 500 counts per second. The maximum value this function can return is 7.

Parameters:
encoder - encoder to read (0 to 2)
Returns:
the number of counts in the last 128 millisecond sample period

getIrReceiver

public static IrReceiver getIrReceiver()
Gets the IrReceiver object for the infrared receiver.

Returns:
IrReceiver object

getLcdDisplay

public static Display getLcdDisplay()
Gets the Display object for the LCD.

The Display object may be used to print to a specific line or character position. Alternatively, the getOutputStream method can be used to print scrolling text to the LCD.

Returns:
Display object

getMotor

public static Motor getMotor(int motor)
Gets the Motor object for the specified motor.

Parameters:
motor - number of the motor (0 - 3)
Returns:
motor object

getOutputStream

public static OutputStream getOutputStream()
Gets the OutputStream for the LCD.

This method can be used in conjuntion with a PrintStream object to print scrolling output to the LCD.

The LCD can be addressed in line and character mode by using the getLcdDisplay method.

Returns:
OutputStream object

getServo

public static Servo getServo(int servo)
Gets the Servo object for a particular Handy Board servo. The Handy Board expansion board supports up to 8 servos, though the full electronics are only present for the first 6 servos. A single servo signal can be supported by a Handy Board without an expansion board by attaching the servo signal to TOC3 (Pin 7 on J3), powering the servo with a 6 volt power source and using this method specifying servo 0.

The Sumo11 expansion board supports up to 8 servos, though connectors are only provided for four. The left and right servo connectors on the main board are not supported by objects returned by this method. The left servo on the main board shares the TOC3 signal used by the expansion board servos. Therefore, the left main board servo port should not be used. The right servo port is connected to TOC2. This servo port could be used but is not supported by the objects returned by this method.

The objects returned by this method are intended to support Futuba compatible servos which are controlled by a 1 to 2 millisecond positioning pulse every 16 - 20 milliseconds. The pulse period is 18 ms.

Parameters:
servo - number of the servo (0 - 7)
Returns:
servo object

getShaftEncoder

public static ShaftEncoder getShaftEncoder(int encoder)
Gets the ShaftEncoder object for a particular quadrature shaft encoder.

Each shaft encoder uses a pair of digital inputs to implement a quadrature shaft encoder. The two pins should be connected to two digital sensors that generate a quadrature signal. The two sensors should be 90 degrees out of phase. If the counter counts in the opposite direction of what is expected, swap the two inputs.

Shaft encoders on the Handy Board are sampled once per millisecond. Therefore, the maximum counting rate which is supported is 500 counts per second.

On the Handy Board, the encoder rate value is updated every 128 milliseconds. The maximum value the getRate method can return is 7.

Parameters:
encoder - number of the encoder
  • 0 - pins 10 and 11
  • 1 - pins 12 and 13
  • 2 - pins 14 and 15

getStartButton

public static PushButton getStartButton()
Returns the PushButton object for the START button.

Returns:
START PushButton

getStopButton

public static PushButton getStopButton()
Returns the PushButton object for the STOP button.

Returns:
STOP PushButton

getThumbWheel

public static AnalogInput getThumbWheel()
Gets the AnalogInput object for the thumbwheel.

Returns:
AnalogInput for the thumbwheel

irRead

public static int irRead()
Reads a waiting character from the infrared receiver.

Returns:
most recent character recieved, or -1 if no data is available

irRxInitialize

public static void irRxInitialize(int startMin,
                                  int startMax,
                                  int shortMin,
                                  int threshold,
                                  int longMax,
                                  int numberOfBits,
                                  boolean invertBits,
                                  boolean reverseBits)
Initializes the receiver.

The infrared receiver supports infrared protocols which transmit data by transmitting a long start pulse followed by short and long data bit pulses.

Parameters:
startMin - minimum start bit length in microseconds
startMax - maximum start bit length in microseconds
shortMin - minimum short bit length in microseconds
threshold - threshold distinguishing short bit from long bit in microseconds
longMax - maximum long bit length
numberOfBits - number of bits frame
invertBits - true if short bits are 1s, false if long bits are 1s
reverseBits - true if frames arrive least significant bit first

isDigitalInputSet

public static boolean isDigitalInputSet(int portNumber)
Reads a digital input bit.

Parameters:
portNumber - number of the port (7 - 15)
Returns:
true if the bit is set, otherwise false

isDigitalOutputSet

public static boolean isDigitalOutputSet(int portNumber)
Returns the state of the specified digital output bit.

Parameters:
portNumber - digital output bit to toggle
  • Handy Board: 9 (digital input 9 may be used as an output)
  • Handy Board w/expansion: 0 - 9
  • Sumo11: 8, 9
  • setDigital9Direction(true) method must be called to configure digital 9 as an output

play

public static void play(int frequency,
                        int duration)
Plays the specified tone (frequency) using the buzzer.

The audible range for a human ear is about 20 Hz and 20 kHz. The range supported by the hardware on the Handy Board is approximately 20 Hz to about 2 kHz.

The frequencies of musical notes starting at middle C on a piano are:

The frequencies of notes double for each higher octave and are halved for each lower octave.

This method doesn't return until tone has been played.

Parameters:
frequency - frequency in Hz of the tone to play
duration - duration to play the tone for in milliseconds

pulseDigitalOutput

public static void pulseDigitalOutput(int portNumber,
                                      int duration)
Pulses the specified digital output bit.

Parameters:
portNumber - digital output bit to toggle
  • Handy Board: 9 (digital input 9 may be used as an output)
  • Handy Board w/expansion: 0 - 9
  • Sumo11: 8, 9
  • setDigital9Direction(true) method must be called to configure digital 9 as an output
duration - duration of the pulse in microseconds. This value should not be greater than 65,535.

readEdgeCount

public static int readEdgeCount(int port)
Returns the count of rising and falling edges detected on this input since pulse measurement was enabled by the enablePulseMeasurement method.

Parameters:
port - digital input port to read
Returns:
count of rising and falling edges detected on this input since pulse measurement was enabled

readPulseDuration

public static int readPulseDuration(int port)
Returns the duration of the last pulse, the value -1 will be returned if no pulse has completed since pulse intput was enabled or since the last read. The enablePulseMeasurement method must be called prior to using this method.

Parameters:
port - digital input port to read
Returns:
duration of last pulse in microseconds, or -1 if a full pulse has not occurred since the last read. The maximum measurable duration is 130 microseconds.

readPulseDuration

public static int readPulseDuration(int port,
                                    boolean highPulse)
Returns the duration of the last high pulse.

The method enablePulseMeasurement must be called prior to calling this method.

Parameters:
port - digital input port to read
highPulse - true for duration of high pulse, false for duration of low pulse
Returns:
duration of last pulse in microseconds, or -1 if a full pulse has not occurred since the last read.

readThumbWheel

public static int readThumbWheel()
Samples the thumbwheel analog input.

Returns:
sampled value between 0 and 255, inclusive

setBoardType

public static void setBoardType(byte type)
Tells the virtual machine what type of controller it is running on.

Motor, servo control, and digital out 8 are controlled differently between the Handy Board and Sumo11.

Note: This method must be called on Sumo11 boards prior to using any of these features.

Parameters:
type - TYPE_HANDY_BOARD or TYPE_SUMO11, defaults to TYPE_HANDY_BOARD on startup.

setDigital9Direction

public static void setDigital9Direction(boolean isOutput)
Sets the direction for digital port 9.

Port 9 may be used as an input or an output. By default it is configured as an input.

Parameters:
isOutput - true if digital 9 is to be configured for output, otherwise false

setDigitalOutput

public static void setDigitalOutput(int portNumber)
Set the specified digital output bit.

Parameters:
portNumber - digital output bit to toggle
  • Handy Board: 9 (digital input 9 may be used as an output)
  • Handy Board w/expansion: 0 - 9
  • Sumo11: 8, 9
  • setDigital9Direction(true) method must be called to configure digital 9 as an output

setMotorPower

public static void setMotorPower(int motor,
                                 int power)
Sets a motor's power.

Parameters:
power - The power level to set.
  • must be between -16 and 16, inclusive
  • positive is forward, negative is reverse and zero is coast

setServoPosition

public static void setServoPosition(int servo,
                                    int position)
Sets the position of the specified servo.

The Handy Board expansion board supports up to 8 servos, though the full electronics are only present for the first 6 servos. A single servo signal can be supported by a Handy Board without an expansion board by attaching the servo signal to TOC3 (Pin 7 on J3), powering the servo with a 6 volt power source and using this method specifying servo 0.

The Sumo11 expansion board supports up to 8 servos, though connectors are only provided for four. The left and right servo connectors on the main board are not supported by this method. The left servo on the main board shares the TOC3 signal used by the expansion board servos. Therefore, the left main board servo port should not be used. The right servo port is connected to TOC2. This servo port could be used but is not supported via this method.

On the Handy Board, TOC2 is used to control the IR transmitter.

This method is intended to support Futuba compatible servos which are controlled by a 1 to 2 millisecond positioning pulse every 16 - 20 milliseconds. The pulse period is 18 ms.

Parameters:
servo - number of the servo (0 - 7)
position - position of the servo in percent. (0 = 1 ms positioning pulse, 100 = 2 ms positioning pulse, -1 = no pulse, servo off)

setTerminateOnStop

public static void setTerminateOnStop(boolean terminateOnStop)
Configures whether the virtual machine terminates the program when the STOP button is pressed.

The initial setting when the program starts is true.

Parameters:
terminateOnStop - true if the program should terminate when the STOP button is pressed.

startPressed

public static boolean startPressed()
Returns true if the START button is pressed.

Returns:
true if START pressed, otherwise false

stopPressed

public static boolean stopPressed()
Returns true if the STOP button is pressed.

Returns:
true if STOP pressed, otherwise false

toggleDigitalOutput

public static void toggleDigitalOutput(int portNumber)
Toggles the specified digital output bit.

Parameters:
portNumber - digital output bit to toggle
  • Handy Board: 9 (digital input 9 may be used as an output)
  • Handy Board w/expansion: 0 - 9
  • Sumo11: 8, 9
  • setDigital9Direction(true) method must be called to configure digital 9 as an output

RoboJDETM v2.0

Copyright (c) 2003-2009 RidgeSoft, LLC. All rights reserved.
www.ridgesoft.com