⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readme

📁 1、手持设备机器人——应用端; 2、基于蓝牙传输;
💻
字号:
About MobileRobotics

	Mobilerobotics
	Mobile Robotics is a project focusing on wireless communication 
	with special focus on Bluetooth and IR. The basic idea is to create
	a Lego Robot wich can be controled by a regular cellphone assuming
	it has Bluetooth capabilities. The focus is sighted towards mobile 
	communication and Lego as a visual help to demonstrate the results 
	in a creative and interesting way
	
	Bluetooth and IR is two different methods to communicate wirelessly. 
	IR stands for Infra Red and reguires line-of-sight to work and 
	Bluetooth is using the radio frequency 2.4 GHz and has a range between 
	10 and 100 meters. 
	
	Unfortunately the Lego Mindstorm system is using IR and not Bluetooth 
	or similar radio communication. This means that it has serious limitations 
	of controlability since it requires line-of-sigth. We intend to bypass 
	this limitation.
	
	In short the idea is to have a cellphone connect to a Hand held device 
	(PDA) wich is located on the robot and via Bluetooth send commands to 
	it. The PDA will then translate the commands into IR and send it to the 
	Lego RCX (A mini computer wich controlls the Lego). The RCX then executes 
	it and the robot performs the action. 

About this file (MobileRobotics.v01.client.Source.zip)
	
	The subfolder MobileRobotics is a SonyEricsson J2ME Wireless Toolkit project.
	You will need it to compile and simulate/build. Download from 
	http://developer.sonyericsson.com

Installation.

	(Full documentation is avaible at http://sourceforge.net/project/showfiles.php?group_id=121144&package_id=150865) 

	Copy the subfolder into your projects folder, probably 
	C:\SonyEricsson\J2ME_SDK\PC_Emulation\WTK2\apps

	Open SonyEricsson J2ME Wireless toolkit, press "Open project". 
	Select MobileRobotics. You have successfully opened our project. 
	Now press settings and make sure you have these under "API selection:"
	
	Target Platform: Custom
	Profiles: MIDP 2.0
	Configuration: CLDC 1.0
	Optional: Bluetooth API (JSR 82)

	To use it with your regular cellphone choose Project - Package
	and then "Build Package". Then copy the .jar and .jad file created 
	(in bin/) to your cellphone and install. 

	Commands: Press 0 to toogle between modes. On a none-pointer cellphone
		    (everyone except P800/P900/P910) you will get a about screen.
		    On P910 you will get a draw-and-the-robot-will-follow screen,
		    try it. 

Questions?

	If you got any questions don't hesitate to contact me using SF 
	(https://sourceforge.net/projects/mobilerobotics/) or the direct
	link: https://sourceforge.net/sendmessage.php?touser=551508

	Or mail me on webmaster@bivald.com
	
	
From documentation:	
	
/*************************************************************
 *
 * The Mobile Robotics Project
 * - mobilerobotics.sourceforge.net
 *
 *************************************************************/

 - File created 2005-04-11 by Niklas Bivald, 
                              Client-software

This file will give you an idea of how the MIDlet work, calling
each thread and similar. See it as a intro and an overview. 

Files:
 - MobileRoboticsMidlet.java	: Main MIDlet
 - Bluetooth.java		: Handles bluetooth connections
 - SplashScren			: Error report and splash screen
 - ControllRobot.java		: Controlls our robot 	

What happens when the MIDlet is started, searches connects and sends a command.

 [MobileRoboticsMidlet] 

   1 Starts [Bluetooth] Thread. 

   2 Calls [Bluetooth].initiate() to open the bluetooth connection

           [Bluetooth.]initiate()
	
             2.1 Initiates [SplashScreen] 
                         - shows the loading bar (Moves the display focus to SplashScreen)
               
             2.2 Search for near bluetooth devices:

                 2.2.1 mobileRoboticsDeviceDiscovery()
			 -  starts the discovery

                 2.2.1.2 deviceDiscovered() 
			 - Puts the discovered device in an array

		 2.2.1.3 inquiryCompleted() 
                         - Device discovery completed.

             2.3 Search devices for our service

                 2.3.1 Loops our array with devices

                 2.2.1.2 searchServices();
                         - Save the device with our services in a string

		  [Abort if no suitable device is found, fatalError()] 

	     2.4 Opens bluetooth connection
                  - Connector.open(serviceUrl);

		  [Abort if there is an error opening the connection, fatalError()] 

             2.5 Opens OutputStream
                  - openOutputStream()

		  [Abort if there is an error opening the OutputStream, fatalError()] 
	
             2.6 Load images
                  - loadImages()

             2.7 Stop splashscreen and return to [MobileRoboticsMidlet]

   [We now got a bluetooth connection and we move on to ControllRobot]

   3 Starts [ControllRobot] Thread. 
   
   4 Calls [ControllRobot].start()

             4.1 Starts our thread and set some values
             
             4.2 Moves over to run() 
             	  - Loops a while-syntax as long as the application run. The while
             	    waits for user input by calling input() and then updates the screen 
             	    by using drawScreen(Graphic g). Note: run() loops until the program exits. 
             	    
             	    About the run() loop. It got several modes, more about that later on. The
             	    example below is for mode 1, controlling the robot with the buttons.            	    	 
             	    
             	    	4.2.1 Input()
             	    	  - Uses getKeyStates() to check for input. When found
             	    	    the coresponding bluetooth command is sent out by calling
             	    	    bluetooth.command(int command); 
             	    	    
             	    	    The stearing work like this:
             	    	    
             	    	    If it is currently turning right, and you click left it will go into neutral.
             	    	    Next time you press it will turn left. Same thing when we travel forward. If
             	    	    you press backwards once it goes into neutral. When you press again it will 
             	    	    go backwards. 
             	    	    
             	    	      4.2.1.1 [Bluetooth].command()
             	    	       - Starts by checking if we got a connection (connection != null) and 
             	    	         that we got an outputStream (os != null). It then compares the sent
             	    	         command (int command) to the last sent command (int lastSentCommand)
             	    	         this is to make sure we doesn't send same commands over and over again.
             	    	         
             	    	         It then converts the int into a byte (easier for the palm to recieve).
             	    	         
             	    	         We then write the byte to the buffer by using os.write(cmd) and then
             	    	         we flush the buffer (os.flush()) to send our command. Method is void
             	    	         (returns nothing to input()). 
             	    		
             	    		 These are our commands:
             	    		 
             	    		     From Bluetooth.java
             	    		 
             	    		    /* 
				     * Bluetooth commands and their function (int direction)
				     *
				     *  Car is running..
				     *
				     *  0) Power On
				     *  1) Power Off
				     *  2) Forward
				     *  3) Backward
				     *  4) Left
				     *  5) Right
				     *  6) Stop
				     *
				     *  For local use only:
				     *  7) Switch (Switch modes (key to pointer))
				     *  8) Killed (It's powered off)
    				     */
             	    	
             	        4.2.2 drawScreen(Graphic g)
             	          - Updates the screen so that we can see that we are for example turning right.
             	          
             4.3 About or recordAndRunAfterPointer
             	  - You toogle modes using the zero (0) button. 
             	 
             	    ControllRobot got three modes, 1 + 2, depending on the cellphone.
             	    Mode 1 is always the regular controllRobot with the wheel. 
             	    Mode 2 is the about screen, this is shown for cellphones without pointer (touchscreen)
             	    Mode 2 (version 2) is for cellphones with touchscreen, 
             	    
             	    Let's demonstrate how it works if we switch to mode 1 to mode 2 (for touchscreens). 
             	    
             	    recordAndRunAfterPointer (not a method name):    
             	      You can "record" a path by clicking multiple times on the cellphones
             	      screen. Then when you press the "Run path" button the robot will
             	      follow the directions. It is not precise but it will move in the
             	      similar direction.
             	            	
             	    Mode change: 
             	    When you press the zero (0) button it is catched by the method keyPressed(int KeyCode)
             	        
             	        4.3.1 keyPressed (int keyCode)
             	          - We start by checking if it's the right button: if(keyCode == 48)
             	            48 represent zero (cross-platform (on all cellphones)). 
             	            
             	            If mode is "1" we send the command "6" so it will stop the robot before switching modes. 
             	            we then set direction (so ControllRobot knows were the robot is heading)
             	            to seven as it represents "Switch modes" (as seen above). 
             	            
             	            After direction is changed and command is sent we set the mode to 2. 
             	            
             	            [If the direction is 2 (and we want to switch back) we send command 6, 
             	            direction 6 and finaly mode 1]
             	        
             	    Now mode is changed to 2. We then return to the run() loop. 
             	    
             4.4 Back to run() 
                 - Every time the loop runs it checks for what mode we are currently is:
                   	   
			   if mode is 1:
				Read input from keys, input() as desribed above

			   if mode is 2:
				If we have touchScreen :2v2: Show the recordAndRunAfterPointer (se above)
				If we haven't:         :2  : Show about screen
				
                   Let's look at what each of them do:
                   
                     4.4.1 mode 1: we've already went through it, input() 
                     4.4.2 mode 2: If we have a pointer screen:
                       -  recordAndRunAfterPointer is not a method name. It's just what we call
                          the function internally. 
                          
                          This method does not use any while-loops to check for key-input.
                          Instead it uses native methods that is called when someone presses
                          the touchscreen. 
                          	
                          However the run() loop is still going to update the screen:
                           drawPointerScreen(Graphics g)

			  When someone clicks on the screen the method pointerPressed(int x,int y) 
			  is called (x and y beeing the cordinates). 
			  
			  4.4.2.1 pointerPressed(int x, int y)
			    - First of all the method checks if the mode is 1, if so it means that 
			      someone has pressed the screen when it's another mode (steering with
			      buttons). We then simply abort calling return;
			      
			      Second of all it checks that we pressed inside the drawing area and
			      if we have it set's the variable havePoints to true. This symbols that
			      we have points/path saved. It also stores the x/y parameters in an array
			      called points[][]. At last it increases int nrpoints with 1.
			      
			      If we haven't checked inside the drawing area it means that we either
			      pressed someplace along the borders or on the buttons "Run path" 
			      or "Clear path". 
			      
			      If we have pressed run path method runPath() is called,
			      If we have pressed clear path method clearPath() is called. 
			      
			   4.4.2.2 clearPath()
			     - It starts by looping the aray points[][] to null all cordinates. 
			       Then it sets havePoints to false and nrpoints to zero. 
			
                           4.4.2.3 runPath()
                              - Command not yet implented. '
                              
                    4.4.3 mode 2: If you haven't got a pointer screen
                      - About screen is shown, drawAboutScreen()
                      
             4.5 Shutdown
               - When ordered a shutdown [MobileRoboticsMidlet].exit() is called. 
                 This preforms the following tasks. 
                 
                  If the bluetooth thread is started and we got an connection and
                  outputstream it will send the commands 6, 1 (stop, shutdown) and cleanUp
                  (closes connections and such)
                  
                  It then stops [ControllRobot] and exits the MIDlet. 
                  
- Niklas Bivald
		                   
             	    
             	    
             	          

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -