|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectch.aplu.nxt.NxtRobot
public class NxtRobot
Class that represents a NXT robot brick. Parts (e.g. motors, sensors) may
be assembled into the robot to make it doing the desired job.
More than one instance may be created. They are indentified by different
Bluetooth names (or addresses).
The Bluetooth communication uses the Bluecove library and is fully standalone
and portable. No serial port emulation (RFCOMM) and no Bluetooth Control Center (BCC)
is used. The Bluecove library supports only interfaces with Widcomm compatibility.
If more than one brick is used at the same time, the Bluetooth interface
must be capable to establish more than one Bluetooth link (e.g. Anycom USB adapter,
Part.No: CC-3036).
NxtJlib implements the usual Java event handling model using event listeners
and adapters. The sensors are polled at a regular interval from a internal
thread and the registered callback method is invoked, when the event condition
is fullfilled (e.g. sensor value crosses a given trigger level).
Many library options are defined in a property file 'nxtjlib.properties' that
may be modified as needed. The property file is searched in the following order:
- Application directory (user.dir)
- Home directory (user.home)
- NxtJLib.jar (distribution)
As soon as the property file is found, the search is cancelled. This allows
to use a personalized property file without deleting or modifing the distributed
file in NxtJLib.jar. Consult the distributed file for more information.
Be careful to keep the original formatting.
If the property KeepAlive is set to 1, a thread is started that sends keep
alive commands every 500 s in order to prevent the automatic shutdown of the NXT.
Field Summary |
---|
Constructor Summary | |
---|---|
NxtRobot()
Asks for the Bluetooth name and creates a NxtRobot instance. |
|
NxtRobot(long btAddress)
Creates a NxtRobot instance with given Bluetooth address. |
|
NxtRobot(long btAddress,
boolean connect)
Creates a NxtRobot instance with given Bluetooth address. |
|
NxtRobot(java.lang.String btName)
Creates a NxtRobot instance with given Bluetooth name. |
|
NxtRobot(java.lang.String btName,
boolean connect)
Creates a NxtRobot instance with given Bluetooth name. |
Method Summary | |
---|---|
void |
addPart(Part part)
Assembles the given part into the robot. |
boolean |
connect()
Connects the host to the robot via Bluetooth. |
boolean |
connect(boolean isConnectPane)
Connects the host to the robot via Bluetooth. |
boolean |
connect(boolean isConnectPane,
boolean isAnnounce)
Connects the host to the robot via Bluetooth. |
boolean |
disconnect()
Cuts the Bluetooth communication. |
void |
exit()
Cuts the Bluetooth communication and terminates the program. |
boolean |
fileExists(java.lang.String filename)
Searches for given file in the brick's file system. |
FileInfo |
findFirst()
Start file enumeration in the brick's file system. |
FileInfo |
findNext(byte handle)
Searches the next file in a file enumeration. |
static java.lang.String |
getAbout()
Returns copywrite information. |
double |
getBatteryLevel()
Returns the battery level. |
java.lang.String |
getBtAddress()
Returns the Bluetooth address (hex). |
long |
getBtAddressLong()
Returns the Bluetooth address (long). |
java.lang.String |
getBtName()
Returns the Bluetooth name |
static int |
getDebugLevel()
Returns the current debug level. |
java.lang.String |
getFriendlyName()
Sends a request to the brick to get the Bluetooth friendly name. |
java.io.InputStream |
getInputStream()
Returns the InputStream reference of the Bluetooth connection. |
protected ch.aplu.nxt.InputValues |
getInputValues(int portId)
Reads the values from given a sensor port. |
protected ch.aplu.nxt.OutputState |
getOutputState(int port)
Retrieves the current output state of a specific port. |
java.io.OutputStream |
getOutputStream()
Returns the OutputStream reference of the Bluetooth connection. |
static NxtProperties |
getProperties()
Returns the properties from the NxtJLib property file. |
javax.microedition.io.StreamConnection |
getStreamConnection()
Returns the StreamConnection reference of the Bluetooth connection. |
static java.lang.String |
getVersion()
Returns library version information. |
boolean |
isConnected()
Returns the connection state. |
void |
keepAlive()
Sends a keep alive command to prevent the automatic shutdown of the brick. |
void |
playConnectMelody()
Plays a standard connect melody. |
void |
playDisconnectMelody()
Plays a standard disconnect melody. |
void |
playTone(int frequency,
int duration)
Plays a tone with given frequency (in Hertz) and duration (in seconds). |
byte[] |
readData()
Reads the data returned as a reply from the brick. |
byte[] |
requestData(byte[] request)
Combines sendData() and readData() in synchronized block. |
void |
sendData(byte[] command)
Sends a direct command to the brick. |
void |
setChannel(int channel)
Sets the Bluetooth channel (default: 1). |
protected void |
setInputMode(int portId,
int sensorType,
int sensorMode)
|
protected void |
setOutputState(int portId,
byte power,
int mode,
int regulationMode,
int turnRatio,
int runState,
int tachoLimit)
Sets the output state of a specific sensor port. |
boolean |
startProgram(java.lang.String filename)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public NxtRobot(java.lang.String btName, boolean connect)
btName
- the Bluetooth friedly name of the brick, e.g. "NXT"connect
- if true, a connection trial is engagedpublic NxtRobot(java.lang.String btName)
btName
- the Bluetooth friedly name of the brick, e.g. "NXT"public NxtRobot(long btAddress, boolean connect)
btAddress
- the Bluetooth address of the brick, e.g. 0x0000A762B001connect
- if true, a connection trial is engagedpublic NxtRobot(long btAddress)
btAddress
- the Bluetooth address of the brick, e.g. 0x0000A762B001public NxtRobot()
Method Detail |
---|
public void setChannel(int channel)
channel
- the channel numberpublic static NxtProperties getProperties()
public static int getDebugLevel()
public void addPart(Part part)
part
- the part to assemblepublic boolean connect()
public boolean connect(boolean isConnectPane)
isConnectPane
- if true an information pane is shown
public boolean connect(boolean isConnectPane, boolean isAnnounce)
isConnectPane
- if true, an information pane is shownisAnnounce
- if true, a connect/disconnect melody is played
public boolean disconnect()
public void exit()
public void playConnectMelody()
public void playDisconnectMelody()
public javax.microedition.io.StreamConnection getStreamConnection()
public java.io.InputStream getInputStream()
public java.io.OutputStream getOutputStream()
public java.lang.String getFriendlyName()
public byte[] requestData(byte[] request)
request
- the data to send
public void sendData(byte[] command)
command
- the data to sendpublic byte[] readData()
protected void setOutputState(int portId, byte power, int mode, int regulationMode, int turnRatio, int runState, int tachoLimit)
protected ch.aplu.nxt.OutputState getOutputState(int port)
port
- (0,..,3)
protected void setInputMode(int portId, int sensorType, int sensorMode)
protected ch.aplu.nxt.InputValues getInputValues(int portId)
portId
- the Id of the sensor port (0,..3)public boolean isConnected()
public void playTone(int frequency, int duration)
public double getBatteryLevel()
public java.lang.String getBtAddress()
public java.lang.String getBtName()
public long getBtAddressLong()
public static java.lang.String getVersion()
public static java.lang.String getAbout()
public void keepAlive()
NxtRobot
public boolean startProgram(java.lang.String filename)
public FileInfo findFirst()
public FileInfo findNext(byte handle)
handle
- the handle of the previous found file
public boolean fileExists(java.lang.String filename)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |