Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: RouteCalculation.cpp
- Revision:
- 5:695c5531f65e
- Parent:
- 4:aff0722b4e50
- Child:
- 6:a1fd0f1374e6
diff -r aff0722b4e50 -r 695c5531f65e RouteCalculation.cpp
--- a/RouteCalculation.cpp Sat Apr 28 12:09:27 2018 +0000
+++ b/RouteCalculation.cpp Sun Apr 29 11:48:33 2018 +0000
@@ -99,21 +99,21 @@
//-----------------------------------------------------------------------
if (map[X-1][ Y-1] == 0){
- route[actionIndex][TYPE] = PLACETURN90;
+ route[actionIndex] = PLACETURN90;
direction = 1;
}else{
- route[actionIndex][TYPE] = FULLDRIVE;
+ route[actionIndex] = FULLDRIVE;
direction = 4;
}
- if(route[actionIndex][TYPE] == FULLDRIVE){
+ if(route[actionIndex] == FULLDRIVE){
while(map[X-1][Y] == 0){
if(X >= 1 | X <= 19){
X = X -2;
i = i + 1;
}
}
- route[actionIndex][LENGHT] = i;
+ route[actionIndex+1] = i;
actionIndex = actionIndex +1;
}
@@ -138,7 +138,7 @@
}
break;
- case 3: while(map[X][Y] == 0{ // Gegen unten
+ case 3: while(map[X][Y] == 0){ // Gegen unten
if (Y >= 1 | Y <= 7){
Y = Y + 2;
i = i + 1;
@@ -154,80 +154,80 @@
}
break;
}
- actionIndex = actionIndex + 1; // Zur nächstesten Aktion
- char *route = (char *)realloc(2*sizeof(char)); // Speicher für neue Aktion initialisieren
- route[actionIndex][TYPE] = FULLDRIVE; // Fahrmodus auf geradeausfahren
- route[actionIndex][LENGHT] = i; // Länge der Strecke eintragen
+ actionIndex = actionIndex + 2; // Zur nächstesten Aktion
+ route = (char *)realloc(route,(actionIndex+2)*sizeof(char)); // Speicher für neue Aktion initialisieren
+ route[actionIndex] = FULLDRIVE; // Fahrmodus auf geradeausfahren
+ route[actionIndex+1] = i; // Länge der Strecke eintragen
// ------------------------------------------------------------------------------------------- Drehungen fahren
switch(direction){
case 1: // Roboter gegen oben ausgerichtet
if(map[X][Y-1] == 0){ // gegen Rechts abbiegen
- actionIndex = actionIndex + 1; // Zur nächstesten Aktion
- char *route = (char*)realloc(2*sizeof(char)); // Speicher für neue Aktion initialisieren
- route[actionIndex][ TYPE] = TURNRIGHT;
- route[actionIndex][ LENGHT] = LEER;
+ actionIndex = actionIndex + 2; // Zur nächstesten Aktion
+ char *route = (char*)realloc(route,(actionIndex+2)*sizeof(char)); // Speicher für neue Aktion initialisieren
+ route[actionIndex] = TURNRIGHT;
+ route[actionIndex+1] = LEER;
direction = directionControl(DREHUNG_RECHTS, direction);
}
if(map[X-1][Y] == 0){ // gegen Links abbiegen
- actionIndex = actionIndex + 1;
- char *route = (char *)realloc(2*sizeof(char));
- route[actionIndex][ TYPE] = TURNLEFT;
- route[actionIndex][ LENGHT] = LEER;
+ actionIndex = actionIndex + 2;
+ route = (char *)realloc(route,(actionIndex+2)*sizeof(char));
+ route[actionIndex]= TURNLEFT;
+ route[actionIndex+1] = LEER;
direction = directionControl(DREHUNG_LINKS, direction);
}
case 2: // Roboter gegen rechts ausgerichtet
if(map[X-1][Y-1] == 0){ // gegen Oben abbiegen
- actionIndex = actionIndex + 1;
- char *route = (char *)realloc(2*sizeof(char));
- route[actionIndex][ TYPE] = TURNLEFT;
- route[actionIndex][ LENGHT] = LEER;
+ actionIndex = actionIndex + 2;
+ route = (char *)realloc(route,(actionIndex+2)*sizeof(char));
+ route[actionIndex]= TURNLEFT;
+ route[actionIndex+1] = LEER;
direction = directionControl(DREHUNG_LINKS, direction);
}
if(map[X][Y] == 0){ // gegen Unten abbiegen
- actionIndex = actionIndex + 1;
- char *route = (char *)realloc(2*sizeof(char));
- route[actionIndex][ TYPE] = TURNRIGHT;
- route[actionIndex][ LENGHT] = LEER;
+ actionIndex = actionIndex + 2;
+ route = (char *)realloc(route,(actionIndex+2)*sizeof(char));
+ route[actionIndex] = TURNRIGHT;
+ route[actionIndex+1] = LEER;
direction = directionControl(DREHUNG_RECHTS, direction);
}
case 3: // Roboter gegen Unten ausgerichtet (Seitenverkehrt)
if(map[X][Y-1] == 0){ // gegen Rechts abbiegen
- actionIndex = actionIndex + 1;
- char *route = (char *)realloc(2*sizeof(char));
- route[actionIndex][ TYPE] = TURNLEFT;
- route[actionIndex][ LENGHT] = LEER;
+ actionIndex = actionIndex + 2;
+ route = (char *)realloc(route,(actionIndex+2)*sizeof(char));
+ route[actionIndex] = TURNLEFT;
+ route[actionIndex+1] = LEER;
direction = directionControl(DREHUNG_LINKS, direction);
}
if(map[X-1][Y] == 0){ // gegen Links abbiegen
- actionIndex = actionIndex + 1;
- char *route = (char *)realloc(2*sizeof(char));
- route[actionIndex][ TYPE] = TURNRIGHT;
- route[actionIndex][ LENGHT] = LEER;
+ actionIndex = actionIndex + 2;
+ route = (char *)realloc(route,(actionIndex+2)*sizeof(char));
+ route[actionIndex] = TURNRIGHT;
+ route[actionIndex+1] = LEER;
direction = directionControl(DREHUNG_RECHTS, direction);
}
case 4: // Roboter gegen links ausgerichtet
if(map[X-1][Y-1] == 0){ // gegen oben abbiegen
- actionIndex = actionIndex + 1;
- char *route = (char *)realloc(2*sizeof(char));
- route[actionIndex][ TYPE] = TURNRIGHT;
- route[actionIndex][ LENGHT] = LEER;
+ actionIndex = actionIndex + 2;
+ route = (char *)realloc(route,(actionIndex+2)*sizeof(char));
+ route[actionIndex] = TURNRIGHT;
+ route[actionIndex+1] = LEER;
direction = directionControl(DREHUNG_RECHTS, direction);
}
if(map[X][Y] == 0){ // gegen unten abbiegen
- actionIndex = actionIndex + 1;
- char *route = (char *)realloc(2*sizeof(char));
- route[actionIndex][ TYPE] = TURNLEFT;
-
+ actionIndex = actionIndex + 2;
+ route = (char *)realloc(route,(actionIndex+2)*sizeof(char));
+ route[actionIndex] = TURNLEFT;
+ route[actionIndex+1] = LEER;
direction = directionControl(DREHUNG_LINKS, direction);
}
}
if (map[X][Y] == 100){
- char *route = (char *)realloc(2*sizeof(char));
- actionIndex = actionIndex + 1;
- route[actionIndex][ TYPE] = ZIEL;
- route[actionIndex][ LENGHT] = ZIEL;
+ route = (char *)realloc(route,(actionIndex+2)*sizeof(char));
+ actionIndex = actionIndex + 2;
+ route[actionIndex] = ZIEL;
+ route[actionIndex+1] = ZIEL;
}