Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Yay

  • Loading branch information...
commit 285e78223b418c543b2cf60e52ef352129fb0fe2 1 parent 9fbf324
@HalfdanJ HalfdanJ authored
View
6 client/AndroidManifest.xml
@@ -9,7 +9,11 @@
</intent-filter>
</activity>
</application>
- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
+
+
+
+
+<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<uses-permission android:name="android.permission.INTERNET"/>
View
71 client/client.pde
@@ -7,11 +7,20 @@ boolean leftRev=false;
boolean rightRev=false;
boolean fwdbkwOn = false;
+int mode = 0;
+
+float serverLat;
+float serverLon;
+float serverGoalLat;
+float serverGoalLon;
+float serverCompas;
+float serverBearing;
+float serverGoalDistance;
void setup() {
frameRate(20);
-
+
size(screenWidth, screenHeight);
background(0);
fontList = PFont.list();
@@ -59,6 +68,32 @@ boolean onKeyDown(int keyCode, KeyEvent event) {
}
}
+ if (keyCode == 108) {
+ String strSend = "goalSet:";
+ strSend += currentLatitude+";";
+ strSend += currentLongitude;
+ strSend = strSend.replace(".","*");
+ talk.SendToAllFriends(strSend);
+ }
+ if (keyCode == 82) {
+ String strSend = "goalSet:";
+ strSend += currentLatitude+";";
+ strSend += currentLongitude;
+ strSend = strSend.replace(".","*");
+ talk.SendToAllFriends(strSend);
+ }
+
+ if (keyCode == 109) {
+ if (mode == 0)
+ mode = 1;
+ else
+ mode = 0;
+
+ String strSend = "modeSet:";
+ strSend += mode;
+ talk.SendToAllFriends(strSend);
+ }
+
return true;
}
@@ -106,8 +141,8 @@ void draw() {
text("Latitude: "+currentLatitude, 20, 40);
text("Longitude: "+currentLongitude, 20, 75);
text("Accuracy: "+currentAccuracy, 20, 110);
- text("Provider: "+currentProvider, 20, 145);
-
+ text("Mode: "+mode, 20, 145);
+ text("Distance: "+serverGoalDistance,20,180);
fill(70, 100, 100);
stroke(255, 255, 255);
rect(screenWidth/2.0-100, screenHeight/2.0-100, 200, 200);
@@ -123,7 +158,33 @@ void draw() {
if (rightRev)
fill(255, 0, 0);
arc(screenWidth/2.0+70, screenHeight/2.0+100, 50, 50, 0-HALF_PI, TWO_PI*right/255.0-HALF_PI);
+
+ fill(255);
+ pushMatrix();
+ translate(width/2, height/2);
+ scale(1);
+ rotate(serverCompas/360.0*TWO_PI);
+ beginShape();
+ vertex(0, -50);
+ vertex(-20, 60);
+ vertex(0, 50);
+ vertex(20, 60);
+ endShape(CLOSE);
+ popMatrix();
+
+ if (serverBearing != 0){
+ fill(255, 0, 0);
+ pushMatrix();
+ translate(width/2, height/2);
+ scale(1);
+ rotate(serverBearing/360.0*TWO_PI);
+ beginShape();
+ vertex(0, -50);
+ vertex(-20, 60);
+ vertex(0, 50);
+ vertex(20, 60);
+ endShape(CLOSE);
+ popMatrix();
+ }
}
-
-
View
66 client/osc.pde
@@ -8,21 +8,20 @@ boolean rightRevSend = false;
void setupOsc() {
- talk = new XMPPMachine("chrliljebeta", "oiuOIU987)(/");
+ talk = new XMPPMachine("chrliljebeta", "oiuOIU987)(/");
talk.openconnection();
-
}
void updateOsc() {
if (leftSend != left || rightSend != right || leftRevSend != leftRev || rightRevSend != rightRev) {
-// SendToAllFriends
-String strSend = "motorSet:";
-strSend += left+",";
-strSend += right+",";
-strSend += leftRev?10:0+",";
-strSend += rightRev?10:0;
-
+ // SendToAllFriends
+ String strSend = "motorSet:";
+ strSend += left+",";
+ strSend += right+",";
+ strSend += (leftRev?10:"0")+",";
+ strSend += rightRev?10:"0";
+ talk.SendToAllFriends(strSend);
leftSend = left;
rightSend = right;
leftRevSend = leftRev;
@@ -30,7 +29,52 @@ strSend += rightRev?10:0;
}
}
-void oscEvent(OscMessage theOscMessage) {
-
+
+
+void parseChat(String msg) {
+ msg = msg.replace("*", ".");
+
+ println(msg);
+
+
+
+ if (msg.startsWith("gpsInfo:")) {
+ String arr1[] = msg.split("#");
+
+ for (int i=0;i<5;i++) {
+ }
+
+ String pin = arr1[0].replaceAll("gpsInfo:", ""); // get 'pin)'
+ String arr[] = pin.split(";");
+
+ serverLat = Float.parseFloat(arr[0]);
+ serverLon = Float.parseFloat(arr[1]);
+
+ pin = arr1[1].replaceAll("goalInfo:", ""); // get 'pin)'
+ arr = pin.split(";");
+
+ serverGoalLat = Float.parseFloat(arr[0]);
+ serverGoalLon = Float.parseFloat(arr[1]);
+ serverGoalDistance = Float.parseFloat(arr[2]);
+
+ pin = arr1[2].replaceAll("modeInfo:", ""); // get 'pin)'
+ mode = Integer.parseInt(pin);
+
+ pin = arr1[3].replaceAll("compasInfo:", ""); // get 'pin)'
+ arr = pin.split(";");
+
+ serverCompas = Float.parseFloat(arr[0]);
+ serverBearing = Float.parseFloat(arr[1]);
+
+ if (mode == 1) {
+ pin = arr1[4].replaceAll("motorInfo:", ""); // get 'pin)'
+ arr = pin.split(";");
+
+ left = Integer.parseInt(arr[0]);
+ right = Integer.parseInt(arr[1]);
+ leftRev = (Integer.parseInt(arr[2])>0)?true:false;
+ rightRev = (Integer.parseInt(arr[3])>0)?true:false;
+ }
+ }
}
View
4 server/arduino.pde
@@ -37,8 +37,8 @@ void updateArduino(){
server.send(new byte[] {
(byte) right
,(byte) left
- ,(byte) (rightRev?0:100)
- ,(byte) (leftRev?100:0)
+ ,(byte) (rightRev?100:0)
+ ,(byte) (leftRev?0:100)
}
);
}
View
2  server/gps.pde
@@ -15,6 +15,7 @@ float currentLatitude = 0;
float currentLongitude = 0;
float currentAccuracy = 0;
String currentProvider = "";
+Location curLocation;
//-----------------------------------------------------------------------------------------
@@ -34,6 +35,7 @@ class MyLocationListener implements LocationListener {
currentLongitude = (float)location.getLongitude();
currentAccuracy = (float)location.getAccuracy();
currentProvider = location.getProvider();
+ curLocation = new Location(location);
}
void onProviderDisabled (String provider) {
currentProvider = "";
View
77 server/navigation.pde
@@ -0,0 +1,77 @@
+
+float distanceToGoal() {
+ if (curLocation != null) {
+ Location goal = new Location(curLocation);
+ goal.setLatitude(latGoal);
+ goal.setLongitude(lonGoal);
+
+ float d = curLocation.distanceTo(goal);
+
+ return d;
+ }
+ return 0;
+}
+
+float rotationToGoal() {
+ if (curLocation != null) {
+
+ Location goal = new Location(curLocation);
+ goal.setLatitude(latGoal);
+ goal.setLongitude(lonGoal);
+
+ float bearing = curLocation.bearingTo(goal);
+
+ float curDir = direction/TWO_PI*360;
+ float ret = curDir+bearing;
+ while (ret > 180)
+ ret -= 360;
+ while (ret < -180)
+ ret += 360;
+ return ret;
+ }
+ return 0;
+}
+
+void autopilot() {
+ left = 0;
+ right = 0;
+
+
+ if (distanceToGoal() > 2) {
+ float dir = -rotationToGoal();
+
+ if (abs(dir) < 10) {
+ left = 255;
+ right = 255;
+ leftRev = false;
+ rightRev = false;
+ }
+ else if (abs(dir) < 45) {
+ leftRev = false;
+ rightRev = false;
+
+ float d = 1-abs(dir)/45;
+ if (dir < 0) {
+ left = 255;
+ right = (int)(255*d);
+ }
+ else {
+ right = 255;
+ left = (int)(255*d);
+ }
+ }
+ else {
+ left = 255;
+ right = 255;
+ if (dir < 0) {
+ leftRev = false;
+ rightRev = true;
+ }
+ else {
+ leftRev = true;
+ rightRev = false;
+ }
+ }
+ }
+}
+
View
53 server/osc.pde
@@ -1,18 +1,52 @@
XMPPMachine talk;
+int lastMsg = 0;
void setupOsc() {
// oscP5 = new OscP5(this, 12000);
//myRemoteLocation = new NetAddress("127.0.0.1", 12000);
- talk = new XMPPMachine("chrliljealpha", "oiuOIU987)(/");
+ talk = new XMPPMachine("chrliljegamma", "oiuOIU987)(/");
talk.openconnection();
}
void updateOsc() {
+ if (millis() > lastMsg + 1000) {
+
+ lastMsg = millis();
+
+ //Send status
+ String strSend = "gpsInfo:";
+ strSend += currentLatitude+";";
+ strSend += currentLongitude;
+
+ strSend += "#goalInfo:";
+ strSend += latGoal+";";
+ strSend += lonGoal+";";
+ strSend += distanceToGoal();
+
+ strSend += "#modeInfo:";
+ strSend += mode;
+
+ strSend += "#compasInfo:";
+ strSend += 360*direction/TWO_PI+";";
+ strSend += rotationToGoal();
+
+ strSend += "#motorInfo:";
+ strSend += left+";";
+ strSend += right+";";
+ strSend += (leftRev?1:0)+";";
+ strSend += (rightRev?1:0);
+
+ strSend = strSend.replace(".", "*");
+ println("Send"+strSend);
+ talk.SendToAllFriends(strSend);
+ }
}
void parseChat(String msg) {
- println(msg);
+ msg = msg.replace("*",".");
+
+ println(msg);
if (msg.startsWith("motorSet:")) {
println("Set motor:");
@@ -26,7 +60,20 @@ void parseChat(String msg) {
leftRev = (Integer.parseInt(arr[2])>0)?true:false;
rightRev = (Integer.parseInt(arr[3])>0)?true:false;
}
-}
+ if (msg.startsWith("goalSet:")) {
+
+ String pin = msg.replaceAll("goalSet:", ""); // get 'pin)'
+ // pin = pin.substring(0, pin.indexOf(")")); // strip the last )
+ String arr[] = pin.split(";");
+ latGoal = Float.parseFloat(arr[0]);
+ lonGoal = Float.parseFloat(arr[1]);
+ }
+
+ if (msg.startsWith("modeSet:")) {
+ String pin = msg.replaceAll("modeSet:", ""); // get 'pin)'
+ mode = Integer.parseInt(pin);
+ }
+}
View
64 server/server.pde
@@ -1,10 +1,16 @@
import android.util.Log;
+import android.location.Location;
boolean leftRev = false;
boolean rightRev = false;
int left=0;
int right=0;
+float latGoal = -1;
+float lonGoal = -1;
+
+int mode = 0; //0 motor mode ; 1 goal mode
+
int mouseGuiElement = -1;
boolean mouseDown = false;
@@ -30,6 +36,13 @@ void setup()
void onResume() {
// Compass
if (compass != null) compass.resume();
+ // Build Listener
+ locationListener = new MyLocationListener();
+ // Acquire a reference to the system Location Manager
+ locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
+ // Register the listener with the Location Manager to receive location updates
+ locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
+
super.onResume();
}
@@ -73,7 +86,9 @@ void draw()
}
-
+ if (mode == 1) {
+ autopilot();
+ }
updateArduino();
@@ -107,9 +122,33 @@ void draw()
fill(0, 0, 120);
rect(5, 0, (screenWidth-10)/2.0, 100);
rect((screenWidth-10)/2.0, 0, (screenWidth-10)/2.0, 100);
-
- translate(width/2, 310);
- scale(2);
+
+
+ fill(255);
+ text("Latitude: "+currentLatitude, 20, 40+300);
+ text("Longitude: "+currentLongitude, 20, 75+300);
+ text("Accuracy: "+currentAccuracy, 20, 110+300);
+ text("G Latitude: "+latGoal, 20, 145+300);
+ text("G Longitude: "+lonGoal, 20, 180+300);
+
+
+ if (curLocation != null) {
+ Location goal = new Location(curLocation);
+ goal.setLatitude(latGoal);
+ goal.setLongitude(lonGoal);
+
+ float distance = goal.distanceTo(curLocation);
+ float bearing = curLocation.bearingTo(goal);
+
+ text("G Distance: "+distance, 20, 205+300);
+ text("G Bearing: "+rotationToGoal(), 20, 240+300);
+ }
+ text("Bearing: "+direction/TWO_PI*360, 20, 275+300);
+ text("Mode: "+mode, 20, 310+300);
+
+ pushMatrix();
+ translate(width/2, 230);
+ scale(1);
rotate(direction);
beginShape();
vertex(0, -50);
@@ -117,6 +156,21 @@ void draw()
vertex(0, 50);
vertex(20, 60);
endShape(CLOSE);
+ popMatrix();
+
+ if (rotationToGoal() != 0){
+ fill(255, 0, 0);
+ pushMatrix();
+ translate(width/2, 230);
+ scale(1);
+ rotate(rotationToGoal()/360.0*TWO_PI);
+ beginShape();
+ vertex(0, -50);
+ vertex(-20, 60);
+ vertex(0, 50);
+ vertex(20, 60);
+ endShape(CLOSE);
+ popMatrix();
+ }
}
-
Please sign in to comment.
Something went wrong with that request. Please try again.