Exemplo n.º 1
0
int main()
{
	init();
	pinMode(14, OUTPUT);
	pinMode(15, OUTPUT);
	digitalWrite(15, LOW);

	pinMode(radioPowerPin, OUTPUT);		// power cycle radio
	digitalWrite(radioPowerPin, LOW);
	delay(100);
	digitalWrite(radioPowerPin, HIGH);
	delay(100);

	pinMode(sonarPowerPin, OUTPUT);
	pinMode(sonarGroundPin, OUTPUT);
	digitalWrite(sonarGroundPin, LOW);
	digitalWrite(sonarPowerPin, HIGH);
	Sonar_Init();

	Radio_Init();
	Radio_Configure(RADIO_2MBPS, RADIO_HIGHEST_POWER);
	Radio_Configure_Rx(RADIO_PIPE_0, sensor_address, ENABLE);



	for (;;)
	{
		if (radio_flag)
		{
			radio_flag = 0;
			Radio_Receive(&packet);				// assumption: radio FIFO contains just one packet
			if (packet.type == REQUEST_ECHO)
			{
				Sonar_PreTrigger();
				Radio_Set_Tx_Addr(packet.payload.request.return_address);
				packet.type = CONFIRM_ECHO;
				packet.payload.confirm.station_id = STATION_ID;
				Radio_Transmit(&packet, RADIO_WAIT_FOR_TX);
				// sonar is triggered as soon as the explorer acknowledges it received the confirmation
				Sonar_Trigger();
				delay(50);
				digitalWrite(14, LOW);
			}
			packet.type = EMPTY;
		}
	}

	for (;;);
	return 0;
}
Exemplo n.º 2
0
int main(void) {
	LockoutProtection();
	InitializeMCU();
	
	//init uart
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);				
  GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);	
	UARTStdioInit(0);
	
	LED_Init();
	Jumper_Init();
	
	ADC_Init();
	Sonar_Init();
	
	usemotors = Jumper_Value & 0x8;
	
	if ((Jumper_Value & 0x7) == 0x1) {
		if (usemotors) {
			Motor_Init(false,true);
			Motor_Set(127,127);
		}
		avoid_sonar(0);
		avoid_ir(filtered_ir);
		for (;;);
	}
	
	if ((Jumper_Value & 0x7) == 0x2) {
		Travel_Init(usemotors);
		Travel_Go(FULL_SPEED);
		for (;;);
	}
	
	if ((Jumper_Value & 0x7) == 0x3) {
		if (usemotors) {
			Motor_Init(false,true);
			Motor_Set(127,127);
		}
		for (;;);
	}
	
	//if no jumpers are set, enter debug mode
	Encoder_Init(true,false);
	
	
	for (;;c++) {
		ADC_Background_Read(0);
		Sonar_Background_Read(0);
		Encoder_Background_Read(0);
		Jumper_Read();
		
		UARTprintf("ADC[%3d %3d %3d %3d %3d %3d %3d %3d]  S[%7d]  E[%3d %3d]  J[%1x] c:%d\n",
			ADC_Values[0],ADC_Values[1],ADC_Values[2],ADC_Values[3],ADC_Values[4],ADC_Values[5],ADC_Values[6],ADC_Values[7],
			Sonar_Value,
			Encoder_Values[0],Encoder_Values[1],
			Jumper_Value,
			c
		);
		
		LED_Set(LED_0,c);
		LED_Set(LED_1,c+64);
		LED_Set(LED_2,c+128);
		LED_Set(LED_3,c+192);

		WaitUS(20000);
	}
}