Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
//WAVEFRONT ALGORITHM#include <stdlib.h>//in main, declare map matrix //6x6 mapint nothing=0;int wall=255;int goal=1;int robot=254;int robot_x=4;int robot_y=4;//map locationsint x=0;int y=0;//temp variablesint temp_A=0;int temp_B=0;//when searching for a node with a lower valueint minimum_node=250;int map[6][6]= {{0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}};//declare functions here, firstvoid propagate_wavefront(int robot_x, int robot_y);void unpropagate(int robot_x, int robot_y);void trace_path(int x, int y);int min_surrounding_node_value(int x, int y);void print_map(void);int main(void) { fopen("results.txt","w"); printf("Starting Wavefront\n\r"); fprintf("results.txt","Starting Wavefront\n\r"); //declare robot location and start propagation propagate_wavefront(5, 3); fclose("results.txt"); return 0; }void propagate_wavefront(int robot_x, int robot_y) { //clear old wavefront unpropagate(robot_x, robot_y); //old robot location was deleted, store new robot location in map map[robot_x][robot_y]=robot; printf("now unpropagated\n\r"); //start location to begin scan at goal location map[2][0]=goal; x=2; y=0; while(x<6 || y<6)//while the map hasnt been fully scanned { //if this location is a wall or the goal, just ignore it if (map[x][y] != wall && map[x][y] != goal) { //a full trail to the robot has been located, finished! if (min_surrounding_node_value(x, y) < 250 && map[x][y]==robot) { trace_path(x,y);//tell robot to start moving down path return; } //record a value in to this node else map[x][y]=minimum_node+1; } //go to next node and/or row x++; if (x==6) { y++; x=0; } } print_map(); }void unpropagate(int robot_x, int robot_y)//clears old path to determine new path { x=0; y=0; //stay within boundary while(x<6 || y<6)//while the map hasnt been fully scanned { if (map[x][y] != wall) //if this location is a wall, just ignore it { if (map[x][y] != goal) map[x][y] = nothing;//clear that space } //go to next node and/or row x++; if (x==6) { y++; x=0; } } }void trace_path(int x, int y) { //look at robot location //find minimum value around robot //min_surrounding_node_value(x, y) printf("\n\r finished"); fprintf("results.txt", "\n\r finished"); //send move command to robot to that location //robot_move(to that location) }//this function looks at a node and returns the lowest value around that nodeint min_surrounding_node_value(int x, int y) { minimum_node=250;//reset minimum //right if(x+1 < 6)//not out of boundary if (map[x+1][y] < minimum_node && map[x+1][y] != nothing)//find the lowest number node, and exclude empty nodes (0's) minimum_node = map[x+1][y]; //left if(x-1 >= 0) if (map[x-1][y] < minimum_node && map[x-1][y] != nothing) minimum_node = map[x-1][y]; //top if(y+1 < 6) if (map[x][y+1] < minimum_node && map[x][y+1] != nothing) minimum_node = map[x][y+1]; //bottom if(y-1 >= 0) if (map[x][y-1] < minimum_node && map[x][y-1] != nothing) minimum_node = map[x][y-1]; return minimum_node; }void print_map(void) { for (temp_B=0;temp_B<6;temp_B++) { for (temp_A=0;temp_A<6;temp_A++) { printf("%d",map[temp_A][temp_B]);//print out the X row first fprintf("results.txt", "%d",map[temp_A][temp_B]); } printf("\n\r");//then go to next line Y fprintf("results.txt", "\n\r"); } }/*pseudocodestart at top left if node == robot end else if node == wall ignore else check 4 sides save lowest number (nothing=0 doesnt count) set current node as lowest number + 1go to next node*/
char output1 = "P";FILE *out; out = fopen( "output.txt", "w" ); if( out != NULL ) fprintf( out, "output = ", output1 );
int output_int = 14 ; float output_float = 0.3674522322 ; char *output_string = "moooooooooo\n" ; FILE *fp ; fp = fopen( "output.txt" , "w" ) ; if( fp ) { fprintf( fp , "hello world %d %f %s\n" , output_int , output_float , output_string ) ; fclose( fp ) ; }
system("pause");
FILE *out ; out = fopen("results.txt","w"); if( out != NULL ) fprintf(out,"Starting Wavefront\n\r"); printf("Starting Wavefront\n\r");
So I compile my code with no problem, and it gives me an .exe. I run the file, it flashes a command prompt for about .05 seconds, then disappears . . .
#include <stdio.h>#include <stdlib.h>int main(int argc, char *argv[]){ printf("Pause test\n"); system("PAUSE"); return 0;}
You say this code:....closes on it own?
I also added in system("pause"); but with no effect
Did you #include <stdio.h>?
FILE *out ;int main(void) { out = fopen("results.txt","w"); if( out != NULL ) fprintf(out,"Starting Wavefront\n\r"); printf("Starting Wavefront\n\r"); //declare robot location and start propagation propagate_wavefront(5, 3); fclose(out); system("PAUSE"); return 0; }
C:\Documents and Settings\Pika\Desktop\MyRobots\iRobot Create>wave_front_simulation.exeStarting Wavefront
if( out != NULL ) fprintf(out,"Starting Wavefront\n\r");
getchar();
Does it completely work now or are you still having problems?