We are currently working on our PLTW Elevator code and use encoders to track our progress. When we press level two, the motor will run until the level is reached. Once we hit another button, the encoder will restart the count. What could be cause the encoder to reset.
#pragma config(Sensor, dgtl1, Bump1, sensorTouch)
#pragma config(Sensor, dgtl2, Bump2, sensorTouch)
#pragma config(Sensor, dgtl3, Bump3, sensorTouch)
#pragma config(Sensor, dgtl10, encoder, sensorQuadEncoder)
#pragma config(Motor, port2, motor, tmotorVex393_MC29, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//
task main()
{
while(true)
{
if(SensorValue(Bump1) ==1)
{
startMotor(port2, -127);
untilEncoderCounts(-8,dgtl10);
stopMotor(port2);
}
if(SensorValue(Bump2)==1)
{
if(SensorValue(encoder)<445)
{
startMotor(port2, 127);
untilEncoderCounts(450,encoder);
stopMotor(port2);
}
else //if(SensorValue(encoder)>445)
{
startMotor(port2, -127);
untilEncoderCounts(440,encoder);
stopMotor(port2);
}
}
if(SensorValue(Bump3)==1)
{
if(SensorValue(encoder)<=850)
{
startMotor(port2, 127);
untilEncoderCounts(850,encoder);
stopMotor(port2);
}
}
}
}