Ejemplo n.º 1
0
/**
Tests that the motors are wired up correctly.

When running, verify that the motor and direction printed over serial is what
is observed on the robot.

Also prints the change in encoder values after each movement - expect the
readings to positive, and correspond with the motor that moved
*/
void tests::motor_wiring() {
	Drive md;

	md.resetEncoders();

	if(md.faulted()) {
		Serial.println("Motor driver has a fault");
		md.clearFault();
		if(md.faulted()) {
			Serial.println("Motor driver still has a fault");
			return;
		}
	}
	else
		Serial.println("Motors are ok");

	{
		Serial.print("Motor R, forward: ");
		uint32_t encr = md.getMREncoder();
		uint32_t encl = md.getMLEncoder();
		Serial.flush();
		md.setMRSpeed(100);
		delay(2e3);
		md.setMRSpeed(0);
		int32_t diffr = md.getMREncoder() - encr;
		int32_t diffl = md.getMLEncoder() - encl;
		Serial.print("dr =");
		Serial.print(diffr);
		Serial.print(", dl =");
		Serial.println(diffl);
	}

	if(md.faulted())
		Serial.println("Motor driver has a fault");
	{
		Serial.print("Motor L, forward: ");
		uint32_t encr = md.getMREncoder();
		uint32_t encl = md.getMLEncoder();
		Serial.flush();
		md.setMLSpeed(100);
		delay(2e3);
		md.setMLSpeed(0);
		int32_t diffr = md.getMREncoder() - encr;
		int32_t diffl = md.getMLEncoder() - encl;
		Serial.print("dr =");
		Serial.print(diffr);
		Serial.print(", dl =");
		Serial.println(diffl);
	}
	if(md.faulted())
		Serial.println("Motor driver has a fault");
}
Ejemplo n.º 2
0
/**
Tests that the encoders work when the motors are spun BY HAND
*/
void tests::encoder_wiring() {
	Drive md;
	Serial.println("Turn the motors by hand");

	uint32_t lastr, lastl;
	while(true) {
		uint32_t encr = md.getMREncoder();
		uint32_t encl = md.getMLEncoder();
		if(encr != lastr || encl != lastl) {
			Serial.print(encr);
			Serial.print(", ");
			Serial.print(encl);
			Serial.println();
		}
		delay(10);
		lastl = encl;
		lastr = encr;
	}
}