Computer science project idea - Possible? (ideas please)

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

Computer science project idea - Possible? (ideas please)

Postby mbenz1 » Mon Oct 08, 2007 5:29 pm

Hi,

for my computer science preoject i am looking to create a mindstorms nxt robot controlled with a bluetooth phone.

Im am looking to program the bot in java as well as the mobile phone application.

maybe looking at the idea of a bomb disposal bot which can be controlled from the phone much in the same way as ericsson have a remote controlled car. So i could use the keys to control it. with bluetooth communication

would this be possible using lejos and how much work?
my main scare is am i able to send/recieve bluetooth commands?
also whats the possibility of sending video to the phone (guessing very advanced)

also any other ideas??? (i am good with java with a little of embedded systems knoledge)

Thanks for reading
Ben
________
maryjane
Last edited by mbenz1 on Thu Feb 03, 2011 1:20 pm, edited 1 time in total.
mbenz1
New User
 
Posts: 10
Joined: Mon Oct 08, 2007 5:22 pm

Postby lawrie » Mon Oct 08, 2007 10:21 pm

I have my mobile phone sending commands to a NXT running leJOS. I have posted a very simple mobile phone App in the past. Also the Lego mobile phone app available from the official Lego web site works with my phone.

Try your mobile phone with the standard Lego mobile phone app and the standard Lego firmware, and then try it with leJOS. If that works, you should not have a problem sending Bluetooth commands.

I don't understand what you mean by sending video to the phone - please explain. If you mean sending video from the robot, what sort of camera are you thinking of?
lawrie
leJOS Team Member
 
Posts: 909
Joined: Mon Feb 05, 2007 1:27 pm

Postby mbenz1 » Tue Oct 09, 2007 11:39 am

sorry i thought there was a camera for the nxt which would be cool if it could send video through bluetooth but that was just a rough idea.

I have looked at the app from lego and it seems pretty simple but was wondering if it would be hard to recreate these commands in my own j2me app.

do you have a link to what you have done so i can take a look?

are there any places with sample leJos code?

also any other project ideas maybe a little more advanced?

thanks for your help
________
buy vaporizer
Last edited by mbenz1 on Thu Feb 03, 2011 1:20 pm, edited 1 time in total.
mbenz1
New User
 
Posts: 10
Joined: Mon Oct 08, 2007 5:22 pm

Postby lawrie » Fri Oct 12, 2007 7:49 pm

Here is a Java Midlet that connects to leJOS NXJ and retrieves the battery level.

Code: Select all
import java.util.Vector;
import javax.bluetooth.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.io.*;
import java.io.IOException;
import java.io.*;


public class BlueDisc extends MIDlet implements CommandListener,
                    DiscoveryListener {
   
    private LocalDevice local = null;
    private DiscoveryAgent agent = null;
   
    private Vector devicesFound = null;
    private ServiceRecord[] servicesFound = null;
    private Alert a;
    StreamConnection con;

    public void startApp() {
       
        /*  Add your MIDlet specific code here.
         *  You probably want to show the user
         *  a welcome screen.
         *  The call to doDeviceDiscovery() is
         *  here for the example's sake. You
         *  should call doDeviceDiscovery() when
         *  the user actively asks for it.
         */
         
        //infoAlert("Discovering Services");

       doDeviceDiscovery();
    }
   
    public void pauseApp() {
    }
   
    public void destroyApp(boolean unconditional) {
    }
   
    public void commandAction(Command c, Displayable d) {
       
    }

    private void infoAlert(String msg) {
         a = new Alert("Info",msg, null, AlertType.INFO);
         a.setTimeout(Alert.FOREVER);
         Display.getDisplay(this).setCurrent(a);
    }

   
    public void deviceDiscovered(RemoteDevice remoteDevice,
                  DeviceClass deviceClass) {

        infoAlert("Device discovered: " + deviceClass.getMajorDeviceClass());
       
        devicesFound.addElement(remoteDevice);
    }
   
    public void inquiryCompleted(int param) {
       
        /*We should give the user an alert based on the
         *inquiry status code
         */
       
        // infoAlert("Inquiry Completed");

        switch (param) {
           
            case DiscoveryListener.INQUIRY_COMPLETED:

                //Inquiry completed normally, add appropriate code here
           
                // infoAlert("Inquiry Completed Normally");

                for(int i=0;i<devicesFound.size();i++) {

                  RemoteDevice rd = (RemoteDevice) devicesFound.elementAt(i);

                  //try {
                      //infoAlert("Searching for " + rd.getFriendlyName(false));
                  //} catch (IOException ioe) {}

                  doServiceSearch(rd);
                }

                break;
               
            case DiscoveryListener.INQUIRY_ERROR:

                //Error during inquiry, add appropriate code here

                infoAlert("Inquiry Completed with error");

                break;
               
            case DiscoveryListener.INQUIRY_TERMINATED:

                /*
       * Inquiry terminated, caused by agent.cancelInquiry()
       * Add appropriate code here
       */

                infoAlert("Inquiry Terminated");
               
                break;
        }
    }
   
    public void serviceSearchCompleted(int transID, int respCode) {
   
            switch(respCode) {
           
            case DiscoveryListener.SERVICE_SEARCH_COMPLETED:

              /*
       * Service search completed successfully
       * Add appropriate code here
       */

                 //infoAlert("Service completed OK");

                break;
               
            case DiscoveryListener.SERVICE_SEARCH_DEVICE_NOT_REACHABLE:

      // device not reachable, add appropriate code here

                infoAlert("Device not reachable");
            
                break;
               
            case DiscoveryListener.SERVICE_SEARCH_ERROR:

      // Error during service search, add appropriate code here

               infoAlert("Service Search Error");
               
                break;
               
            case DiscoveryListener.SERVICE_SEARCH_NO_RECORDS:

      // No records found, add appropriate code here

                infoAlert("No Services");
               
                break;
               
            case DiscoveryListener.SERVICE_SEARCH_TERMINATED:
           
      /*
       * Search terminated, caused by agent.cancelServiceSearch(..)
       * Add appropriate code here
       */

                infoAlert("Service Search Terminated");
             
                break;
        }
   
    }
   
    public void servicesDiscovered(int transID,
               ServiceRecord[] serviceRecord) {
                            
       //Services discovered, keep a reference to the ServiceRecord array

        //infoAlert("Services Discovered");
       
       servicesFound = serviceRecord;

        String url = serviceRecord[0].getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);

        //infoAlert(url);
       
        try{

            byte[] b = new byte[4];
            byte[]  r = new byte[7];

            b[0] = 2;
            b[1] = 0;
            b[2] = 0;
            b[3] = 0x0B;


            con = (StreamConnection) Connector.open(url);

           
            OutputStream os = con.openOutputStream();
            os.write(b);
            os.flush();

            InputStream is = con.openInputStream();
            is.read(r);

            infoAlert("Battery: " + ((r[5] & 0xFF) + ((r[6] & 0xFF) << 8)));
           
            is.close();
            os.close();

         }
         catch(IOException e){
            infoAlert("" + e.getMessage());
         }

    }
   
    private void doDeviceDiscovery() {
       
        try {
            local = LocalDevice.getLocalDevice();
        }catch (BluetoothStateException bse) {
           
            // Error handling code here

            infoAlert("No local device");
        }
       
        agent = local.getDiscoveryAgent();

        // infoAlert((agent == null ? "No agent" : "Got agent"));
       
        devicesFound = new Vector();
       
        try {
           
            if(!agent.startInquiry(DiscoveryAgent.GIAC,this)) {
               
                //Inquiry not started, error handling code here

                infoAlert("Inqiry not started");
            }
        }catch(BluetoothStateException bse) {
           
            //Error handling code here

            infoAlert("Inquiry Exception");
        }
    }
   
    private void doServiceSearch(RemoteDevice device) {
       
       /*
        * Service search will always give the default attributes:
        * ServiceRecordHandle (0x0000), ServiceClassIDList (0x0001),
        * ServiceRecordState (0x0002), ServiceID (0x0003) and
        * ProtocolDescriptorList (0x004).
        *
        * We want additional attributes, ServiceName (0x100),
        * ServiceDescription (0x101) and ProviderName (0x102).
        *
        * These hex-values must be supplied through an int array
        */
       
       int[] attributes = {0x100,0x101,0x102};
       
       /*
        * Supplying UUIDs in an UUID array enables searching for specific
        * services. PublicBrowseRoot (0x1002) is used in this example. This
        * will return any services that are public browsable. When searching
        * for a specific service, the service's UUID should be supplied here.
        */
       
       UUID[] uuids = new UUID[1];
       //uuids[0] = new UUID(0x1002);
        uuids[0] = new UUID("1101",true); // Serial Port
       
       try {
         agent.searchServices(attributes,uuids,device,this);
      } catch (BluetoothStateException e) {

                      infoAlert("Service Search Exception");

                 infoAlert( "" + e);
         // Error handling code here
      }
    }
}

lawrie
leJOS Team Member
 
Posts: 909
Joined: Mon Feb 05, 2007 1:27 pm

Postby mbenz1 » Mon Oct 15, 2007 1:46 pm

Thanks lawrie,

im sure ill be asking questions when i get started tx :D
________
Warren Transmission
Last edited by mbenz1 on Thu Feb 03, 2011 1:20 pm, edited 1 time in total.
mbenz1
New User
 
Posts: 10
Joined: Mon Oct 08, 2007 5:22 pm

Postby elpy » Wed Oct 17, 2007 10:41 am

I'm working on a pretty much identical computer science project right now. Only difference is that I have next to no Java experience (only the past two months), so I'm having a hard time understanding..well.. anything :P

My original project was to make my phone communicate with the NXT, but if I could at least make my computer communicate with the NXT I'll be happy :) (should be easy if I just read and understood the PCtools, right?).

Could someone help me out with this? I've been reading loads of "Getting started" documentation about Java and blutooth, but everything seems past my level of experience.

So far I have a good understanding of BTRecieve (the sample) and sent a few bytes from the official Lego NXT mobile program(can't use this though, since I need open source code that I can understand for it to be valid in the project).

I couldn't get that Midlet to work on my phone though :/

Edit: To elaborate:
I just need something really simple like;

PC side:
open bluetooth connection
if push button 1 - send int 1
if push button 2 - send int 2
...

NXT side:
open connection
if readInt == 1 - MotorA+MotorC forward
if readInt == 2 - MotorA forward , MotorC backward
...

Can't be too hard?
elpy
New User
 
Posts: 4
Joined: Wed Oct 17, 2007 10:34 am

Postby mbenz1 » Fri Oct 19, 2007 1:56 pm

This is basically what i need to do,

does anyone know how to do this, as i too dont want to use the lego mobile app and need to create on myself...

let me know how you get on with this
________
VI 5,5
mbenz1
New User
 
Posts: 10
Joined: Mon Oct 08, 2007 5:22 pm


Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff