示例#1
0
文件: Logic.c 项目: moeabbas/lfr
// Run the IHK line
void runLine(){

	LCDClear();

	static const uint8_t forwardDirection = 0;
	
	// Start speed, current speed.
	uint8_t currentSpeed = SPEED_CREEP;

	setDirectionMotorL(forwardDirection);
	setDirectionMotorR(forwardDirection);

	// Run until end of track.
	while(stopFlag == FLAG_NOT_SET)
	{
		if(getSensorUpdateFlag())
		{
			// When a line is lost after driving straight, go in search mode
			if(lostLineFlag == FLAG_SET)
			{
				searchMode();
				lostLineFlag = FLAG_NOT_SET;
			}

			// When line is found, make a Right turn
			// Increase speed and follow the line.
			if(foundLineFlag == FLAG_SET)
			{
				go(150,DIRECTION_RIGHT,SPEED_CREEP);
				setDirectionMotorL(forwardDirection);
				setDirectionMotorR(forwardDirection);
				currentSpeed = SPEED_CREEP;
				foundLineFlag = FLAG_USED;
			}
		
			// When following the line,
			// if front sensor detects obstacle,
			// exit line following loop
			if (foundLineFlag == FLAG_USED)
			{
				uint16_t distance = AdcConvert(1);
				
				if (distance > (uint16_t)500)
				{
					setStopFlag(FLAG_SET);
				}
			}

			// Calculate and set new duty cycle.
			calcDuty(currentSpeed, calcFloorErrorAndFlagControl());

			clearSensorUpdateFlag();
		}
	}

	// Stop the robot at end mark.
	setDutyCycleMotorL(0);
	setDutyCycleMotorR(0);
}
示例#2
0
bool obstacleDetectedInFront()
{
	uint16_t distance = AdcConvert(1);

	if (distance > (uint16_t)400)
	{
		return true;
	}

	return false;
}
示例#3
0
bool isExtremelyNearToObstacle()
{
	uint16_t distance = AdcConvert(2);

	if (distance > (uint16_t)500)
	{
		return true;
	}

	return false;
}
示例#4
0
bool hasAlignedWithObstacle()
{
	uint16_t distance = AdcConvert(2);

	if (distance > 250)
	{
		return true;
	}

	return false;
}
示例#5
0
bool isTooNearToObstacle()
{
	uint16_t distance = AdcConvert(2);

	if (distance > (uint16_t)400)
	{
		return true;
	}

	return false;
}
示例#6
0
bool isTooFarFromObstacle()
{
	uint16_t distance = AdcConvert(2);

	if (distance < (uint16_t)350)
	{	
		return true;
	}

	return false;
}
int main(void)
{
	DDRF = 0x00;
	DDRA = 0xFF;
	DDRB = 0xFF;
	
	sei();
	
	initAdc();
	
	
    /* Replace with your application code */
    while (1) 
    {
		_delay_ms(10);
		AdcConvert();
    }
	
	return 1;
}