rysc
YaBB Newbies
Offline
Posts: 2
Connectivity Using a BAM to an iRobot
Aug 29th , 2008, 6:35pm
I was wondering if anybody could help me out with this problem, I am trying to run my Java code to an iRobot using a Blue tooth adapter, the computer sees the BAM device and everything but everytime I connect it to the outgoing port I always get this error; java.lang.NullPointerException at roombacomm.RoombaCommSerial.send(RoombaCommSerial.java:199) Below is the code that I am trying to run; import roombacomm.*; import roombacomm.net.*; import mkv.MyGUI.*; // if you set roombaCommPort to null, it will bring up the port picker dialog // if you set it to "testdummy", it will be a bring up a non-functioning test of the GUI //String roombacommPort = "testdummy"; //String roombacommPort = "/dev/cu.KeySerial1"; //String roombacommPort = "/dev/cu.BlueRadios-COM0-1"; String roombacommPort = null ; // This is the line that you will need to worry about boolean done = true; RoombaCommSerial roombacomm; void setup() { roombacommSetup(); } void draw() { if (roombacomm == null ) return; } void roombacommMove() { int speed = 300; int time = 5000; roombacomm.goForwardAt(speed); roombacomm.pause(time); println("travelling at "+speed+" millimeters per second for "+time+" milliseconds."); roombacomm.stop(); } void roombacommPortSelected() { roombacomm = new RoombaCommSerial(); if( roombacommPort.equals("testdummy")) { return; //Test the user interface without the Roomba } println("opening roomba serial port ' " +roombacommPort+ "'" ); if(! roombacomm.connect(roombacommPort)) { println("Couldn't connect to the registered port" +roombacommPort ); } //This block of code was taken from Dr. Kandasamy's challenge 1a code println("Roomba connected to port" +roombacommPort); roombacomm.startup(); roombacomm.control(); //Puts in a state of Safe Mode roombacomm.pause(50); //Pause for 50 milliseconds roombacomm.playNote(72, 8); //Plays note to signify proper connectivity roombacomm.pause(200); // Pauses while the notes are being played roombacomm.playNote(72, 10); roombacomm.updateSensors(); // Command that updates Sensors roombacommMove(); //Start the program } void roombacommSetup() { if( roombacommPort != null ) { roombacommPortSelected(); return; } RoombaComm rc = new RoombaCommSerial(); // throwaway just to find ports final String portlist[] = rc.listPorts(); // FIXME: should be made static javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { try { String port = (String) javax.swing.JOptionPane.showInputDialog( null, "Select Roomba Port", "RoombaTune", javax.swing.JOptionPane.QUESTION_MESSAGE, null, portlist, null); if( port == null ) { javax.swing.JOptionPane.showMessageDialog(null, "No port chosen, goodbye"); System.exit(1); } roombacommPort = port; roombacommPortSelected(); } catch (Exception e) { e.printStackTrace(); } } }); } any kind of feedback would be great. Thanks Ryan