Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Done

  • Loading branch information...
commit b542cc82ffeaef8d902e9bfc2472f86ef311d9ee 1 parent fef8758
@HalfdanJ HalfdanJ authored
View
158 client/client.pde
@@ -9,13 +9,17 @@ boolean rightRev=false;
boolean fwdbkwOn = false;
int mode = 0;
+String sendThis = null;
+
+
float serverLat;
float serverLon;
-float serverGoalLat;
-float serverGoalLon;
+float goalLat;
+float goalLon;
float serverCompas;
float serverBearing;
float serverGoalDistance;
+int serverSelectedWaypoint = 0;
boolean settingGoal = false;
@@ -30,10 +34,17 @@ int mapZoom = 16;
PImage mapImg;
+ArrayList<float[]> waypoints;
+
void setup() {
- frameRate(20);
+
+ ToneGenerator tone = new ToneGenerator(AudioManager.STREAM_MUSIC, 100);
+ tone.startTone(ToneGenerator.TONE_CDMA_EMERGENCY_RINGBACK, 2000);
+ frameRate(20);
+
+ waypoints = new ArrayList<float[]>();
size(screenWidth, screenHeight);
background(0);
fontList = PFont.list();
@@ -45,18 +56,36 @@ void setup() {
boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == 23) {//X
- left = 255;
- right = 255;
- leftRev = false;
- rightRev = false;
- fwdbkwOn = true;
+ if (mode == 0) {
+ left = 255;
+ right = 255;
+ leftRev = false;
+ rightRev = false;
+ fwdbkwOn = true;
+ }
+ else {
+
+ String strSend = "goalAdd:";
+ strSend += goalLat+";";
+ strSend += goalLon;
+ strSend = strSend.replace(".", "*");
+ sendThis = strSend;
+ println("Add waypoint "+strSend);
+ }
}
if (keyCode == 99) {//square
- left = 255;
- right = 255;
- leftRev = true;
- rightRev = true;
- fwdbkwOn = true;
+ if (mode == 0) {
+ left = 255;
+ right = 255;
+ leftRev = true;
+ rightRev = true;
+ fwdbkwOn = true;
+ }
+ else {
+ String strSend = "goalRestart:";
+ sendThis = strSend;
+ // talk.SendToAllFriends(strSend);
+ }
}
if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
if (mode == 0) {
@@ -65,12 +94,12 @@ boolean onKeyDown(int keyCode, KeyEvent event) {
else {
settingGoal = true;
if (mapImg != null) {
- float[] goalP = LLToXY(serverGoalLat, serverGoalLon, mapCenterLat, mapCenterLon, mapZoom);
- goalP[0] += 5;
- float[] goalP2 = XYToLL((int)goalP[0], (int)goalP[1], mapCenterLat, mapCenterLon, mapZoom);
+ float[] goalP = LLToXY(goalLon, goalLat, mapCenterLon, mapCenterLat, mapZoom);
+ goalP[0] -= 5;
+ float[] goalP2 = XYToLL((int)goalP[0], (int)goalP[1], mapCenterLon, mapCenterLat, mapZoom);
- serverGoalLat = goalP2[0];
- serverGoalLon = goalP2[1];
+ goalLat = goalP2[1];
+ goalLon = goalP2[0];
}
}
}
@@ -81,12 +110,12 @@ boolean onKeyDown(int keyCode, KeyEvent event) {
else {
settingGoal = true;
if (mapImg != null) {
- float[] goalP = LLToXY(serverGoalLat, serverGoalLon, mapCenterLat, mapCenterLon, mapZoom);
- goalP[0] -= 5;
- float[] goalP2 = XYToLL((int)goalP[0], (int)goalP[1], mapCenterLat, mapCenterLon, mapZoom);
+ float[] goalP = LLToXY(goalLon, goalLat, mapCenterLon, mapCenterLat, mapZoom);
+ goalP[0] += 5;
+ float[] goalP2 = XYToLL((int)goalP[0], (int)goalP[1], mapCenterLon, mapCenterLat, mapZoom);
- serverGoalLat = goalP2[0];
- serverGoalLon = goalP2[1];
+ goalLat = goalP2[1];
+ goalLon = goalP2[0];
}
}
}
@@ -96,12 +125,12 @@ boolean onKeyDown(int keyCode, KeyEvent event) {
else {
settingGoal = true;
if (mapImg != null) {
- float[] goalP = LLToXY(serverGoalLat, serverGoalLon, mapCenterLat, mapCenterLon, mapZoom);
- goalP[1] += 5;
- float[] goalP2 = XYToLL((int)goalP[0], (int)goalP[1], mapCenterLat, mapCenterLon, mapZoom);
+ float[] goalP = LLToXY(goalLon, goalLat, mapCenterLon, mapCenterLat, mapZoom);
+ goalP[1] -= 5;
+ float[] goalP2 = XYToLL((int)goalP[0], (int)goalP[1], mapCenterLon, mapCenterLat, mapZoom);
- serverGoalLat = goalP2[0];
- serverGoalLon = goalP2[1];
+ goalLat = goalP2[1];
+ goalLon = goalP2[0];
}
}
}
@@ -111,12 +140,12 @@ boolean onKeyDown(int keyCode, KeyEvent event) {
else {
settingGoal = true;
if (mapImg != null) {
- float[] goalP = LLToXY(serverGoalLat, serverGoalLon, mapCenterLat, mapCenterLon, mapZoom);
- goalP[1] -= 5;
- float[] goalP2 = XYToLL((int)goalP[0], (int)goalP[1], mapCenterLat, mapCenterLon, mapZoom);
+ float[] goalP = LLToXY(goalLon, goalLat, mapCenterLon, mapCenterLat, mapZoom);
+ goalP[1] += 5;
+ float[] goalP2 = XYToLL((int)goalP[0], (int)goalP[1], mapCenterLon, mapCenterLat, mapZoom);
- serverGoalLat = goalP2[0];
- serverGoalLon = goalP2[1];
+ goalLat = goalP2[1];
+ goalLon = goalP2[0];
}
}
}
@@ -139,12 +168,22 @@ boolean onKeyDown(int keyCode, KeyEvent event) {
}
}
- if (keyCode == 108) {
+ if (keyCode == 100) {//triange
+ if (mode == 1) {
+ String strSend = "goalClear:";
+ sendThis= strSend;
+ // talk.SendToAllFriends(strSend);
+ }
+ }
+ if (keyCode == 108) { //Start
+ /*
String strSend = "goalSet:";
strSend += currentLatitude+";";
strSend += currentLongitude;
strSend = strSend.replace(".", "*");
- talk.SendToAllFriends(strSend);
+ talk.SendToAllFriends(strSend);*/
+ goalLat = 55.647434;
+ goalLon = 12.555727;
/* latSaved = currentLatitude;
lonSaved = currentLongitude; */
}
@@ -156,9 +195,11 @@ boolean onKeyDown(int keyCode, KeyEvent event) {
talk.SendToAllFriends(strSend);
}*/
if (keyCode == 82) {
- mapImg = loadImage("http://maps.google.com/maps/api/staticmap?center="+serverLat+","+serverLon+"&zoom=+"+mapZoom+"&size=350x480&sensor=false", "jpg");
+ mapImg = loadImage("http://maps.google.com/maps/api/staticmap?center="+serverLat+","+serverLon+"&zoom=+"+mapZoom+"&size=350x480&sensor=false&maptype=satellite", "jpg");
mapCenterLat = serverLat;
mapCenterLon = serverLon;
+ goalLat = serverLat;
+ goalLon = serverLon;
}
if (keyCode == 109) {
@@ -188,6 +229,7 @@ boolean onKeyUp(int keyCode, KeyEvent event) {
rightRev = false;
fwdbkwOn = false;
}
+
if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
if (mode == 0) {
if (fwdbkwOn) {
@@ -195,10 +237,10 @@ boolean onKeyUp(int keyCode, KeyEvent event) {
}
}
else {
- settingGoal = false;
+ settingGoal = false;
String strSend = "goalSet:";
- strSend += serverGoalLat+";";
- strSend += serverGoalLon;
+ strSend += goalLat+";";
+ strSend += goalLon;
strSend = strSend.replace(".", "*");
talk.SendToAllFriends(strSend);
}
@@ -212,8 +254,8 @@ boolean onKeyUp(int keyCode, KeyEvent event) {
else {
settingGoal = false;
String strSend = "goalSet:";
- strSend += serverGoalLat+";";
- strSend += serverGoalLon;
+ strSend += goalLat+";";
+ strSend += goalLon;
strSend = strSend.replace(".", "*");
talk.SendToAllFriends(strSend);
}
@@ -222,10 +264,10 @@ boolean onKeyUp(int keyCode, KeyEvent event) {
if (mode == 0) {
}
else {
- settingGoal = false;
+ settingGoal = false;
String strSend = "goalSet:";
- strSend += serverGoalLat+";";
- strSend += serverGoalLon;
+ strSend += goalLat+";";
+ strSend += goalLon;
strSend = strSend.replace(".", "*");
talk.SendToAllFriends(strSend);
}
@@ -243,6 +285,11 @@ boolean onKeyUp(int keyCode, KeyEvent event) {
}
void draw() {
+ if (sendThis != null) {
+ talk.SendToAllFriends(sendThis);
+ sendThis = null;
+ }
+
if (latSaved != -1) {
latDiff = latSaved - currentLatitude;
lonDiff = lonSaved - currentLongitude;
@@ -254,24 +301,33 @@ void draw() {
background(0);
fill(255);
if (mapImg != null) {
+ ellipseMode(CENTER);
+
pushMatrix();
translate(screenWidth-350, 0);
image(mapImg, 0, 0, 350, 480);
- float[] centP = LLToXY(serverLat, serverLon, mapCenterLat, mapCenterLon, mapZoom);
- float[] weP = LLToXY(currentLatitude, currentLongitude, mapCenterLat, mapCenterLon, mapZoom);
- float[] goalP = LLToXY(serverGoalLat, serverGoalLon, mapCenterLat, mapCenterLon, mapZoom);
+ float[] centP = LLToXY(serverLon, serverLat, mapCenterLon, mapCenterLat, mapZoom);
+ float[] weP = LLToXY(currentLongitude, currentLatitude, mapCenterLon, mapCenterLat, mapZoom);
+ float[] goalP = LLToXY(goalLon, goalLat, mapCenterLon, mapCenterLat, mapZoom);
fill(255, 0, 0);
translate(0.5*350, 0.5*480);
//ellipse(centP[0], centP[1], 30, 30);
fill(0, 255, 0);
- ellipse(-weP[0], -weP[1], 30, 30);
+ ellipse(weP[0], weP[1], 30, 30);
+
+ fill(100, 100, 255);
+ for (int i=0;i<waypoints.size();i++) {
+ float[] p = LLToXY(waypoints.get(i)[1], waypoints.get(i)[0], mapCenterLon, mapCenterLat, mapZoom);
+ ellipse(p[0], p[1], 30, 30);
+ }
+
fill(0, 0, 255);
- ellipse(-goalP[0], -goalP[1], 30, 30);
+ ellipse(goalP[0], goalP[1], 30, 30);
fill(255, 0, 0);
pushMatrix();
- translate(-centP[0], -centP[1]);
+ translate(centP[0], centP[1]);
scale(0.3);
rotate(-serverCompas/360.0*TWO_PI);
beginShape();
@@ -314,7 +370,7 @@ void draw() {
pushMatrix();
translate(width/2, height/2);
scale(1);
- rotate(serverCompas/360.0*TWO_PI);
+ rotate(-serverCompas/360.0*TWO_PI);
beginShape();
vertex(0, -50);
vertex(-20, 60);
View
10 client/map.pde
@@ -1,13 +1,13 @@
-int offset=268435456;
+float offset=268435456.0;
float radius=offset/PI;
int LToX(float x) {
- return round(offset+radius*x*PI/180);
+ return round(offset+radius*x*PI/180.0);
}
int LToY(float y)
{
- return round(offset-radius*log((1+sin(y*PI/180))/(1-sin(y*PI/180)))/2);
+ return round(offset-radius*log((1+sin(y*PI/180.0))/(1-sin(y*PI/180.0)))/2.0);
}
float XToL(int x)
@@ -25,8 +25,8 @@ float[] Adjust(float X, float Y, float x, float y, int z, boolean w) {
float[] ret;
ret = new float[2];
if (w) {
- ret[0] = ((LToX(X)-LToX(x))>>(21-z));
- ret[1] = ((LToY(Y)-LToY(y))>>(21-z));
+ ret[0] = (LToX(X)-LToX(x))>>(21-z);
+ ret[1] = (LToY(Y)-LToY(y))>>(21-z);
}
else
View
49 client/osc.pde
@@ -1,5 +1,6 @@
XMPPMachine talk;
-
+import android.media.ToneGenerator;
+import android.media.AudioManager;
int leftSend = -1;
int rightSend = -1;
@@ -14,17 +15,17 @@ void setupOsc() {
void updateOsc() {
- if (millis() > lastMsg + 5000) {
-
- lastMsg = millis();
- String strSend = "diffSet:";
- // strSend += latDiff*10000+";";
- // strSend += lonDiff*10000;
- strSend += "0"+";";
- strSend += "0";
- strSend = strSend.replace(".", "*");
- talk.SendToAllFriends(strSend);
- }
+ /* if (millis() > lastMsg + 5000) {
+
+ lastMsg = millis();
+ String strSend = "diffSet:";
+ // strSend += latDiff*10000+";";
+ // strSend += lonDiff*10000;
+ strSend += "0"+";";
+ strSend += "0";
+ strSend = strSend.replace(".", "*");
+ talk.SendToAllFriends(strSend);
+ } */
if (leftSend != left || rightSend != right || leftRevSend != leftRev || rightRevSend != rightRev) {
// SendToAllFriends
String strSend = "motorSet:";
@@ -63,11 +64,6 @@ void parseChat(String msg) {
pin = arr1[1].replaceAll("goalInfo:", ""); // get 'pin)'
arr = pin.split(";");
-
- if ((Float.parseFloat(arr[0]) != serverGoalLat || Float.parseFloat(arr[1]) != serverGoalLon) && !settingGoal) {
- serverGoalLat = Float.parseFloat(arr[0]);
- serverGoalLon = Float.parseFloat(arr[1]);
- }
serverGoalDistance = Float.parseFloat(arr[2]);
pin = arr1[2].replaceAll("modeInfo:", ""); // get 'pin)'
@@ -88,6 +84,25 @@ void parseChat(String msg) {
leftRev = (Integer.parseInt(arr[2])>0)?true:false;
rightRev = (Integer.parseInt(arr[3])>0)?true:false;
}
+
+ pin = arr1[5].replaceAll("waypointInfo:", ""); // get 'pin)'
+ arr = pin.split(";");
+
+ waypoints.clear();
+ for (int i=0;i<arr.length;i+=2) {
+ float[] arr2 = new float[2];
+ arr2[0] = Float.parseFloat(arr[i]);
+ arr2[1] = Float.parseFloat(arr[i+1]);
+ waypoints.add(arr2);
+ }
+
+ pin = arr1[6].replaceAll("waypointSelInfo:", ""); // get 'pin)'
+ if (serverSelectedWaypoint != Integer.parseInt(pin)) {
+ ToneGenerator tone = new ToneGenerator(AudioManager.STREAM_MUSIC, 100);
+ tone.startTone(ToneGenerator.TONE_CDMA_EMERGENCY_RINGBACK, 2000);
+
+ serverSelectedWaypoint = Integer.parseInt(pin);
+ }
}
}
View
2  server/arduino.pde
@@ -38,7 +38,7 @@ void updateArduino(){
(byte) right
,(byte) left
,(byte) (rightRev?100:0)
- ,(byte) (leftRev?0:100)
+ ,(byte) (leftRev?100:0)
}
);
}
View
29 server/navigation.pde
@@ -1,9 +1,20 @@
+float[] getCurrentWaypoint() {
+
+ if (waypoints.size() > currentWaypoint) {
+ return waypoints.get(currentWaypoint);
+ }
+ else {
+ return null;
+ }
+}
+
float distanceToGoal() {
- if (curLocation != null) {
+ if (curLocation != null && getCurrentWaypoint() != null) {
Location goal = new Location(curLocation);
- goal.setLatitude(latGoal+latDiff);
- goal.setLongitude(lonGoal+lonDiff);
+
+ goal.setLatitude(getCurrentWaypoint()[0]);
+ goal.setLongitude(getCurrentWaypoint()[1]);
float d = curLocation.distanceTo(goal);
@@ -13,11 +24,11 @@ float distanceToGoal() {
}
float rotationToGoal() {
- if (curLocation != null) {
+ if (curLocation != null && getCurrentWaypoint() != null) {
Location goal = new Location(curLocation);
- goal.setLatitude(latGoal+latDiff);
- goal.setLongitude(lonGoal+lonDiff);
+ goal.setLatitude(getCurrentWaypoint()[0]);
+ goal.setLongitude(getCurrentWaypoint()[1]);
float bearing = curLocation.bearingTo(goal);
@@ -41,11 +52,11 @@ void autopilot() {
float dir = -rotationToGoal();
- if (abs(dir) < 10) {
+ if (abs(dir) < 20) {
leftRev = false;
rightRev = false;
- float d = 1-abs(dir)/10;
+ float d = 1-abs(dir)/20.0;
if (dir < 0) {
left = 255;
right = (int)(255*d);
@@ -55,7 +66,7 @@ void autopilot() {
left = (int)(255*d);
}
}
- if (abs(dir) < 30) {
+ else if (abs(dir) < 30) {
leftRev = false;
rightRev = false;
View
45 server/osc.pde
@@ -37,6 +37,15 @@ void updateOsc() {
strSend += (leftRev?1:0)+";";
strSend += (rightRev?1:0);
+ strSend += "#waypointInfo:";
+ for (int i=0;i<waypoints.size();i++) {
+ strSend += waypoints.get(i)[0]+";"+waypoints.get(i)[1]+";";
+ }
+
+
+ strSend += "#waypointSelInfo:";
+ strSend += currentWaypoint;
+
strSend = strSend.replace(".", "*");
println("Send"+strSend);
talk.SendToAllFriends(strSend);
@@ -44,9 +53,9 @@ void updateOsc() {
}
void parseChat(String msg) {
- msg = msg.replace("*",".");
-
- println(msg);
+ msg = msg.replace("*", ".");
+
+ println(msg);
if (msg.startsWith("motorSet:")) {
println("Set motor:");
@@ -61,6 +70,29 @@ void parseChat(String msg) {
rightRev = (Integer.parseInt(arr[3])>0)?true:false;
}
+
+ if (msg.startsWith("goalClear:")) {
+ waypoints.clear();
+ }
+ if (msg.startsWith("goalRestart:")) {
+ currentWaypoint = 0;
+ }
+
+ if (msg.startsWith("goalAdd:")) {
+ String pin = msg.replaceAll("goalAdd:", ""); // get 'pin)'
+ // pin = pin.substring(0, pin.indexOf(")")); // strip the last )
+ String arr[] = pin.split(";");
+
+ for (int i=0;i<arr.length;i+=2) {
+ float[] arr2 = new float[2];
+ arr2[0] =(float) Double.parseDouble(arr[i]);
+ arr2[1] =(float) Double.parseDouble(arr[i+1]);
+
+ waypoints.add(arr2);
+ }
+
+ println("Set lat: "+latGoal+" long:" + lonGoal);
+ }
if (msg.startsWith("goalSet:")) {
String pin = msg.replaceAll("goalSet:", ""); // get 'pin)'
@@ -69,7 +101,7 @@ void parseChat(String msg) {
latGoal =(float) Double.parseDouble(arr[0]);
lonGoal =(float) Double.parseDouble(arr[1]);
-
+
println("Set lat: "+latGoal+" long:" + lonGoal);
}
@@ -77,8 +109,8 @@ void parseChat(String msg) {
String pin = msg.replaceAll("modeSet:", ""); // get 'pin)'
mode = Integer.parseInt(pin);
}
-
- if (msg.startsWith("diffSet:")) {
+
+ if (msg.startsWith("diffSet:")) {
String pin = msg.replaceAll("diffSet:", ""); // get 'pin)'
// pin = pin.substring(0, pin.indexOf(")")); // strip the last )
@@ -87,6 +119,5 @@ void parseChat(String msg) {
latDiff = Float.parseFloat(arr[0])/10000.0;
lonDiff = Float.parseFloat(arr[1])/10000.0;
}
-
}
View
18 server/server.pde
@@ -20,12 +20,14 @@ PFont androidFont;
float latDiff = 0;
float lonDiff = 0;
+ArrayList<float[]> waypoints;
+int currentWaypoint = 0;
+
void setup()
{
-
-
orientation(PORTRAIT);
frameRate(30);
+ waypoints = new ArrayList<float[]>();
setupArduino();
setupOsc();
@@ -56,7 +58,9 @@ void onPause() {
void draw()
{
-
+ if (distanceToGoal() < 8 && distanceToGoal() > 0 && currentWaypoint < waypoints.size()) {
+ currentWaypoint ++;
+ }
updateOsc();
if (mousePressed) {
@@ -137,10 +141,10 @@ void draw()
text("G Longitude: "+lonGoal, 20, 180+300);
- if (curLocation != null) {
+ if (curLocation != null && getCurrentWaypoint() != null) {
Location goal = new Location(curLocation);
- goal.setLatitude(latGoal+latDiff);
- goal.setLongitude(lonGoal+lonDiff);
+ goal.setLatitude(getCurrentWaypoint()[0]);
+ goal.setLongitude(getCurrentWaypoint()[1]);
float distance = goal.distanceTo(curLocation);
float bearing = curLocation.bearingTo(goal);
@@ -149,7 +153,7 @@ void draw()
text("G Bearing: "+rotationToGoal(), 20, 240+300);
}
text("Bearing: "+direction/TWO_PI*360, 20, 275+300);
- text("Mode: "+mode, 20, 310+300);
+ text("Mode: "+mode+" waypoint: "+currentWaypoint+"/"+waypoints.size(), 20, 310+300);
pushMatrix();
translate(width/2, 230);
Please sign in to comment.
Something went wrong with that request. Please try again.