public class NxtRobot
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
NxtRobot.ConnectState
Enum that defines return values for the connect() method.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ABOUT |
static byte |
ANGLE |
static byte |
ANGLESTEPSMODE |
static double |
AXE_LENGTH
Axe length (in m) used by Gear.leftArc(), Gear.rightArc()
|
static byte |
BOOLEANMODE |
static byte |
BOOT |
static byte |
BRAKE |
static byte |
CELSIUSMODE |
static byte |
CLOSE |
static int |
COMPASS_SENSOR_POLL_DELAY |
static double |
CRAWLER_ROTATION_FACTOR
Factor between crawler robot angle (in degrees) and motor rotation count
|
static int |
CRAWLER_ROTATION_SPEED
Turtle crawler speed for rotations
|
static int |
CRAWLER_SPEED
Turtle crawler speed for straight movements
|
static double |
CRAWLER_STEP_FACTOR
Factor between turtle crawler steps and motor rotation count
|
static byte |
CUSTOM |
static byte |
DELETE |
static byte |
DELETE_USER_FLASH |
static byte |
DIRECT_COMMAND_NOREPLY |
static byte |
DIRECT_COMMAND_REPLY |
static byte |
FAHRENHEITMODE |
static byte |
FIND_FIRST |
static byte |
FIND_NEXT |
static int |
GEAR_ACCELERATION_DELAY
Time to wait between increasing/decreasing speed steps in Gear.moveTo()
|
static int |
GEAR_BRAKE_DELAY
Time to wait between succeeding movement calls before stop
|
static int |
GEAR_SPEED
Default gear speed
|
static byte |
GET_BATTERY_LEVEL |
static byte |
GET_CURRENT_PROGRAM_NAME |
static byte |
GET_DEVICE_INFO |
static byte |
GET_FIRMWARE_VERSION |
static byte |
GET_INPUT_VALUES |
static byte |
GET_OUTPUT_STATE |
static byte |
HIGH_SPEED_BUFFER |
static byte |
KEEP_ALIVE |
static byte |
LIGHT_ACTIVE |
static byte |
LIGHT_INACTIVE |
static int |
LIGHT_SENSOR_POLL_DELAY |
static byte |
LOWSPEED |
static byte |
LOWSPEED_9V |
static byte |
LS_GET_STATUS |
static byte |
LS_READ |
static byte |
LS_WRITE |
static byte |
MESSAGE_READ |
static byte |
MESSAGE_WRITE |
static byte |
MODEMASK |
static int |
MOTION_DETECTOR_POLL_DELAY |
static byte |
MOTOR_RUN_STATE_IDLE |
static byte |
MOTOR_RUN_STATE_RAMPDOWN |
static byte |
MOTOR_RUN_STATE_RAMPUP |
static byte |
MOTOR_RUN_STATE_RUNNING |
static int |
MOTOR_SPEED
Default motor speed
|
static double |
MOTOR_SPEED_FACTOR
Factor between speed and velocity (in m/s): velocity = MotorSpeedFactor * speed
|
static byte |
MOTORON |
static byte |
NO_OF_SENSOR_TYPES |
static byte |
NO_SENSOR |
static byte |
NXJ_FIND_FIRST |
static byte |
NXJ_FIND_NEXT |
static byte |
OPEN_APPEND_DATA |
static byte |
OPEN_READ |
static byte |
OPEN_READ_LINEAR |
static byte |
OPEN_WRITE |
static byte |
OPEN_WRITE_DATA |
static byte |
OPEN_WRITE_LINEAR |
static byte |
PCTFULLSCALEMODE |
static byte |
PERIODCOUNTERMODE |
static byte |
PLAY_SOUND_FILE |
static byte |
PLAY_TONE |
static byte |
POLL |
static byte |
POLL_BUFFER |
static byte |
POLL_LENGTH |
static byte |
RAWMODE |
static byte |
READ |
static byte |
REFLECTION |
static byte |
REGULATED |
static byte |
REGULATION_MODE_IDLE |
static byte |
REGULATION_MODE_MOTOR_SPEED |
static byte |
REGULATION_MODE_MOTOR_SYNC |
static byte |
REPLY_COMMAND |
static byte |
RESET_MOTOR_POSITION |
static byte |
RESET_SCALED_INPUT_VALUE |
static byte |
SET_BRICK_NAME |
static byte |
SET_INPUT_MODE |
static byte |
SET_OUTPUT_STATE |
static byte |
SLOPEMASK |
static byte |
SOUND_DB |
static byte |
SOUND_DBA |
static int |
SOUND_SENSOR_POLL_DELAY
Wait time (in ms) between polling the sensor value when registering an event handler
|
static byte |
START_PROGRAM |
static byte |
STOP_PROGRAM |
static byte |
STOP_SOUND_PLAYBACK |
static byte |
SWITCH |
static byte |
SYSTEM_COMMAND_NOREPLY |
static byte |
SYSTEM_COMMAND_REPLY |
static byte |
TEMPERATURE |
static int |
TOUCH_SENSOR_POLL_DELAY |
static byte |
TRANSITIONCNTMODE |
static double |
TURTLE_ROTATION_FACTOR
Factor between turtle angle (in degrees) and motor rotation count
|
static int |
TURTLE_ROTATION_SPEED
Turtle speed for rotations
|
static int |
TURTLE_SPEED
Turtle speed for straight movements
|
static double |
TURTLE_STEP_FACTOR
Factor between turtle steps and motor rotation count
|
static int |
ULTRASONIC_SENSOR_POLL_DELAY |
static java.lang.String |
VERSION |
static byte |
WRITE |
Constructor and Description |
---|
NxtRobot(android.app.Activity activity)
Opens a GGInputDialog to ask for the Bluetooth friendly name of the NXT brick
and creates a NxtRobot instance.
|
NxtRobot(android.app.Activity activity,
android.bluetooth.BluetoothDevice nxtDevice)
Creates a NxtRobot instance with given BluetoothDevice of the NXT brick.
|
NxtRobot(android.app.Activity activity,
java.lang.String nxtName)
Creates a NxtRobot instance with given Bluetooth friendly name of the NXT brick.
|
Modifier and Type | Method and Description |
---|---|
void |
addNxtConnectionListener(NxtConnectionListener listener)
Registers a connection listener to get notifications when the NXT
bricks connects/disconnects.
|
void |
addPart(Part part)
Assembles the given part into the robot.
|
NxtRobot.ConnectState |
connect()
If the NXT name is not known, asks for the NXT Bluetooth friendly name.
|
static void |
delay(int time)
Halts current thread for the given amount of time.
|
void |
enableConnectMelody(boolean enable)
Enables/disables melody played when the Bluetooth connection is
established/broken (default: enabled).
|
void |
exit()
Closes the Bluetooth communication and resets the NXT brick to
accept the next connection.
|
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.
|
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 |
setVerbose(boolean verbose)
Show/hide verbose information about the Bluetooth search displayed
as toast (default: true) when connect() is called.
|
boolean |
startProgram(java.lang.String filename) |
void |
waitDisconnected()
Blocks the current thread until the Bluetooth link is disconnected.
|
boolean |
waitDisconnected(int timeout)
Checks repeatedly if Bluetooth link is disconnected for the given maximum
amount of time.
|
public static final java.lang.String ABOUT
public static final java.lang.String VERSION
public static final byte DIRECT_COMMAND_REPLY
public static final byte SYSTEM_COMMAND_REPLY
public static final byte REPLY_COMMAND
public static final byte DIRECT_COMMAND_NOREPLY
public static final byte SYSTEM_COMMAND_NOREPLY
public static final byte OPEN_READ
public static final byte OPEN_WRITE
public static final byte READ
public static final byte WRITE
public static final byte CLOSE
public static final byte DELETE
public static final byte FIND_FIRST
public static final byte FIND_NEXT
public static final byte GET_FIRMWARE_VERSION
public static final byte OPEN_WRITE_LINEAR
public static final byte OPEN_READ_LINEAR
public static final byte OPEN_WRITE_DATA
public static final byte OPEN_APPEND_DATA
public static final byte BOOT
public static final byte SET_BRICK_NAME
public static final byte GET_DEVICE_INFO
public static final byte DELETE_USER_FLASH
public static final byte POLL_LENGTH
public static final byte POLL
public static final byte POLL_BUFFER
public static final byte HIGH_SPEED_BUFFER
public static final byte START_PROGRAM
public static final byte STOP_PROGRAM
public static final byte PLAY_SOUND_FILE
public static final byte PLAY_TONE
public static final byte SET_OUTPUT_STATE
public static final byte SET_INPUT_MODE
public static final byte GET_OUTPUT_STATE
public static final byte GET_INPUT_VALUES
public static final byte RESET_SCALED_INPUT_VALUE
public static final byte MESSAGE_WRITE
public static final byte RESET_MOTOR_POSITION
public static final byte GET_BATTERY_LEVEL
public static final byte STOP_SOUND_PLAYBACK
public static final byte KEEP_ALIVE
public static final byte LS_GET_STATUS
public static final byte LS_WRITE
public static final byte LS_READ
public static final byte GET_CURRENT_PROGRAM_NAME
public static final byte MESSAGE_READ
public static final byte MOTORON
public static final byte BRAKE
public static final byte REGULATED
public static final byte REGULATION_MODE_IDLE
public static final byte REGULATION_MODE_MOTOR_SPEED
public static final byte REGULATION_MODE_MOTOR_SYNC
public static final byte MOTOR_RUN_STATE_IDLE
public static final byte MOTOR_RUN_STATE_RAMPUP
public static final byte MOTOR_RUN_STATE_RUNNING
public static final byte MOTOR_RUN_STATE_RAMPDOWN
public static final byte NO_SENSOR
public static final byte SWITCH
public static final byte TEMPERATURE
public static final byte REFLECTION
public static final byte ANGLE
public static final byte LIGHT_ACTIVE
public static final byte LIGHT_INACTIVE
public static final byte SOUND_DB
public static final byte SOUND_DBA
public static final byte CUSTOM
public static final byte LOWSPEED
public static final byte LOWSPEED_9V
public static final byte NO_OF_SENSOR_TYPES
public static final byte RAWMODE
public static final byte BOOLEANMODE
public static final byte TRANSITIONCNTMODE
public static final byte PERIODCOUNTERMODE
public static final byte PCTFULLSCALEMODE
public static final byte CELSIUSMODE
public static final byte FAHRENHEITMODE
public static final byte ANGLESTEPSMODE
public static final byte SLOPEMASK
public static final byte MODEMASK
public static final byte NXJ_FIND_FIRST
public static final byte NXJ_FIND_NEXT
public static final int MOTOR_SPEED
public static final double MOTOR_SPEED_FACTOR
public static final int GEAR_SPEED
public static final int GEAR_BRAKE_DELAY
public static final int GEAR_ACCELERATION_DELAY
public static final double AXE_LENGTH
public static final int TURTLE_SPEED
public static final double TURTLE_STEP_FACTOR
public static final int TURTLE_ROTATION_SPEED
public static final double TURTLE_ROTATION_FACTOR
public static final int CRAWLER_SPEED
public static final double CRAWLER_STEP_FACTOR
public static final int CRAWLER_ROTATION_SPEED
public static final double CRAWLER_ROTATION_FACTOR
public static final int SOUND_SENSOR_POLL_DELAY
public static final int LIGHT_SENSOR_POLL_DELAY
public static final int TOUCH_SENSOR_POLL_DELAY
public static final int ULTRASONIC_SENSOR_POLL_DELAY
public static final int MOTION_DETECTOR_POLL_DELAY
public static final int COMPASS_SENSOR_POLL_DELAY
public NxtRobot(android.app.Activity activity, android.bluetooth.BluetoothDevice nxtDevice)
activity
- the activity where to retrieve information about the
Bluetooth adapternxtDevice
- a valid reference to the existing Bluetooth devicepublic NxtRobot(android.app.Activity activity, java.lang.String nxtName)
activity
- the activity where to retrieve information about the
Bluetooth adapternxtName
- the Bluetooth name of the NXT brickpublic NxtRobot(android.app.Activity activity)
activity
- the activity where to retrieve information about the
Bluetooth adapterpublic void setVerbose(boolean verbose)
verbose
- if true, information is displayedpublic void enableConnectMelody(boolean enable)
enable
- if true, a melody is played when the brick connects/disconnectspublic void addPart(Part part)
part
- the part to assemblepublic NxtRobot.ConnectState connect()
public void exit()
public void addNxtConnectionListener(NxtConnectionListener listener)
listener
- the NxtConnectionListener to registerpublic void playConnectMelody()
public void playDisconnectMelody()
public byte[] requestData(byte[] request)
request
- the data to sendpublic void sendData(byte[] command)
command
- the data to sendpublic byte[] readData()
public boolean isConnected()
public void playTone(int frequency, int duration)
public double getBatteryLevel()
public static java.lang.String getVersion()
public static java.lang.String getAbout()
public void keepAlive()
public boolean startProgram(java.lang.String filename)
public FileInfo findFirst()
public FileInfo findNext(byte handle)
handle
- the handle of the previous found filepublic boolean fileExists(java.lang.String filename)
public static void delay(int time)
time
- the time the thread will sleep (in ms)public void waitDisconnected()
public boolean waitDisconnected(int timeout)
timeout
- the maximum time to wait (in ms)