17. December 2010
To create a relatively simple but working navigationsystem we wrote an Android application. Android, because we could access GPS data and XML on a webserver using the mobile phone connection.<?php // 5MB maximum file size $MAXIMUM_FILESIZE = 5 * 1024 * 1024; // Valid file extensions (images, word, excel, powerpoint) $rEFileTypes = "/^\.(jpg|jpeg|gif|png|doc|docx|txt|rtf|pdf|xls|xlsx| ppt|pptx){1}$/i"; $dir_base = "/home/httpd/vhosts/alaingroeneweg.com/subdomains/gps/httpdocs"; $isFile = is_uploaded_file($_FILES['userfile']['tmp_name']); if($isFile) // do we have a file? { //userfile is the name of the upload_button move_uploaded_file($_FILES['userfile']['tmp_name'], $dir_base."/route.xml"); parseXml(); } function parseXml(){ $xml = simplexml_load_string(file_get_contents('route.xml')); $new_xml = simplexml_load_string(''); foreach ($xml->xpath('//xls:RouteInstruction') as $route_instr) { $instructionArr = $route_instr->xpath('xls:Instruction'); $instruction = $instructionArr[0]; $posArr = $route_instr->xpath('xls:RouteInstructionGeometry/gml:LineString/gml:pos'); $pos = $posArr[0]; //two variables out of one through splitting the string at the space list($long, $lat) = explode(' ', $pos); if (preg_match("/\blinks\b/i", $instruction)) { $location = $new_xml->addChild('location'); $location->addChild('longitude',$long); $location->addChild('latitude',$lat); $location->addChild('direction',"1"); } if (preg_match("/\bhalb links\b/i", $instruction)) { $location = $new_xml->addChild('location'); $location->addChild('longitude',$long); $location->addChild('latitude',$lat); $location->addChild('direction',"2"); } if (preg_match("/\brechts\b/i", $instruction)) { $location = $new_xml->addChild('location'); $location->addChild('longitude',$long); $location->addChild('latitude',$lat); $location->addChild('direction',"3"); } if (preg_match("/\bhalb rechts\b/i", $instruction)) { $location = $new_xml->addChild('location'); $location->addChild('longitude',$long); $location->addChild('latitude',$lat); $location->addChild('direction',"4"); } } $dom = new DomDocument("1.0"); $dom->loadXML($new_xml->asXml()); $dom->encoding="iso-8859-1"; htmlspecialchars($dom->saveXML()); $dom->save("minimal.xml"); chmod("minimal.xml",0777); } ?> <head> <title>Routeuploader</title> </head> <bod> <h1>Bike-Navigation</h1> <a id="link" href="http://openrouteservice.org/">download openrouteservice-xml here</a> <!-- The data encoding type, enctype, MUST be specified as below --> <form enctype="multipart/form-data" method="POST"> <!-- MAX_FILE_SIZE must precede the file input field --> <!-- Name of input element determines name in $_FILES array --> Send this file:<br /> </form> </body>Android Script Amarino is a Android Application. Since it is a native of Android application, the Android Developer SDK is required. For our tests, we used a HTC with Android Hero Europe Edition with Android 2.1. SAXParser By using SAX parser, we could easily access the XML file that has been uploaded by our PHP script and retrieve corresponding values. GPS as a singleton It seems that the Amarino Plugin doens’t allow to have any Activities on runtime. The GPS on the other hand requires an activity. To solve this problem we built the GPS part as a Singleton and started its activity before the plug-in runs as a Background service. This way we could access the GPS data al the time in our Android plug-in. Amarino Our Amarino plugin reads the XML data from the SAX parser and compares the coordinates with the GPS values. If the GPS data is close to the coordinades form the XML is reads the direction and sends the direction to the Arduino using Bluetooth. Arduino The Arduino microcontroller recieves the sent values from the Amarino plug-in and starts a vibrations pattern for the handlebars. For each direction we have two different pattern.
// This Code Reads the Serial Data whoch comes from Android // 2009 mlab.uiah.fi/paja // Echoing program (Return byte that is recieved from serial. #include <MeetAndroid.h> MeetAndroid meetAndroid; char incomingByte = 0; // for incoming serial data // ------ DIRECTION PINS INIT --------------------- int pinArrayLeft[] = {12, 13, 14}; int pinArrayLittleLeft[] = {12, 13}; int pinArrayRight[] = {2, 3, 4}; int pinArrayLittleRight[] = {2, 3}; // ------------------------------------------------ int timer = 100; int timerLittle =400; int count = 0; void setup() { // Start serial communication Serial1.begin(115200); Serial.begin(57600); for (count=0;count<3;count++) { //////////////// LINKS pinMode(pinArrayLeft[count], OUTPUT); pinMode(pinArrayLittleLeft[count], OUTPUT); //////////////// RECHTS pinMode(pinArrayRight[count], OUTPUT); pinMode(pinArrayLittleRight[count], OUTPUT); } } void loop() { while (Serial1.available() > 0) { byte serialreadbytevalue = Serial1.read(); Serial.println(serialreadbytevalue); switch(serialreadbytevalue) { case 49: goLeft(); break; case 50: goLittleLeft(); break; case 51: goRight(); break; case 52: goLittleRight(); break; } } } void goLeft() { for (count=0;count<3;count++) { digitalWrite(pinArrayLeft[count], HIGH); delay(timer); digitalWrite(pinArrayLeft[count], LOW); delay(timer); } } void goRight() { for (count=0;count<3;count++) { digitalWrite(pinArrayRight[count], HIGH); delay(timer); digitalWrite(pinArrayRight[count], LOW); delay(timer); } } void goLittleLeft() { for (count=0;count<2;count++) { digitalWrite(pinArrayLittleLeft[count], HIGH); delay(timerLittle); digitalWrite(pinArrayLittleLeft[count], LOW); delay(timerLittle); } } void goLittleRight() { for (count=0;count<2;count++) { digitalWrite(pinArrayLittleRight[count], HIGH); delay(timerLittle); digitalWrite(pinArrayLittleRight[count], LOW); delay(timerLittle); } }