Beispiel #1
0
void Ultrasonic_Ranger() {
	if(new_range)
	{
		new_range = 0;
		range = read_ranger();
		start_ping();

		printf("\rRange: %d\n", range);

		//set motor
		if(range < 40)   //forward
		{
			if(range > 10)
				PW_SC = PW_MAX_SC - (PW_MAX_SC - PW_NEUTRAL_SC)*(range-10)/30.0;
			else
				PW_SC = PW_MAX_SC;
		}
		else if(range > 50)  //reverse
		{
			if(range < 90)
				PW_SC = PW_MIN_SC + (PW_NEUTRAL_SC - PW_MIN_SC)*(1 - (range-50)/40.0);
			else
				PW_SC = PW_MIN_SC;
		}
		else    //neutral
			PW_SC = PW_NEUTRAL_SC;

		
		printf("\rPW: %u\n", PW_SC);
		PCA0CPL2 = 0xFFFF - PW_SC;
    	PCA0CPH2 = (0xFFFF - PW_SC) >> 8;
	}
}
//********************************************************************
// 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
JNIEXPORT jlong JNICALL
Java_com_cs4911_video_1editor_android_BandwidthMeasurement_launchLatencyTest(JNIEnv * env, jobject  obj)
{
    return start_ping();   
}