Chapter 10 Application Programmer’s Interface
10-22 ER1 User Guide
///////////////////////////////////////////////////////////////////////
// Application Entry Point
///////////////////////////////////////////////////////////////////////
/**
* @brief
* Program entry point.
*
* @param args Command-line arguments.
*/
static ER1Client client = null;
public static void main(String[] args) {
// Create a new client to communicate with ER1.
client = new ER1Client(args);
// Connect to the ER1 RCC.
if (client.connect()) {
// Run the user program.
userProgram();
}
}
}
Java API Example Programs
To change what commands you send it:
1. Edit the
TestClient.java file. make changes to this section:
/**
* @brief
* Users put their own commands here.
*/
public static void userProgram()
{
// Send the first move command, 10 inches forward.
String recvMsg = client.sendCommand("move 10 i\n");
client.waitFor("move");
// Send the turn command, 90 degrees to left.
recvMsg = client.sendCommand("move -90 d\n");
client.waitFor("move");
// Send the next move command, 50 cm forward.
recvMsg = client.sendCommand("move 50 c\n");
client.waitFor("move");
}
2. Just add your API command in quotes to recvMsg line
3. Change the client. Wait for the line to reflect what is output at the end of your action
in the
events command.
4. For example to have the robot speak the sentence "This is a test", you would add this
to the bottom:
recvMsg = client.sendCommand(play phrase "This is a test."\n);
client.waitFor("play");
Then you must recompile everything:
javac ER1test.java
javac TestClient.java