maslab.orc
Class Orc

java.lang.Object
  extended by maslab.orc.Orc

public class Orc
extends java.lang.Object

Low-level access to the OrcBoard; when possible, use a wrapper class.


Nested Class Summary
static class Orc.DrawMode
           
static class Orc.LcdFont
           
static class Orc.MotorDirection
          Motor Direction constants, for use with motorSet.
static class Orc.PinMode
          Pin modes, for use with pinModeSet
 
Field Summary
static int BUTTON_DOWN
           
static int BUTTON_LEFT
           
static int BUTTON_MENU
          Bit field mask for the Pad's Menu button
static int BUTTON_RIGHT
           
static int BUTTON_STICK
          Bit field mask for the Pad's Stick button
static int BUTTON_STOP
          Bit field mask for the Pad's Stop button
static int BUTTON_UP
           
 
Constructor Summary
Orc()
          Create a new Orc object, connecting to localhost on the default ports (7320, 7321)
Orc(java.lang.String host)
           
Orc(java.lang.String host, int cmdport, int asyncport)
          Create a new Orc object.
 
Method Summary
 void addUpdateListener(OrcUpdateListener ul)
          Add an OrcUpdateListener.
 void allStop()
          Perform an emergency allStop.
 int analogLPFRead(int port)
          Read the current low-pass filter value.
 void analogLPFWrite(int port, int val)
          Configure the analog low-pass filter for a port.
 double analogRead(int port)
          ports 0-19 correspond to numbered ports.
 long clockRead()
          Read the Orc board's internal clock, a 16 bit counter updating at 512 Hz.
 int dacRead(int port)
          Read the DAC (digital-to-analog) NOT IMPLEMENTED.
 void dacWrite(int port, int v)
          Write to the DAC (digital-to-analog).
static int diff16(long a, long b)
          Compute a-b, accounting for wraparound with 16 bit numbers.
static long diff32(long a, long b)
          Compute a-b, accounting for wraparound with 32 bit numbers.
 boolean digitalRead(int port)
          Read the digital port.
 void digitalWrite(int port, boolean v)
          Write the digital port.
 long gyroReadRaw()
          Read the raw gyro integrator value.
 boolean i2cRead(int addr, byte[] buf, int len)
          Perform an I2C Read transaction REQUIRES FIRMWARE UPGRADE.
 boolean i2cWrite(int addr, byte[] buf, int len)
          Perform an I2C Write transaction REQUIRES FIRMWARE UPGRADE.
 boolean i2cWriteRead(int addr, byte[] writebuf, int writelen, byte[] readbuf, int readlen)
          Perform a combined write/read I2C transaction UNTESTED.
 int joyX()
          Returns the Pad's current joystick position (X axis)
 int joyY()
          Returns the Pad's current joystick position (Y axis)
 void lcdClear()
          Clear the LCD
 void lcdConsoleGoto(int x, int y)
          Move the console cursor position.
 void lcdConsoleHome()
          Clear the portion of the lcd being used by the console, and move the cursor to the top left position.
 void lcdConsoleSettings(int top, int height, int left, int width)
          Set the console size and location.
 void lcdConsoleWrite(java.lang.String s)
          Write text to the console at the current cursor position.
 void lcdDrawLine(int x0, int y0, int x1, int y1)
          Draw a line.
 void lcdDrawMode(Orc.DrawMode dm)
          Set the draw mode.
 void lcdDrawText(Orc.LcdFont font, int x, int y, java.lang.String s)
          Draw text at an arbitrary location.
 void lcdFill(int even, int odd)
          Fill the entire LCD with a pattern.
 java.awt.image.BufferedImage lcdRead()
          Read the entire LCD frame buffer.
 void lcdRead(int x, int y, int length, byte[] buf, int offset)
          Read the LCD's frame buffer.
 void lcdWrite(int xi, int yi, java.awt.image.BufferedImage i)
          Draw an image on the lcd.
 void lcdWrite(int x, int y, byte[] buf, int blocksize)
          Write to the LCD's frame buffer.
 Orc.MotorDirection motorActualDirectionRead(int port)
          Returns the motor's actual direction.
 int motorActualRead(int port)
          Read the motor's current PWM.
 double motorCurrentRead(int port)
          Returns the current consumption for the motor.
 Orc.MotorDirection motorGoalDirectionRead(int port)
          Returns the motor's goal direction.
 int motorGoalRead(int port)
          Read the motor's current goal PWM
 int motorSlewRead(int port)
          Returns the current slew rate.
 void motorSlewWrite(int port, int slew)
          Set the rate at which motors can change the PWM.
 void motorWrite(int port, int pwm)
          Set a motor's goal speed and direction.
 void motorWrite(int port, int pwm, Orc.MotorDirection dir)
          Set a motor's goal speed and direction.
 int padButtonsGet()
          Wait for a button to be pressed and released, and return it.
 int padButtonsPoll()
          Test the current status of the buttons and return immediately.
 Orc.PinMode pinModeRead(int port)
          Determine the new pin mode.
 void pinModeWrite(int port, Orc.PinMode m)
          Configure a port.
 int pwmDutyCycleRead(int port)
          NOT IMPLEMENTED.
 int pwmPeriodRead(int port)
          NOT IMPLEMENTED.
 int pwmSourceRead(int port)
          NOT IMPLEMENTED.
 void pwmWrite(int port, int source, int period, int dutycycle)
          NOT IMPLEMENTED.
 int quadphaseErrorsRead(int port)
          Returns the number of errors that have occured on the quadphase port.
 int quadphaseRead(int port)
          Read the quadphase/monophase counter.
 void removeUpdateListener(OrcUpdateListener ul)
          Remove an OrcUpdateListener.
 double servoCurrentRead(int port)
          Returns the current consumption for the servo.
 int servoRead(int port)
          Read the servo's current position.
 void servoWrite(int port, int v)
          Write the servo's position.
 void setCacheLifetime(int ms)
          Set the maximum number of milliseconds that the cache will be used for.
 void ultrasoundPing(int port)
          Initiate a new ultrasound ping.
 int ultrasoundPingCount(int port)
          Returns a continuously running 4bit counter of the number of pings on this port
 double ultrasoundRange(int port)
          Determine the range for an ultrasound ping.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUTTON_STICK

public static final int BUTTON_STICK
Bit field mask for the Pad's Stick button

See Also:
Constant Field Values

BUTTON_MENU

public static final int BUTTON_MENU
Bit field mask for the Pad's Menu button

See Also:
Constant Field Values

BUTTON_STOP

public static final int BUTTON_STOP
Bit field mask for the Pad's Stop button

See Also:
Constant Field Values

BUTTON_UP

public static final int BUTTON_UP
See Also:
Constant Field Values

BUTTON_DOWN

public static final int BUTTON_DOWN
See Also:
Constant Field Values

BUTTON_LEFT

public static final int BUTTON_LEFT
See Also:
Constant Field Values

BUTTON_RIGHT

public static final int BUTTON_RIGHT
See Also:
Constant Field Values
Constructor Detail

Orc

public Orc()
    throws java.io.IOException
Create a new Orc object, connecting to localhost on the default ports (7320, 7321)

Throws:
java.io.IOException

Orc

public Orc(java.lang.String host)
    throws java.io.IOException
Throws:
java.io.IOException

Orc

public Orc(java.lang.String host,
           int cmdport,
           int asyncport)
    throws java.io.IOException
Create a new Orc object.

Parameters:
host - The host to connect to
cmdport - The TCP port for command connections
asyncport - The TCP port for async event connections
Throws:
java.io.IOException
Method Detail

setCacheLifetime

public void setCacheLifetime(int ms)
Set the maximum number of milliseconds that the cache will be used for. Set to 0 to disable the cache.


motorGoalDirectionRead

public Orc.MotorDirection motorGoalDirectionRead(int port)
Returns the motor's goal direction.

Parameters:
port - [0,3]

motorActualDirectionRead

public Orc.MotorDirection motorActualDirectionRead(int port)
Returns the motor's actual direction.

Parameters:
port - [0,3]

motorActualRead

public int motorActualRead(int port)
Read the motor's current PWM.


motorGoalRead

public int motorGoalRead(int port)
Read the motor's current goal PWM


motorCurrentRead

public double motorCurrentRead(int port)
Returns the current consumption for the motor.

Parameters:
port - [0,3]
Returns:
The current, in amps.

servoCurrentRead

public double servoCurrentRead(int port)
Returns the current consumption for the servo.

Parameters:
port - [0,3]
Returns:
The current, in amps.

analogRead

public double analogRead(int port)
ports 0-19 correspond to numbered ports. (Some of these can't do analog in.) 20-25 correspond to curent-sense inputs on motors0-3 and servos0-1


analogLPFWrite

public void analogLPFWrite(int port,
                           int val)
Configure the analog low-pass filter for a port.

Parameters:
port - [0,19] that supports analog in.
val - [0,10]. The parameter of the low-pass filter, higher numbers representing much stronger filtering.

analogLPFRead

public int analogLPFRead(int port)
Read the current low-pass filter value.

Parameters:
port - [0,19] that supports analog in.

dacRead

public int dacRead(int port)
Read the DAC (digital-to-analog) NOT IMPLEMENTED.

Parameters:
port - [12]
Returns:
v [0,255]

dacWrite

public void dacWrite(int port,
                     int v)
Write to the DAC (digital-to-analog).

Parameters:
port - [12]
v - [0,255]

digitalRead

public boolean digitalRead(int port)
Read the digital port.

Parameters:
port - [0,19]

digitalWrite

public void digitalWrite(int port,
                         boolean v)
Write the digital port.

Parameters:
port - [0,19]
v - The value

servoRead

public int servoRead(int port)
Read the servo's current position.

Parameters:
port - [0,3]
Returns:
The PWM value, [0,65535]

servoWrite

public void servoWrite(int port,
                       int v)
Write the servo's position.

Parameters:
port - [0,3]
v - [0,65535] The PWM value.

ultrasoundPing

public void ultrasoundPing(int port)
Initiate a new ultrasound ping.

Parameters:
port - The port, 4 or 6.

ultrasoundRange

public double ultrasoundRange(int port)
Determine the range for an ultrasound ping.

Parameters:
port - The port, 5 or 7.
Returns:
The range, assuming speed of sound of 33146 cm/s. If the measurement is still in progress, returns zero.

ultrasoundPingCount

public int ultrasoundPingCount(int port)
Returns a continuously running 4bit counter of the number of pings on this port


pinModeWrite

public void pinModeWrite(int port,
                         Orc.PinMode m)
Configure a port. Check which modes are possible before calling.

Parameters:
port - The port, [0,19].
m - The mode.

pinModeRead

public Orc.PinMode pinModeRead(int port)
Determine the new pin mode.

Parameters:
port - The port, [0,19].

pwmWrite

public void pwmWrite(int port,
                     int source,
                     int period,
                     int dutycycle)
NOT IMPLEMENTED.


pwmSourceRead

public int pwmSourceRead(int port)
NOT IMPLEMENTED.


pwmPeriodRead

public int pwmPeriodRead(int port)
NOT IMPLEMENTED.


pwmDutyCycleRead

public int pwmDutyCycleRead(int port)
NOT IMPLEMENTED.


quadphaseErrorsRead

public int quadphaseErrorsRead(int port)
Returns the number of errors that have occured on the quadphase port. A small number of errors can be expected, but a large number of errors means the sensor is not working properly or is counting too quickly. This value is meaningless for monophase ports.

Parameters:
port - The port, [16,19].

quadphaseRead

public int quadphaseRead(int port)
Read the quadphase/monophase counter.

Parameters:
port - The port, [16,19].

allStop

public void allStop()
Perform an emergency allStop. The Orc board will become unresponsive after calling this function.


motorWrite

public void motorWrite(int port,
                       int pwm,
                       Orc.MotorDirection dir)
Set a motor's goal speed and direction.

Parameters:
port - [0,3]
pwm - [0,255]. For directions other than disabled, low pwms imply braking.
dir - The direction

motorWrite

public void motorWrite(int port,
                       int pwm)
Set a motor's goal speed and direction.

Parameters:
port - [0,3]
pwm - [-255,255]. Negative PWMs correspond to backwards, positive PWM to forwards. The motor is never disabled with this API.

motorSlewWrite

public void motorSlewWrite(int port,
                           int slew)
Set the rate at which motors can change the PWM. When motors are written, it only changes the goal speed and direction. The actual speed and direction change more gradually, according to the slew rate. Larger slew rates mean that the PWM changes faster.

Parameters:
port - [0,3]
slew - [1,255]. Motor speeds are updated at 64Hz, so the worst case slewing interval is seconds=512/(64*slew).

motorSlewRead

public int motorSlewRead(int port)
Returns the current slew rate.

Parameters:
port - [0,3]

padButtonsGet

public int padButtonsGet()
Wait for a button to be pressed and released, and return it.

Returns:
the logical OR of all simultaneously pressed buttons.

padButtonsPoll

public int padButtonsPoll()
Test the current status of the buttons and return immediately.

Returns:
the logical OR of all the buttons currently depressed. The corresponding bit is 1 if the button is depressed.

joyX

public int joyX()
Returns the Pad's current joystick position (X axis)


joyY

public int joyY()
Returns the Pad's current joystick position (Y axis)


lcdClear

public void lcdClear()
Clear the LCD


lcdConsoleGoto

public void lcdConsoleGoto(int x,
                           int y)
Move the console cursor position.


lcdConsoleWrite

public void lcdConsoleWrite(java.lang.String s)
Write text to the console at the current cursor position.


lcdFill

public void lcdFill(int even,
                    int odd)
Fill the entire LCD with a pattern. See the orcmanual for documentation on this function.


lcdDrawLine

public void lcdDrawLine(int x0,
                        int y0,
                        int x1,
                        int y1)
Draw a line.


lcdConsoleHome

public void lcdConsoleHome()
Clear the portion of the lcd being used by the console, and move the cursor to the top left position.


lcdConsoleSettings

public void lcdConsoleSettings(int top,
                               int height,
                               int left,
                               int width)
Set the console size and location. Note that the units for the parameters are in characters, columns, and rows-- not pixles. There are a total of eight rows, and approximately 32 columns usable for the console. In general, the top status bar consumes the top line.

Parameters:
top - The top line of the console, [0,7]
height - The number of lines in the console, [0,7].
left - The leftmost column of the console [0,31]
width - The number of columns in the console.

lcdDrawMode

public void lcdDrawMode(Orc.DrawMode dm)
Set the draw mode. This command affects line and pixel drawing commands, and is reset to DrawMode.DRAW by a screen clear.


lcdDrawText

public void lcdDrawText(Orc.LcdFont font,
                        int x,
                        int y,
                        java.lang.String s)
Draw text at an arbitrary location.

Parameters:
font - The font to draw in
x - The x location (in pixels), [0, 127]
y - The y location (in pixels), [0, 63]
s - The string to write, no more than 32 characters long.

lcdRead

public void lcdRead(int x,
                    int y,
                    int length,
                    byte[] buf,
                    int offset)
Read the LCD's frame buffer. Reads a horizontal swath of pixels, 8 pixels high.

Parameters:
x - The x offset to begin reading from.
y - The y offset to begin reading from. Must be a multiple of 8.
length - The number of bytes to read.
buf - The buffer to deposit the data into
offset - The offset in the buffer

lcdWrite

public void lcdWrite(int x,
                     int y,
                     byte[] buf,
                     int blocksize)
Write to the LCD's frame buffer. Writes a horizontal swath of pixels, 8 pixels high.

Parameters:
x - The x offset to begin writing from.
y - The y offset to begin writing from. Must be a multiple of 8.
buf - The buffer to get the data from
blocksize - The number of bytes to use from the buffer

lcdRead

public java.awt.image.BufferedImage lcdRead()
Read the entire LCD frame buffer. This function is fairly slow.

Returns:
A 128x64 BufferedImage in TYPE_BYTE_GRAY format.

lcdWrite

public void lcdWrite(int xi,
                     int yi,
                     java.awt.image.BufferedImage i)
Draw an image on the lcd.

Parameters:
xi - The top left x coordinate, [0,127]
yi - The top left y coordinate, [0,63] and a multiple of 8.
i - The image. For good results, the image should be reduced to dithered black and white. This procedure uses only the green channel to determine whether a pixel should be on or off.

clockRead

public long clockRead()
Read the Orc board's internal clock, a 16 bit counter updating at 512 Hz.


gyroReadRaw

public long gyroReadRaw()
Read the raw gyro integrator value. This is not calibrated, and not intended for use by mere mortals.


i2cRead

public boolean i2cRead(int addr,
                       byte[] buf,
                       int len)
Perform an I2C Read transaction REQUIRES FIRMWARE UPGRADE.

Parameters:
addr - I2C Address, [0,127]
buf - Buffer to deposit data into
len - Length of read (<64)
Returns:
true if read succeeds.

i2cWrite

public boolean i2cWrite(int addr,
                        byte[] buf,
                        int len)
Perform an I2C Write transaction REQUIRES FIRMWARE UPGRADE.

Parameters:
addr - I2C Address, [0,127]
buf - Buffer to data to write
len - Length of write (<64)
Returns:
true if write succeeds.

i2cWriteRead

public boolean i2cWriteRead(int addr,
                            byte[] writebuf,
                            int writelen,
                            byte[] readbuf,
                            int readlen)
Perform a combined write/read I2C transaction UNTESTED. REQUIRES FIRMWARE UPGRADE.

Parameters:
addr - I2C Address, [0,127]
writebuf - The buffer which will be written first
writelen - The length of the buffer (<64)
readbuf - The buffer in which to deposit read data
readlen - The number of bytes to read (<64)
Returns:
true if the transaction succeeds.

diff16

public static int diff16(long a,
                         long b)
Compute a-b, accounting for wraparound with 16 bit numbers.


diff32

public static long diff32(long a,
                          long b)
Compute a-b, accounting for wraparound with 32 bit numbers.


addUpdateListener

public void addUpdateListener(OrcUpdateListener ul)
Add an OrcUpdateListener. It will be notified whenever the Orc publishes new data on a different thread.


removeUpdateListener

public void removeUpdateListener(OrcUpdateListener ul)
Remove an OrcUpdateListener.