Sunday, January 4, 2009

Connection, Command, and File Dump Panels

This blog entry is the continuation of my discussion of my project to demonstrate the idea behind Monte Carlo Localization (MCL) for robots using the NXT Mindstorms robot. The PC will run the MCL algorithm with the robot acting essentially like a mobile sensor platform. The PC and robot will communicate with each other over a Bluetooth connection. Here, I am going to discuss the connection panel, the command panel, and the file dump panel.

We want the Connection Panel to look like this


The single button at the top will act as both the connect and the disconnect button. The text on the button will alternate between the words connect, printed in green, and disconnect, printed in red. The status field, which cannot be edited by the user, will read either disconnected when the PC is not connected to the NXT robot, or connected when a Bluetooth connection has been established between the PC and the robot.

The only method that might need some explanation is this one:

public void clickConnectButton(){
if(connectButton.getText().equals("Disconnect")){
connectButton.doClick();
}
}

This method is needed in case the user attempts to terminate the program before the robot is disconnected from the PC. If this should happen, we need a way to programmatically click the disconnect button before the program terminates. The doClick() method of the connectButton component does just exactly that.

I have primed the Bluetooth address field with my own NXT's Bluetooth address for the sake of personal convenience. You can change this by either commenting out or amending the following line of code.

addressField.setText("00:16:53:00:57:37");

You can download ConnectPanel.java here.

Another panel that we need is the Command panel. We want it to look like this


It has three buttons: initialize, move, and turn. The initialize button is used to re-start the MCL algorithm from scratch. The move button is used the move the robot a specified number of millimeters forward, if the distance is positive; backwards if the distance is negative. The turn button is used to turn the robot in place a specified number of degrees to the right, if the angle is negative; to the left if the angle is positive. The speed slider is used to adjust the robot’s speed.

We should emphasize that we are not trying to develop a remote control robot. Rather, the robot moves or turns in distinct stages. After each move or turn, students can observe how that move or turn has impacted the MCL algorithm. I am hoping that in this way students can learn how the MCL algorithm works through experimentation and feedback.

The following method may need some additional explanation:

public void setButtonsEnabled(boolean setting){
initialize.setEnabled(setting);
move.setEnabled(setting);
turn.setEnabled(setting);
speedSlider.setEnabled(setting);
}

A similar method also appears in the Statistics panel. This method is used to enable or disable the input components. The components are disabled whenever there is no connection between the PC and the robot; enabled whenever there is a connection between the PC and the robot. You can download CommandPanel.java here.

Another panel that we need is called the File Dump panel. We want the panel to look like this:


When the user clicks on the File Dump button, all of the statistics currently held by the MCL algorithm are written to a comma-separated value (csv) file using the index number on the spinner as part of the file’s file name. The spinner is automatically incremented to the next integer to avoid an accidental file overwrite. If the auto dump box is checked by the user, then the statistics are written to a csv file automatically after every move or turn of the robot. The spinner is automatically incremented to prevent an accidental file overwrite.

The purpose of the file dump panel is to allow the user to study the MCL algorithm's statistical data in another application such as Matlab or Excel to name two examples.

The File Dump button is always enabled, because there is always statistics to be written out to a file, even when the program is first initialized. You can download FileDump.java here.

The last panel that we will need is the Display Panel. I want to defer discussion of that panel until the next time I blog, because that panel touches very closely upon the MCL algorithm. While the class itself is not complicated as far as Java code goes, some of the things that the panel is doing might be unclear and require some explanation. If you should have any questions, please contact me at adcaine@gmail.com. See you next time.

No comments: