Difference between revisions of "Visual navigation for Acrob or SBOT robot with Android with camera ( Marek Kádek, Jana Sucháneková)"
|  (→Úvod) |  (→Postup riešenia) | ||
| Line 13: | Line 13: | ||
| # Android zariadenie spárujeme s bluetooth modulom. | # Android zariadenie spárujeme s bluetooth modulom. | ||
| + | # Na android zariadenie nainštalujeme [http://code.google.com/p/amarino/downloads/detail?name=Amarino_2_v0_55.apk&can=2&q= Amarino]. | ||
| + | # Vytvoríme projekt v eclipse a do build path pridáme [http://code.google.com/p/amarino/downloads/detail?name=AmarinoLibrary_v0_55.jar&can=2&q= knižnicu]. | ||
| + | |||
| + | Ukážka nadviazania spojenia pomocou knižnice: | ||
| + | |||
| + |     private static final String DEVICE_ADDRESS =  "00:06:66:03:73:7B"; | ||
| + |     private ArduinoReceiver arduinoReceiver = new ArduinoReceiver(); | ||
| + | |||
| + |     @Override | ||
| + |     protected void onStart() { | ||
| + |         super.onStart(); | ||
| + |         registerReceiver(arduinoReceiver, new IntentFilter(AmarinoIntent.ACTION_RECEIVED)); | ||
| + |         Amarino.connect(this, DEVICE_ADDRESS); | ||
| + |     } | ||
| − | |||
| + |     @Override | ||
| + |     protected void onStop() { | ||
| + |         super.onStop(); | ||
| + |         Amarino.disconnect(this, DEVICE_ADDRESS); | ||
| + |         unregisterReceiver(arduinoReceiver); | ||
| + |     } | ||
| + | |||
| + | |||
| + |     public class ArduinoReceiver extends BroadcastReceiver { | ||
| + |         @Override | ||
| + | 	public void onReceive(Context context, Intent intent) { | ||
| + | 	    String data = null; | ||
| + | 	    final String address = intent.getStringExtra(AmarinoIntent.EXTRA_DEVICE_ADDRESS); | ||
| + |  	    final int dataType = intent.getIntExtra(AmarinoIntent.EXTRA_DATA_TYPE, -1); | ||
| + | |||
| + | 	    if (dataType == AmarinoIntent.STRING_EXTRA){ | ||
| + | 		data = intent.getStringExtra(AmarinoIntent.EXTRA_DATA); | ||
| + | |||
| + | 		if (data != null){ | ||
| + | 			try { | ||
| + | 			     // tu mozeme spracovat data, ktore robot posle na mobil | ||
| + |                              }  | ||
| + | 			 catch (Exception e) {  | ||
| + |                         } | ||
| + | 				} | ||
| + | 			} | ||
| + | 		} | ||
| + | 	} | ||
| + | |||
| + | 	priv | ||
| == Zdroje == | == Zdroje == | ||
| # [http://www.amarino-toolkit.net/ Amarino toolkit] | # [http://www.amarino-toolkit.net/ Amarino toolkit] | ||
Revision as of 09:34, 12 June 2013
Úvod
Cieľom projektu Editing Visual navigation for Acrob with Android with camera bolo vytvoriť robota, reagujúceho na vizuálne podnety v labyrinte pomocou snímania okolia kamerou mobilu s operačným systémom Android. Robot má byť spojený s telefónom pomocou protokolu bluetooth.
Postup riešenia
V prvej etape tvorby projektu bolo základom zložiť robota. (OBBBBBBBR)
V druhej etape sme vytvorili bluetooth spojenie medzi robotom a mobilným telefónom, pomocou knižnice Amarino - Android meets Andruino. Z rôznych zdrojov a diskusií na internete sme sa dozvedeli, že vytvorenie spojenia z android bluetooth na bluetooth modul robota je mnohokrát problémové a chyby sú ťažko odhaliteľné. Veľa rád práve smerovalo na použitie knižnice Amarino na riešenie tohoto problému.
Postup tvorby spojenia:
- Android zariadenie spárujeme s bluetooth modulom.
- Na android zariadenie nainštalujeme Amarino.
- Vytvoríme projekt v eclipse a do build path pridáme knižnicu.
Ukážka nadviazania spojenia pomocou knižnice:
   private static final String DEVICE_ADDRESS =  "00:06:66:03:73:7B";
   private ArduinoReceiver arduinoReceiver = new ArduinoReceiver();
   
   @Override
   protected void onStart() {
       super.onStart();
       registerReceiver(arduinoReceiver, new IntentFilter(AmarinoIntent.ACTION_RECEIVED));
       Amarino.connect(this, DEVICE_ADDRESS);
   }
   @Override
   protected void onStop() {
       super.onStop();
       Amarino.disconnect(this, DEVICE_ADDRESS);
       unregisterReceiver(arduinoReceiver);
   }
   public class ArduinoReceiver extends BroadcastReceiver {
       @Override
public void onReceive(Context context, Intent intent) { String data = null; final String address = intent.getStringExtra(AmarinoIntent.EXTRA_DEVICE_ADDRESS);
final int dataType = intent.getIntExtra(AmarinoIntent.EXTRA_DATA_TYPE, -1);
if (dataType == AmarinoIntent.STRING_EXTRA){ data = intent.getStringExtra(AmarinoIntent.EXTRA_DATA);
if (data != null){ try { // tu mozeme spracovat data, ktore robot posle na mobil
}
catch (Exception e) {
}
} } } }
priv
