The GUI for the Monte Carlo localization is largely implemented. The directory for the files can be found here. The most recently updated files are CommandPanel.java, EventHandler.java, Statistics.java, FileDump.java, ConnectPanel.java, and Localization.java.
I have also added a new class called Robot.java. This class is meant to be run on the NXT brick. Consequently, it should be placed in a separate project, with the project being turned into a Lejos project. I assume here that you are using Eclipse. Link and upload Robot.java to your brick.
To establish the Bluetooth connection, first run Robot.java on the brick. You should hear two beeps, which indicates that the brick is waiting for a Bluetooth connection from the PC.
Next, start Tester.java running. The GUI should open. Recall that the Bluetooth field has been primed with the Bluetooth address of my brick. Your Bluetooth address will be different, and you should enter your brick’s Bluetooth address in the field. Now, press the connect button.
Once the Bluetooth connection is established, you should hear the robot chime, which indicates that it is connected. On the GUI, the connect button should turn red and read disconnect. The status field should read connected. All of the buttons on the GUI should become active.
You can make the robot turn and move using the appropriate buttons and by supplying an angle in degrees or a distance in millimeters, as the case may be. You can request the battery voltage, or manually ping the ultrasonic sensor. After every turn or move, the latest ultrasonic sensor readings should appear on the GUI.
You can dump the statistics of the MCL algorithm into a csv file. However, please note that the file path and file names are hard coded in the Event Handler class. I welcome suggestions on how to make this more flexible.
The Robot class assumes 56 mm diameter wheels with a 121 mm wheel base. The left motor is connected to the C port; the right to the A port. If your robot’s configuration is different than mine, you will have to change the line of code in the Robot class, which instantiates the Pilot class. The Robot class also assumes that the ultrasonic sensor is connected to sensor port S1. Additionally, I assume that the ultrasonic sensor will point directly straight ahead along the robot's line of forward travel. I welcome suggestions on how to make the configuration of the physical parameters more flexible for the user.
Because the MCL algorithm is not yet fully implemented, the particles on the display do not appear to change in response to movements or turns of the robot. This is to be expected. However, if you do want to see the display change, click on the initialize button to restart the MCL algorithm.
To disconnect the PC and the robot, click on the disconnect button, and click on the yes button to confirm. Once the disconnection cycle is complete, the robot should chime. On the GUI, the disconnect button should now read connect in green lettering, and the status field should now read disconnected.
To bring the localization program to an end, click on the close button, and then click on the yes button to confirm.
Happy roboting!
To submit suggestions or report bugs, please email me at adcaine@gmail.com.
Thank you.
Showing posts with label graphical user interface. Show all posts
Showing posts with label graphical user interface. Show all posts
Monday, January 5, 2009
Sunday, January 4, 2009
Putting it all Together: A working GUI
In this blog, I will explain DisplayPanel.java and then put everything together to make up the final GUI.
To understand and run the Display Panel, you must download Point.java, Line.java, and Pose.java. A point is a location in two-dimensional space; the class is the aggregate of two double precision numbers. In our implementation, a line is defined in terms of two points: a starting point and an ending point. A pose is a particular guess at the location and heading of the robot. It is defined in terms of heading, a point, and three other variables. Those three other variables are the pose’s distance, the shortest distance to the nearest boundary of the enclosure; its weight, the extent to which we believe that the pose is a correct estimate of the robot’s true heading and position; and finally its cumulative weight, the sum of the weights of all of the poses before it and itself.
The display panel looks like this

Admittedly, it’s not very impressive. No pose or boundary line information has been given to it to display. So, the panel simply shows its white background. Once pose and boundary information is given to the display panel, it will show the poses as red dots, and the boundaries and black lines.
Still, we’re now in a position to start putting everything together to get a GUI that looks like this:

The directory to the source code is here. To get the GUI running, execute it from Tester.java.
I have implemented the Connect button. Remember to substitute your own Bluetooth address for your own NXT in the Bluetooth address field of the GUI. Turn on your NXT. Click on the Connect button. You should be connected. The disconnect aspect of the button has not yet been implemented. However, you can achieve a disconnection by pressing on the enter and escape keys of your NXT to reset it. The Bluetooth connection will be lost.
The Localization class is the class responsible for assembling the GUI. It instantiates the panels and, using absolute positioning, places them on the content pane. Because we are using absolute positioning, we make the GUI non-resizable. If we left the GUI resizable, a resizing on the part of the user could cause panels to become hidden from the user.
The Localization class also instantiates the Event Handler, passing a reference to it to all of the panels. The implementation of the Bluetooth connection routine can be found in the Event Handler class.
As well, the Localization class instantiates the BTCommPC class. This class is responsible for opening the Bluetooth connection between the PC and the robot, closing the connection, and negotiating communication between the two. As soon as the Event Handler detects that a connect action event has been fired, the Event Handler calls BTCommPC’s open method to take the necessary steps to open the Bluetooth connection, if it can.
Because problems can arise in establishing a Bluetooth connection, exceptions can be thrown. When these exceptions are thrown, we want to put error messages up on the GUI, such as

To do this, we use the JOptionPane’s static showMessageDialog() method. However, that method requires that it know in which JFrame to draw the dialog box. Consequently, the Localization class passes a reference to itself when it instantiates the BTCommPC class.
Finally, the Localization class is responsible for listening to the user clicking on the close window button in the upper right-hand corner, because the close button is regarded as part of the JFrame and not as part of any of the JPanels. Before terminating the program, the Localization class puts put a confirmation window on the screen.

If the user clicks on the yes button, the Localization class attempts to programmatically click the disconnect button if it currently appears on the GUI. Only when the Bluetooth connection is closed does the program finally terminate.
If you should have any questions, please write to me at adcaine@gmail.com. See you next time when I will show you additional implementations.
To understand and run the Display Panel, you must download Point.java, Line.java, and Pose.java. A point is a location in two-dimensional space; the class is the aggregate of two double precision numbers. In our implementation, a line is defined in terms of two points: a starting point and an ending point. A pose is a particular guess at the location and heading of the robot. It is defined in terms of heading, a point, and three other variables. Those three other variables are the pose’s distance, the shortest distance to the nearest boundary of the enclosure; its weight, the extent to which we believe that the pose is a correct estimate of the robot’s true heading and position; and finally its cumulative weight, the sum of the weights of all of the poses before it and itself.
The display panel looks like this
Admittedly, it’s not very impressive. No pose or boundary line information has been given to it to display. So, the panel simply shows its white background. Once pose and boundary information is given to the display panel, it will show the poses as red dots, and the boundaries and black lines.
Still, we’re now in a position to start putting everything together to get a GUI that looks like this:
The directory to the source code is here. To get the GUI running, execute it from Tester.java.
I have implemented the Connect button. Remember to substitute your own Bluetooth address for your own NXT in the Bluetooth address field of the GUI. Turn on your NXT. Click on the Connect button. You should be connected. The disconnect aspect of the button has not yet been implemented. However, you can achieve a disconnection by pressing on the enter and escape keys of your NXT to reset it. The Bluetooth connection will be lost.
The Localization class is the class responsible for assembling the GUI. It instantiates the panels and, using absolute positioning, places them on the content pane. Because we are using absolute positioning, we make the GUI non-resizable. If we left the GUI resizable, a resizing on the part of the user could cause panels to become hidden from the user.
The Localization class also instantiates the Event Handler, passing a reference to it to all of the panels. The implementation of the Bluetooth connection routine can be found in the Event Handler class.
As well, the Localization class instantiates the BTCommPC class. This class is responsible for opening the Bluetooth connection between the PC and the robot, closing the connection, and negotiating communication between the two. As soon as the Event Handler detects that a connect action event has been fired, the Event Handler calls BTCommPC’s open method to take the necessary steps to open the Bluetooth connection, if it can.
Because problems can arise in establishing a Bluetooth connection, exceptions can be thrown. When these exceptions are thrown, we want to put error messages up on the GUI, such as
To do this, we use the JOptionPane’s static showMessageDialog() method. However, that method requires that it know in which JFrame to draw the dialog box. Consequently, the Localization class passes a reference to itself when it instantiates the BTCommPC class.
Finally, the Localization class is responsible for listening to the user clicking on the close window button in the upper right-hand corner, because the close button is regarded as part of the JFrame and not as part of any of the JPanels. Before terminating the program, the Localization class puts put a confirmation window on the screen.
If the user clicks on the yes button, the Localization class attempts to programmatically click the disconnect button if it currently appears on the GUI. Only when the Bluetooth connection is closed does the program finally terminate.
If you should have any questions, please write to me at adcaine@gmail.com. See you next time when I will show you additional implementations.
Subscribe to:
Posts (Atom)