Vex - EasyC - 180 Degree Turn - Noob Looking For Help

Hello! I am just wondering of how I can make a button trigger the robot to turn 180 degrees in operator control. I know the basics of EasyC so I can understand mostly what you are talking about when informing me about how to do this. I tried a bunch of joystick digital to motor but I don’t think it will work. Any help?

Thanks,

Murf.

ok, so this is a bit complicated, you will need a gyro to do this, or, you will need to know something to give you information about how many degrees you have turned. something like encoders would be ideal for this

the encoders are the easy way, but I think the gyro is a better way.

for the encoders, lets say you wanted to turn left you would say
LeftEncoderValue = RightEncoderValue = 0;
while( LeftEncoderValue > - target && RightEncoderValue < target){
leftdrivemotor = -127;
righDriveMotor = 127;
}
leftdrivemotor = rightdrivemotor = 0;

target would be something you determined experimentally, it would be the number of encoder tics to get to a 180 degree turn.

The other way would be to using a gryo. Using a gyro will allow you to turn to any angle, both relative to the field and relative to the robot. For example, you could turn 90 degrees to the left of where you are NOW, or you could turn to 90 degrees relative to the field.

for example, when I say relative to the field, I have a model for my robot, where if you stand where the drivers in a match stand, looking towards the side of the field with the goals on it, 0 degrees it directly to the right, and 90 degrees is directly in front of you. This allows you to point to a given direction, regardless of where you are facing at the moment you activate the command. Now I don’t know how easyC works, but to activate the command when you press a button in RobotC it would work like this

if(vexRT[Btn8D] == 1){

LeftEncoderValue = RightEncoderValue = 0;
while( LeftEncoderValue > - target && RightEncoderValue < target){
leftdrivemotor = -127;
righDriveMotor = 127;
}
leftdrivemotor = rightdrivemotor = 0;

}

Btn8D is a certain button on the vex controller, you could use any button you wanted

if you are interested in doing the gyro method let me know, I can post the code here for you

Thank You!:smiley:

I actually managed to do this really really well.

I posted the code here. It’s PROS and fairly complicated as I really tried to model the robot in a modular way.

Look at the turnHoloXCL function.

bool turnHoloXCL(Axle * a, Axle * b, ControlLoopConfig * cl, double degrees, Time timeout) {

	print("STARTING TURN-HOLO-X\r\n");

	ControlLoopData cld;
	controlLoopInit(&cld);

	timeout = millis() + timeout;		// Time to give up (timeout)

	resetTicksAxle(a);					// Reset the encoders
	resetTicksAxle(b);					// Reset the encoders

	short samples = 0;

	// Calculate distance
	double distance = M_PI * a->diameter * (degrees / 360);

	while(isAutonomous()	 || isEnabled()) {

		double alD = getDistanceFromAxle(a, LEFT);		// Compute distances for A
		double arD = getDistanceFromAxle(a, RIGHT);
		double blD = getDistanceFromAxle(b, LEFT);		// Compute distances for B
		double brD = getDistanceFromAxle(b, RIGHT);

		// Compute average distance traveled (ignoring sign)
		double aD = (alD + arD + blD + brD) / 4;

		// Are we within the range that we want to be?
		if(within(distance - aD, -.25, .25)) samples++;

		//printf("\tTURN-HOLO-X SAMPLES\t%d\r\n", samples);

		// Exit condition
		if(samples >= 50) {

			goGroup(a->left,		0);				goGroup(a->right,	0);
			goGroup(b->left,		0);				goGroup(b->right,	0);

			print("ENDING TURN-HOLO-X with a return of true\r\n");

			return true;

		}

		// PD code here - determine error correction speeds
		int speed = (int) computePid(cl, &cld, distance - aD, 0);

		// limit speed to 20 to -20
		if(speed < 0 && speed > -20)	speed = -20;
		if(speed > 0 && speed < 20)	speed = 20;

		printf("\tTURN-HOLO-X SPEED\t%d\r\n", speed);
		printf("\tTURN-HOLO-X ERROR\t%f\r\n", distance - aD);
		printf("\tTURN-HOLO-X DIST\t%f\r\n", distance);
		printf("\tTURN-HOLO-X AV DIST\t%f\r\n", aD);

		// Go
		goGroup(a->left,		speed);			goGroup(a->right,	speed);
		goGroup(b->left,		speed);			goGroup(b->right,	speed);

		delay(20);

		// Did we time out?
		if(millis() > timeout) {

			goGroup(a->left,		0);				goGroup(a->right,	0);
			goGroup(b->left,		0);				goGroup(b->right,	0);

			return false;

		}

	}

	return false;	// We became disabled outside of autonomous

}

It uses control loops and regularly got the robot turned within +/- about 2.5 degrees of it’s target.