View Single Post
  #3   Spotlight this post!  
Unread 07-04-2014, 18:10
Kevin Selavko's Avatar
Kevin Selavko Kevin Selavko is offline
Registered User
AKA: Voltonless
FRC #3260 (SHARP)
Team Role: Electrical
 
Join Date: Jan 2012
Rookie Year: 2008
Location: Beaver PA USA
Posts: 155
Kevin Selavko is on a distinguished road
Re: How to loop peices of code forever?

You may want to posibly try this, I changed some things that might make it work a little better(or fail miserably):
Code:
#pragma config(Sensor, in1, pot, sensorPotentiometer)
#pragma config(Sensor, in3, LineLeft, sensorLineFollower)
#pragma config(Sensor, in4, LineRight, sensorLineFollower)
#pragma config(Sensor, in5, LineCenter, sensorLineFollower)
#pragma config(Sensor, dgtl1, touch, sensorTouch)
#pragma config(Sensor, dgtl2, Encoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl7, Encoder2, sensorQuadEncoder)
#pragma config(Motor, port2, arm, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port3, elbow, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port7, rightMotor, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor, port8, leftMotor, tmotorServoContinuousRotation, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

int threshold = 2000;
void lineFollower(int speed);

task main()
{
	while(true)
	{

		if(SensorValue(touch) == 0)
		{
			motor[arm] = 0;
		}

		if(SensorValue(touch) == 1)
		{
			motor[elbow] = -63;
			wait1Msec(1500);
			motor[elbow] = 0;			

			SensorValue[Encoder] = 0;
			while(SensorValue[Encoder] < 210)
			{
				lineFollower(60);
			}

			motor[arm] = 63;  // Brackets were wraped around this, is there suposed to be a loop or somthing here?
			wait1Msec(2000);

			motor[elbow] = 63;
			wait1Msec(200);

			motor[rightMotor] = 0;
			motor[leftMotor] = 0;
			wait1Msec(1000);

			motor[arm] = -63;
			wait1Msec(1800);

			motor[elbow] = -63;
			wait1Msec(2500);

			motor[elbow] = 0;
			wait1Msec(1000);

			motor[rightMotor] = -43;
			motor[leftMotor] = -43;
			wait1Msec(500);
		}

		SensorValue[Encoder] = 0;

		while(SensorValue[Encoder] > -450)
		{
			lineFollower(-60);
		}
	}
}

void lineFollower(int speed)  // Can help clean up your code and make it easier to read
{

	if(SensorValue(LineRight) > threshold && SensorValue(LineCenter) > threshold)
	{ // Added a slight turn to have a bit of a gentler correction when the robot is not that far off the line
		motor[leftMotor] = speed;
		motor[rightMotor] = (speed / 2);
	}
	else if(SensorValue(LineLeft) > threshold && SensorValue(LineCenter) > threshold)
	{
		motor[leftMotor] = 0;
		motor[rightMotor] = (speed / 2);
	}
	else if(SensorValue(LineCenter) > threshold)
	{
		motor[leftMotor] = speed;
		motor[rightMotor] = speed;
	}
	else if(SensorValue(LineRight) > threshold)
	{
		motor[leftMotor] = speed;
		motor[rightMotor] = 0;
	}
	else if(SensorValue(LineLeft) > threshold)
	{
		motor[leftMotor] = 0;
		motor[rightMotor] = speed;
	}
	else
	{
		motor[leftMotor] = 0;
		motor[rightMotor] = 0;

	}
}
__________________
Team SHARP
Pittsburgh Regional Champions 2014
Vex Pittsburgh Excellence Award 2014
Vex Pittsburgh Champions 2014
Vex Maryland Champions 2014
Pittsburgh Regional Finalists 2013
Buckeye Regional Finalists 2013