int main(int argc, char** argv) { // Lab two problems problemOne(); problemTwo(); problemThree(); problemFour(); problemFive(); problemSix(); problemSeven(); problem8(); problem9(); problem10(); // Pass any applicable command line arguments to GLUT. These arguments // are platform dependent. glutInit(&argc, argv); // Set the initial window size glutInitWindowSize( 400, 400 ); // Create a window using a string and make it the current window. glutCreateWindow("CSE 618 Lab2"); // Indicate to GLUT that the flow of control should return to the program after // the window is closed and the GLUTmain loop is exited. glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS); // GLEW does not entirely support the Core GLUT Profile out of the box. // The following statement fixes the problem. glewExperimental = GL_TRUE; // Intilize GLEW. This must be done after glut is initialized. GLenum res = glewInit(); if (res != GLEW_OK) { fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res)); return false; // GLEW could not be initialized. } // Callback for window redisplay glutDisplayFunc(RenderSceneCB); glutReshapeFunc(ResizeCB); // Set window clear color glClearColor( 0.0f, 0.0f, 0.0f, 1.0f); // Unbind shader in use to enable fixed function pipeline functionality (compatability mode) glUseProgram(0); // Enter the GLUT main loop. Control will not return until the // window is closed. glutMainLoop(); return 0; } // end main
int main(int argc, char *argv[]){ //The gpio port numbers needed to drive the motor unsigned int gpio1 = 30; unsigned int gpio2 = 31; unsigned int gpio3 = 48; unsigned int gpio4 = 51; unsigned int gpio5 = 15; unsigned int gpios[4] = {gpio1, gpio2, gpio3, gpio4}; int gpio_fd1, gpio_fd2, gpio_fd3, gpio_fd4, gpio_fd5; int behavior = atoi(argv[1]); int rc; int len; int nfds = 2; //Port numbers for the analog in char AnalogIn1[] = "AIN0"; char AnalogIn2[] = "AIN1"; //char analogs[] = {AnalogIn1, AnalogIn2}; //printf("checking init analogs: %s \n", analogs[0]); char buf[64]; //Arrays to hold the values we get back from the sensors struct pollfd fdset[2]; int Sensor1_val; int Sensor2_val; //int Sensor_sum; int mode = atoi(argv[1]); //Initializes the position as zero, but we dont really know where this is int pos = 0; //Set up the gpios so we can use them to drive the motor gpio_export(gpio1); gpio_export(gpio2); gpio_export(gpio3); gpio_export(gpio4); gpio_export(gpio5); gpio_set_dir(gpio1, "out"); gpio_set_dir(gpio2, "out"); gpio_set_dir(gpio3, "out"); gpio_set_dir(gpio4, "out"); gpio_set_dir(gpio5, "in"); gpio_set_edge(gpio5, "rising"); gpio_fd1 = gpio_fd_open(gpio1, O_RDONLY); gpio_fd2 = gpio_fd_open(gpio2, O_RDONLY); gpio_fd3 = gpio_fd_open(gpio3, O_RDONLY); gpio_fd4 = gpio_fd_open(gpio4, O_RDONLY); gpio_fd5 = gpio_fd_open(gpio5, O_RDONLY); int cycle = 0; int minValue = 999999; int minPosition = 0; int Sensor_avg = 0; //Wait for the start button to be pushed before we acutally start doing anything printf("Press the start button to begin the program \n"); len = read(gpio_fd5, buf, 64); while(1){ memset((void*)fdset, 0, sizeof(fdset)); fdset[0].fd = STDIN_FILENO; fdset[0].events = POLLIN; fdset[1].fd = gpio_fd5; fdset[1].events = POLLPRI; rc = poll(fdset, nfds, 3000); if(rc < 0){ printf("Poll failed \n"); } if(fdset[1].revents & POLLPRI){ lseek(fdset[1].fd, 0, SEEK_SET); len = read(fdset[1].fd, buf, 64); printf("Triggered \n"); //pos = problemOne(gpios, pos); pos = problemTwo(gpios, AnalogIn1, AnalogIn2, pos, mode); //break; } } printf("Begining our steps to attempt to come up with "); for(cycle = 0; cycle <= MAX_CYCLES; cycle++){ printf("One cycle number: %d", cycle); Sensor1_val = analogIn(AnalogIn1); Sensor2_val = analogIn(AnalogIn2); Sensor_avg = (Sensor1_val + Sensor2_val)/ 2; if(Sensor_avg < minValue){ minValue = Sensor_avg; minPosition = cycle; } //Should move the IR sensors here } printf("%d\n", minValue); if(minPosition <=10){ //Rotate clockwise to position } else{ //Rotate counterclockwise to position } while(1){ Sensor1_val = analogIn(AnalogIn1); Sensor2_val = analogIn(AnalogIn2); if(Sensor1_val > Sensor2_val){ //Rotate clockwise once } else{ //Rotate counterclockwise } } return 0; }