void main(void) { Sys_Init(); //All init function putchar(' '); XBR0_Init(); ADC_Init(); Port_Init(); PCA_Init(); SMB_Init(); //end the init function lcd_clear(); lcd_print("initializing\r\n"); printf("\n\n\n\rinitalizing"); PCA0CP2 = 0xFFFF - MOTOR_NEUT;//set all to neutural PCA0CPL0 = 0xFFFF - PW_CENTER; PCA0CPH0 = (0xFFFF - PW_CENTER) >> 8; pause(); //pause for a second? start_run(); while (1) { while(SS){ // if the slideswitch is off slide_switch_off(); }///end slide switch off while(!SS){ //while the slideswitch is on Heading(); Ranger(); LCD_Print(); //print all values on the lcd printf("\n\rRange:%d Compass:%d dh: %d, mPW: %d, sPW %d, batt:%d, obst: %d", range, heading, desired_heading, MOTOR_PW_AND_STEER_PW, STEER_PW, battery, near_obstical); //print these on the secure crt for data aquisition //printf("\n\r Range:%d Compass:%d dh: %d, mPW: %d, sPW %d, obst: %d", range, heading, desired_heading, MOTOR_PW_AND_STEER_PW, STEER_PW, near_obstical); //print these on the secure crt for data aquisition }//end slide switch on } //end of the infinite while loop }//end of the main function
//----------------------------------------------------------------------------- // Main Function //----------------------------------------------------------------------------- void main(void) { int heading = 0; // initialize board Sys_Init(); putchar(' '); //the quotes in this line may not format correctly Port_Init(); XBR0_Init(); PCA_Init(); SMB0CR = 0x93; // set the frequency of the i2c bus to 95.41 kHz ENSMB = 1; //enable the SMBus //print beginning message //printf("Embedded Control Steering Calibration\n"); //calibrate_steering(); //printf("\rCalibrated\n"); while(1){ //Steering_Servo(); //printf("H = %d\n",h_counts); if(h_counts%2){ //printf("We are in %d", h_counts); heading = read_compass(); } if(!h_counts){ printf("\rThe Heading is: %u\n", heading); //print the heading } //else{printf("\rthis is h_coutn %d\n",h_counts);} } }
void main(void) { Sys_Init(); //All init function putchar(' '); XBR0_Init(); ADC_Init(); Port_Init(); PCA_Init(); SMB_Init(); //end the init function lcd_clear(); lcd_print("initializing\r\n"); PCA0CP2 = 0xFFFF - MOTOR_NEUT; PCA0CPL0 = 0xFFFF - PW_CENTER; PCA0CPH0 = (0xFFFF - PW_CENTER) >> 8; while (n_Counts < 50); //pause for a second? start_run(); while (1) { while(SS){ // if the slideswitch is off slide_switch_off(); }///end slide switch off while(!SS) //while the slideswitch is on { Heading(); Ranger(); LCD_Print(); //print all values on the lcd printf("\n\r Range:%d Compass:%d PW:%d", range, heading, PW); //print these on the secure crt for data aquisition } } //end of the infinite while loop }//end of the main function
//******************************************************************** // Main Functions //******************************************************************** void main(void) { //Main function Sys_Init(); // initialize board putchar(' '); //the quotes in this line may not format correctly Port_Init();//Init ports XBR0_Init();//init xbro PCA_Init();//init pca SMB_Init();//init smb printf("\r\n\n\n\nEmbedded Control Electric Compass and Ranger\n"); //print beginning message Calibration();//Run calibration comp_cal(); //Compass calibration Choose_heading(); //Heading choice printf("\r\nheading error"); while(1) { //inf loop, 40 ms it returns the heading if (new_heading){ //enough overflows for a new heading COMPASS STUFF new_heading = 0;//Clear new_heading heading = ReadCompass(); //get compass heading Steering_Servo(); //run steer func }//end if new heading if (new_range) { //if 80 ms has passed new_range=0;//Clear new_range range=ReadRanger();//read ranger start_ping();//start ping counts++;//set up text function Drive_Motor(); //run drive func }//end if new_range if (counts == 3){ //prevoudly output prined every 200 ms, now every 180 ms print_output();//Print data function. Delete this if faster output is desired }//end if counts }//end inf while }//end main
void main(void) { Sys_Init(); putchar(' '); XBR0_Init(); SMB_Init(); PCA_Init(); Drive_Init(); Port_Init(); ADC_Init(); ranger_pd_init(); //fan angle initialization code goes here while(1) { voltage_update(); if(SS) { Range_Update(); //update the range Drive_Motor(ranger_pd()); } else Drive_Motor(PW_NEUT); //if ss is not flipped, put it in neutral } }
void main(void) { Sys_Init(); putchar(' '); XBR0_Init(); PCA_Init(); i2c_Init(); while(1) { if (new_range) { new_range = 0; cmrange = ReadRanger(); Data[0] = 0x51; //write 0x51 to reg 0 of the ranger: i2c_write_data(ranger_addr, 0, Data, 1) ; // write one byte of data to reg 0 at addr printf("range = %d\r\n", cmrange); } } }
//----------------------------------------------------------------------------- // Main Function //----------------------------------------------------------------------------- void main(void) { // initialize board Sys_Init(); putchar(' '); //the quotes in this line may not format correctly Port_Init(); XBR0_Init(); PCA_Init(); ADC_Init(); SMB_Init(); //drive motor config printf("\rBegin Speed Controller Initialization\n"); PCA0CPL2 = 0xFFFF - PW_SC; PCA0CPH2 = (0xFFFF - PW_SC) >> 8; counts = 0; while(counts < 100); //wait 1 second printf("\rSC init finished\n"); //start_ping(); // set the PCA output to a neutral setting PW_SS = PW_CENTER_SS; PCA0CPL0 = 0xFFFF - PW_SS; PCA0CPH0 = (0xFFFF - PW_SS)>>8; /* //print beginning message printf("Embedded Control Steering Calibration\n"); printf ("\n\rr or l for direction, space for center, then right, then left\n\r"); while (flag < 3) { Steering_Config(); } */ //select heading/gain desired_heading = pick_heading(); gain_SS = pick_gain(); while(1) { //steering servo //ultrasonic ranger if(!SS1){ //switch is on Steering_Servo(); Ultrasonic_Ranger(); run_stop = 1; } else if(run_stop) { PW_SC = PW_NEUTRAL_SC; //drive motor stop PCA0CPL2 = 0xFFFF - PW_SC; PCA0CPH2 = (0xFFFF - PW_SC) >> 8; desired_heading = pick_heading(); gain_SS = pick_gain(); run_stop = 0; } if(new_display) { new_display = 0; Print_LCD(); } } }
//----------------------------------------------------------------------------- // Main Function //----------------------------------------------------------------------------- void main(void) { desired_range = 150; // initialize board Sys_Init(); putchar(' '); //the quotes in this line may not format correctly PCA_Init(); ADC_Init(); Interrupt_Init(); Port_Init(); XBR0_Init(); SMB_Init(); putchar('\r'); //print beginning message printf("En taro Adun, Executor!\r\n"); // set the PCA output to a neutral setting steering_neutral(); ranger_neutral(); wait(); /* Let stuff warm up */ // Get the PD constants and target heading from the keypad compass_kp = read_gain()/10.; desired_heading = read_heading(); compass_kd = read_gain_high(); ranger_kp = read_gain_thrust()/10.; ranger_kd = read_gain_thrust_high(); //Write the settings to the record printf ( "Compass KP = %d, Compass KD = %d, Desired Heading = %d, Ranger KP = %d, Ranger KD = %d, Desired Range = %d\r\n", compass_kp, compass_kd, desired_heading, ranger_kp, ranger_kd, desired_range ); printf ( "Time, heading, range\r\n "); PCA0CPL1 = 0xFFFF - 3200; PCA0CPH1 = ( 0xFFFF - 3200 ) >> 8 ; // Start at time 0. time = 0; while(1) /* Infinite loop is go */ { if ( nCounts == 50 ) { // Update the LCD loop lcd_clear(); lcd_print( "Batt level: %d\n", get_battery_voltage() ); lcd_print("Heading :%d\n", heading/10); lcd_print("Alt: %d", range ); if (SS) lcd_print("PAUSED\n"); else lcd_print("\n"); lcd_print("# forHead, * forGain"); } if ( read_keypad() != -1 ) { // Check the keypad pause(); if ( getKey() == '#' ) { // If # was pressed, get a new heading steering_neutral(); ranger_neutral(); desired_heading = read_heading(); time = 0; printf ( "Compass KP = %d, Compass KD = %d, Desired Heading = %d, Ranger KP = %d, Ranger KD = %d, Desired Range = %d\r\n", compass_kp, compass_kd, desired_heading, ranger_kp, ranger_kd, desired_range ); printf ( "Time, heading, range\r\n "); } else if( getKey() == '*' ) { // If * was pressed, get new gain contants steering_neutral(); ranger_neutral(); compass_kp = read_gain()/10.; compass_kd = read_gain_high(); ranger_kp = read_gain_thrust()/10.; ranger_kd = read_gain_thrust_high(); time = 0; printf ( "Compass KP = %d, Compass KD = %d, Desired Heading = %d, Ranger KP = %d, Ranger KD = %d, Desired Range = %d\r\n", compass_kp, compass_kd, desired_heading, ranger_kp, ranger_kd, desired_range ); printf ( "Time, heading, range\r\n "); } } else pause(); if(SS) //while the SS is off { //printf("The slide switch is OFF \r\n"); steering_neutral(); ranger_neutral(); } if(!SS) //SS is On { //printf("The Slide switch is On \r\n"); if ( new_heading ) printf("%lu,%d,%d\r\n", time, compass_old_error, ranger_old_error ); if (new_heading) //wait for 40ms { heading=read_compass(); //printf("The heading result is %d\r\n", heading); new_heading=0; Steering_Servo( ); } if (new_range) { ReadRanger( ); Speed_Cont( ); //adjust motor speed new_range=0; //reset ranger flag } } } }