Autonomus issue

Hello everyone, I have an issue. My team uses a potentiometer that allows us to use 4 programs. Anyways this is the code(I use ROBOTC):

task autonomous()
{

	if(SensorValue[autoSelector] > 0 && SensorValue[autoSelector] < breaks[0])
	{
                //Poten resets during pre-auto
		//FAILSAFE X.X
		Forward(500);
		Backward(500);
	}
	else if (SensorValue[autoSelector] > breaks[0] && SensorValue[autoSelector] < breaks[1])
	{
		//Red and Blue  next to skyrise pole
		Forward(6000);
		TurnLeft(2550);
		Forward(2000);
	}
	else if (SensorValue[autoSelector] > breaks[1] && SensorValue[autoSelector] < breaks[2])
	{
		//Red and Blue not Next to skyrise pole facing towards other robot
		TurnRight(1700);
		Backward(1000);
		TurnRight(740);
		Forward(150);
	}
	else if (SensorValue[autoSelector] > breaks[2] && SensorValue[autoSelector] < POT_MAX)
	{
		//Red and Blue Next to skyrise pole facing at it
		//Coming soon

	}

Anyways whenever autonomous starts, the robot goes forward, ramming into the wall, going back and going forward again. This is not always an issue but, sometimes it almost gets us DQ’d. If you know anything, Please help! :frowning:

What are the values inside of the break] array, and what are the function definitions of Forward(), Backward(), etc.?

What does your robot do if the only code in the autonomous() task is the following?


Forward(500);
Backward(500);

Thanks for the info. The codes for forward and backward:

void Forward(int time)
{
	motor [FrontRightMotor] = 80;
	motor [FrontLeftMotor] = 80;
	motor [BackLeftMotor] = 80;
	motor [BackRightMotor] = 80;
	wait1Msec(time);
	motor [FrontRightMotor] = 0;
	motor [FrontLeftMotor] = 0;
	motor [BackLeftMotor] = 0;
	motor [BackRightMotor] = 0;
}

void Backward (int time)
{
	motor [FrontRightMotor] = -90;
	motor [FrontLeftMotor] = -90;
	motor [BackLeftMotor] = -90;
	motor [BackRightMotor] = -90;
	wait1Msec(time);
	motor [FrontRightMotor] = 0;
	motor [FrontLeftMotor] = 0;
	motor [BackLeftMotor] = 0;
	motor [BackRightMotor] = 0;
}

Honestly I have no clue why I set one value to 80 and the other -90, I will change that:confused:.

Since i’m somewhat of an amatuer programmer when you mean the breaks do you mean:

//Resets Potentiometer
#define POT_MAX 4070
#define N_AUTO_MODES 4

int breakStep = POT_MAX / N_AUTO_MODES;
int breaks [N_AUTO_MODES - 1];
void pre_auton()
{

	bStopTasksBetweenModes = true;
	breaks [0] = breakStep;
	for(int i = 1; i < N_AUTO_MODES -1; i++ )
	{
		breaks* = breaks* +	breakStep;
	}


}

I’m at a competition so, I should be able to test it on Tuesday.**

I don’t see any thing wrong with your code. I’m a little confused on when this happens. I’m taking this only happens once in a while not every time. Does it matter what autonomous routine you select? The odd part is you so it goes forward, backward, and then forward yet I see no code that will do this. Maybe some one else will see what I’m missing, but more info would be helpful.

Post the turn code also.

is it possibly that the code is repeating inside the ‘if’ loop?

I’m relatively new to programming, but one reason I can think of would be that the if loop is behaving like the while(true) (or equivalent) loops used to constantly update for applications like in driver control. This could cause your functions to run as normal but continue to repeat until the 15 seconds is up.

I am sure it could be, Just looking at the code it has nothing to tell it to stop.

I’ll get to that tomorrow. (I need to update my flash drive :()

Yes, I’m Sorry about that, I’ll try to get more info and maybe even a video.:slight_smile:

UPDATE
During the semifinals we had a tie, so we started over. Autonomous started and the robot did not move at all. Driver control worked but, we lost.
I’m sure the potentiometer could have been unplugged but, it could also be a glitch due to how the autonomous is working. Thanks for the help guys :smiley:

An if statement is not a loop; the only way the contents of an if statement will repeat is if there’s a for or while loop inside or containing the if.

Thank you guys for the support. I have the code now and will posts what you need…

Turn Code

void TurnRight(int time)
{
	motor [FrontRightMotor] = 80;
	motor [FrontLeftMotor] = 80;
	motor [BackLeftMotor] = 0;
	motor [BackRightMotor] = 0;
	wait1Msec(time);
	motor [FrontRightMotor] = 0;
	motor [FrontLeftMotor] = 0;
	motor [BackLeftMotor] = 0;
	motor [BackRightMotor] = 0;
}

void TurnLeft (int time)
{
	motor [FrontRightMotor] = -80;
	motor [FrontLeftMotor] = -80;
	motor [BackLeftMotor] = 0;
	motor [BackRightMotor] = 0;
	wait1Msec(time);
	motor [FrontRightMotor] = 0;
	motor [FrontLeftMotor] = 0;
	motor [BackLeftMotor] = 0;
	motor [BackRightMotor] = 0;
}

Claw and arm (wrist is a scrapped idea)


//Claw and Arm w/ Wrist
void ClawOpen (int time)
{
	motor [ClawMotor] = 127;
	wait1Msec(time);
	motor [ClawMotor] = 0;
}

void ArmUp (int time)
{
	motor [ArmMotor1] = motor [ArmMotor2] = 127;
}

void ArmDown (int time)
{
	motor [ArmMotor1] = motor [ArmMotor2] = -127;
}

I’m sure I got all the info you guys need. I might switch to encoders because wait times aren’t always accurate.
If I’m able to get a video I will show you guys ;).

Your turn code is wrong that is what’s making it go forward, backward, and forward.

To turn you need to have the sides go in opposite direction for a “piviot” turn.

Ex right piviot turn:
FrontLeft = 80;
BackLeft = 80;
FrontRight = -80;
BackRight = -80;

You could also do a swing or wide turn to the right:
FrontLeft = 80;
BackLeft = 80;
FrontRight = 0;
BackRight = 0;

Also, another thing you might need to consider is that simply setting the motors to 0 may not stop your robot on the spot, depending on if it heavy and has some momentum when moving.

I don’t know how your robot is, but if it coasts to a stop you may want to apply a small braking power for a short amount of time. For example:
Motors (80)
Wait (time)
Motors (-10)
Wait (250msec)
Motors (0)