Skip to content
Aryaman Arora edited this page Nov 2, 2017 · 5 revisions

Some notes.

The holy grail.

Straight movement

void forward(float revolutions) {
	nSyncedMotors = synchBC;
	nMotorEncoder[motorB] = 0;
	nMotorEncoderTarget[motorB] = revolutions * 360;

	nSyncedTurnRatio = 100;
	motor[motorB] = (revolutions > 0) ? 50 : -50;

	while(nMotorRunState[motorB] != runStateIdle) {}
}

void forward_cm(float cm) {
	forward((5 * (cm / 90)) * 100/98); // I just made up this number, and it works sooo...
}

Turning

Swing turns

Please never do these, do a pivot turn instead.

void swing_turn(float degrees) {
	nSyncedMotors = synchNone;

	if (degrees >= 0) {
		nMotorEncoder[motorB] = 0;
		nMotorEncoderTarget[motorB] = 2 * 360 * (degrees/180);

		motor[motorB] = 30;
		while(nMotorRunState[motorB] != runStateIdle) {}

		motor[motorB] = 0;
	}
	else {
		nMotorEncoder[motorC] = 0;
		nMotorEncoderTarget[motorC] = 2 * 360 * (degrees/180);

		motor[motorC] = 10;
		while(nMotorRunState[motorC] != runStateIdle) {}

		motor[motorC] = 0;
	}
}

Pivot turns

The most recent code used for pivot turns is this:

void pivot_turn(float degrees) {
	nSyncedTurnRatio = -100;
	nMotorEncoder[motorB] = 0;
	nMotorEncoderTarget[motorB] = 350 * (degrees/180);
	if (degrees > 0) {
		motor[motorB] = 20;
	}
	else {
		motor[motorB] = -20;
	}

	while(nMotorRunState[motorB] != runStateIdle) {}
	nSyncedTurnRatio = 100;
	motor[motorB] = 0;
}

nMotorEncoderTarget[motorB] seems to vary daily though... expect anything between 350 * (degrees/180) and 390 * (degrees/180).

Times

ClearTimer(T1); // resets timer 1 (there are 4 timers)
time1[T1]; // time in ms

Clone this wiki locally