My students tried three variations on the elevator project (sonar, line follower, and quad encoder). None of my six groups could get their elevator to work correctly (push button sends the elevator to the appropriate floor). The sonar was set in cm and the debugger displayed the correct values, but we could not get it to go to each floor. We were using RobotC 4.5, we downloaded the firmware and master CPU files before downloading the code, and a fresh battery was used often.
Below is our code, could anyone give me pointers on how to get this working. The compiler didn’t find any coding errors and I couldn’t find any hardware problems using the motor and senor debugger.
#pragma config(Sensor, dgtl3, LimitSwitch1, sensorTouch)
#pragma config(Sensor, dgtl4, LimitSwitch2, sensorTouch)
#pragma config(Sensor, dgtl5, LimitSwitch3, sensorTouch)
#pragma config(Sensor, dgtl6, Sonar, sensorSONAR_inch)
#pragma config(Motor, port2, MainMotor, tmotorVex393_MC29, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//
task main()
{
while(1==1)
if(SensorValue(LimitSwitch1)==1) //* push limit switch 1 to make the elevator go to the first floor*//
{
if(SensorValue(Sonar)==1)
{stopMotor(MainMotor);}
if(SensorValue(Sonar) >1)
{startMotor(MainMotor,60);
untilSonarLessThan(1.1,Sonar);
stopMotor(MainMotor);}
}
if(SensorValue(LimitSwitch2)==1) //* Push limit switch 2 to make the elevator go to floor 2, regardless of where it was before.*//
{
if(SensorValue(Sonar)==4)
{stopMotor(MainMotor);}
if(SensorValue(Sonar) >4)
{startMotor(MainMotor,60);
untilSonarLessThan(4.1,Sonar);
stopMotor(MainMotor);}
if(SensorValue(Sonar) <4)
{startMotor(MainMotor,-60);
untilSonarGreaterThan(3.9,Sonar);
stopMotor(MainMotor);}
}
if(SensorValue(LimitSwitch3)==1) //* Push limit switch 3 to make the elevator go to floor 3.*//
{
if(SensorValue(Sonar) <6.9)
{startMotor(MainMotor,-60);
untilSonarGreaterThan(6.9,Sonar);
stopMotor(MainMotor);}
else(SensorValue(Sonar)==7);
{stopMotor(MainMotor);}
}
}