Ejemplo n.º 1
0
// Polls the inputs and obtains new sensor readings. 
// Updates LED indicators and detects button presses
void Update()
{
	// Gets new sensor readings
	left = analogRead(LEFT_SENSOR);
	right = analogRead(RIGHT_SENSOR);
	leftDetected = left < thresholdLeft;
	rightDetected = right < thresholdRight;

	// Detects button presses and decrements the LCD counter
	if(StopButton()) MENU = true;
	if(StartButton()) MENU = false;
	lcdRefreshCount = (lcdRefreshCount <= 0) ? lcdRefreshPeriod : (lcdRefreshCount - 1);

	// Reverse direction if bumper pressed
	if(LeftBumper()) direction = RIGHT;
	else if (RightBumper()) direction = LEFT;
}
Ejemplo n.º 2
0
// Polls the inputs and obtains new sensor readings. 
// Updates LED indicators and detects button presses
void Update()
{
	// Gets new sensor readings
	left = analogRead(LEFT_SENSOR);
	right = analogRead(RIGHT_SENSOR);
	leftDetected = left > threshold;
	rightDetected = right > threshold;

	// Updates the LED tape-detect indicators. Pin logic is inverted
	digitalWrite(LEFT_LED, !leftDetected);
	digitalWrite(RIGHT_LED, !rightDetected);
	digitalWrite(ERROR_LED, !((!leftDetected) && (!rightDetected)));

	// Detects button presses and decrements the LCD counter
	if(StopButton()) MENU = true;
	if(StartButton()) MENU = false;
	lcdRefreshCount = (lcdRefreshCount <= 0) ? lcdRefreshPeriod : (lcdRefreshCount - 1);

	// Reverse direction if bumper pressed
	if(LeftBumper()) direction = RIGHT;
	else if (RightBumper()) direction = LEFT;
}
Ejemplo n.º 3
0
// Displays a tuning parameter on the LCD
void ProcessMenu()
{
	motor.stop_all();
	int debounceTime = 200;
	int knobValue = knob(VALUE_ADJUST_KNOB) / 4;
	LCD.clear(); LCD.setCursor(0,1);
	LCD.print("Set to "); LCD.print(knobValue); LCD.print("?");
	LCD.home();

	int menuItem = knob(MENU_ADJUST_KNOB) / 200; // Divides by 256 to reduce possible values
	switch (menuItem)
	{
	case SPEED:
		LCD.print("Speed: ");
		LCD.print(speed);
		if (!StopButton(debounceTime)) break;
		speed = knobValue * 4;
		EEPROM.write(SPEED, speed / 4); // divide by four to prevent overflow (EEPROM max is 255)
		break;
	case PROPORTIONAL_GAIN:
		LCD.print("P Gain: ");
		LCD.print(proportionalGain);
		if (!StopButton(debounceTime)) break;
		proportionalGain = knobValue;
		EEPROM.write(PROPORTIONAL_GAIN, proportionalGain);
		break;
	case DERIVATIVE_GAIN:
		LCD.print("D Gain: ");
		LCD.print(derivativeGain);
		if (!StopButton(debounceTime)) break;
		derivativeGain = knobValue;
		EEPROM.write(DERIVATIVE_GAIN, derivativeGain);
		break;
	case THRESHOLD:
		LCD.print("TH: ");
		LCD.print((int)threshold);
		LCD.print(" ");
		LCD.print(left);
		LCD.print(" ");
		LCD.print(right);
		if (!StopButton(debounceTime)) break;
		threshold = knobValue * 2;
		EEPROM.write(THRESHOLD, threshold / 2);
		break;
	case PERPENDICULAR:
		LCD.print("PERP: ");
		LCD.print((int)perpendicular);
		if (!StopButton(debounceTime)) break;
		perpendicular = knobValue;
		EEPROM.write(PERPENDICULAR, perpendicular);
		break;
	default:
		LCD.print("PERP: ");
		LCD.print((int)perpendicular);
		if (!StopButton(debounceTime)) break;
		perpendicular = knobValue;
		EEPROM.write(PERPENDICULAR, perpendicular);
		break;
	}
	delay(30); // Pauses to prevent screen flicker
}
Ejemplo n.º 4
0
// Displays a tuning parameter on the LCD
void ProcessMenu()
{
	motor.stop_all();
	int debounceTime = 200;
	int knobValue = knob(VALUE_ADJUST_KNOB);
	LCD.clear(); LCD.setCursor(0,1);
	LCD.print("Set to "); LCD.print(knobValue); LCD.print("?");
	LCD.home();

	int menuItem = knob(MENU_ADJUST_KNOB) / 100; // Divides by 1 to reduce possible values to something like 10
	switch (menuItem)
	{
		case SPEED:
		LCD.print("Speed: ");
		LCD.print(speed);
		if (!StopButton(debounceTime)) break;
		speed = knobValue ;
		EEPROM.write(SPEED, speed / 4); // divide by four to prevent overflow (EEPROM max is 255)
		break;
		case PROPORTIONAL_GAIN:
		LCD.print("P Gain: ");
		LCD.print(proportionalGain);
		if (!StopButton(debounceTime)) break;
		proportionalGain = knobValue;
		EEPROM.write(PROPORTIONAL_GAIN, proportionalGain/4);
		break;
		case DERIVATIVE_GAIN:
		LCD.print("D Gain: ");
		LCD.print(derivativeGain);
		if (!StopButton(debounceTime)) break;
		derivativeGain = knobValue;
		EEPROM.write(DERIVATIVE_GAIN, derivativeGain/4);
		break;
		case INTEGRAL_GAIN:
		LCD.print("I Gain: ");
		LCD.print(integralGain);
		if (!StopButton(debounceTime)) break;
		integralGain = knobValue;
		EEPROM.write(INTEGRAL_GAIN, integralGain/4);
		break;
		case THRESHOLD_LEFT:
		LCD.print("TH L: ");
		LCD.print((int)thresholdLeft);
		LCD.print(" ");
		LCD.print(left);
		if (!StopButton(debounceTime)) break;
		thresholdLeft = knobValue;
		EEPROM.write(THRESHOLD_LEFT, thresholdLeft / 4);
		break;
		case THRESHOLD_RIGHT:
		LCD.print("TH R: ");
		LCD.print((int)thresholdRight);
		LCD.print(" ");
		LCD.print(right);
		if (!StopButton(debounceTime)) break;
		thresholdRight = knobValue;
		EEPROM.write(THRESHOLD_RIGHT, thresholdRight / 4);
		break;
		case PERPENDICULAR:
		LCD.print("PERP: ");
		LCD.print((int)perpendicular);
		if (!StopButton(debounceTime)) break;
		perpendicular = knobValue;
		EEPROM.write(PERPENDICULAR, perpendicular /4 );
		break;
		case TURN_COMPENSATION:
		LCD.print("COMP: ");
		LCD.print((int)turnCompensationGain);
		if (!StopButton(debounceTime)) break;
		turnCompensationGain = knobValue;
		EEPROM.write(TURN_COMPENSATION, turnCompensationGain /4 );
		break;
		default:
		LCD.print("PERP: ");
		LCD.print((int)perpendicular);
		if (!StopButton(debounceTime)) break;
		perpendicular = knobValue;
		EEPROM.write(PERPENDICULAR, perpendicular / 4);
		break;
	}
	delay(30); // Pauses to prevent screen flicker
}