EDU.cmu.cs.coral.cye
Class JCyeComm

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--EDU.cmu.cs.coral.cye.JCyeComm

public class JCyeComm
extends java.lang.Thread

Handles all of the communication between the JCyeSrv class and the Cye robot. Thread is extended, to enable the CyeComm object to run in the background and poll the robot at a set frequency. If you are creating an instance of this class manually in your code, you are almost certainly doing something wrong. This class should only be created as a side effect of instantiating a JCyeSrv object.

See Also:
Thread, JCyeSrv, JCyeMsg, JCyeStatus

Field Summary
static byte BLACK_ROBOT
          Indicates the connection is to a newer black robot;
static byte CHROME_ROBOT
          Indicates the connection is to a newer chrom robot;
static int NEW_RADIO
          Indicates the connection is via new radio (must send a bunch of padding chars).
static int OLD_RADIO
          Indicates the connection is via old radio (must wait for warm up).
static byte ORANGE_ROBOT
          Indicates the connection is to a newer orange robot;
static byte ORIGINAL_ROBOT
          Indicates the connection is to an original robot.
static int WIRED
          Indicates the connection to the robot is wired (no radio warm up reqd).
static byte YELLOW_ROBOT
          Indicates the connection is to a newer yellow robot;
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected JCyeComm(java.lang.String d, int b, int c, byte i)
          The constructor for class JCyeComm.
 
Method Summary
protected  void ClearObstacle()
          Resets the obstacle detector.
protected  double GetLastB()
          Returns the last reported battery voltage of el roboto.
protected  int GetLastH()
          Returns the last reported heading of el roboto.
protected  int GetLastX()
          Returns the last reported X position of el roboto.
protected  int GetLastY()
          Returns the last reported Y position of el roboto.
protected  boolean GetObstacle()
          Returns the status of the obstacle detector.
 void run()
          The background run method for JCyeComm.
protected  JCyeMsg SendMsg(JCyeMsg Msg)
          Sends a message (represented as an object of class JCyeMsg) to the Cye robot, and waits for an acknowledgement or retry failure.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

WIRED

public static final int WIRED
Indicates the connection to the robot is wired (no radio warm up reqd).

OLD_RADIO

public static final int OLD_RADIO
Indicates the connection is via old radio (must wait for warm up).

NEW_RADIO

public static final int NEW_RADIO
Indicates the connection is via new radio (must send a bunch of padding chars).

ORIGINAL_ROBOT

public static final byte ORIGINAL_ROBOT
Indicates the connection is to an original robot.

BLACK_ROBOT

public static final byte BLACK_ROBOT
Indicates the connection is to a newer black robot;

ORANGE_ROBOT

public static final byte ORANGE_ROBOT
Indicates the connection is to a newer orange robot;

YELLOW_ROBOT

public static final byte YELLOW_ROBOT
Indicates the connection is to a newer yellow robot;

CHROME_ROBOT

public static final byte CHROME_ROBOT
Indicates the connection is to a newer chrom robot;
Constructor Detail

JCyeComm

protected JCyeComm(java.lang.String d,
                   int b,
                   int c,
                   byte i)
            throws JCyeException
The constructor for class JCyeComm. Initializes the serial port driver, then carries out the ISTART/ASTART sequence to initialize the robot.
Parameters:
d - the name of the serial device to open.
b - baud rate (9600 or 19200).
c - connection type (WIRED or OLD_RADIO or NEW_RADIO).
i - ID number.
Method Detail

SendMsg

protected JCyeMsg SendMsg(JCyeMsg Msg)
Sends a message (represented as an object of class JCyeMsg) to the Cye robot, and waits for an acknowledgement or retry failure.
Parameters:
Msg - the JCyeMsg to send to the robot.
Returns:
the acknowledgement message from the robot, represented as an object of type JCyeMsg.

run

public void run()
The background run method for JCyeComm. This method polls the robot (with a CMD_POLL_REQUEST message, then goes back to sleep for SLEEP_TIME ms.
Overrides:
run in class java.lang.Thread

GetLastX

protected int GetLastX()
Returns the last reported X position of el roboto.
Returns:
the X position

GetLastY

protected int GetLastY()
Returns the last reported Y position of el roboto.
Returns:
the Y position

GetLastH

protected int GetLastH()
Returns the last reported heading of el roboto.
Returns:
the heading

GetLastB

protected double GetLastB()
Returns the last reported battery voltage of el roboto.
Returns:
the battery voltage

GetObstacle

protected boolean GetObstacle()
Returns the status of the obstacle detector. If an obstacle has been hit since the last call to ClearObstacle, return true.
Returns:
the obstacle detector status.

ClearObstacle

protected void ClearObstacle()
Resets the obstacle detector. Call this method to reset the detection logic.