Hello to who reads this.
I am a student currently working on a project that requires me to make an elevator.
In the process of creating the elevator, I have ran into some code problems.
Below is the code that I have been working on, and I have not been able to get any motor to run whatsoever.
Before I show the code, this is how it should function.
- I press a button.
- The code runs through yValue, which gives the future floor value.
- Code calculates difference between future floor and current floor (y - x)
- Moves the desired distance
- x, the current floor value, now equals y
- Repeat the process
#pragma config(Sensor, in1, door, sensorPotentiometer)
#pragma config(Sensor, dgtl5, Floorone, sensorTouch)
#pragma config(Sensor, dgtl6, Floortwo, sensorTouch)
#pragma config(Sensor, dgtl7, Floorthree, sensorTouch)
#pragma config(Sensor, dgtl8, Encoder, sensorQuadEncoder)
#pragma config(Motor, port2, Cable, tmotorVex269_MC29, openLoop)
#pragma config(Motor, port3, door, tmotorVex269_MC29, openLoop)
void halt()
{
motor[Cable] = 0;
}
int yValue(int prevY) //The y value is the value of the future floor
{
int y;
if(SensorValue[Floorone] == 1)
{y = 1;}
else if(SensorValue[Floortwo] == 1)
{y = 2;}
else if(SensorValue[Floorthree] == 1)
{y = 3;}
return y;
}
/void move(int diff)
{
if(diff < 0)
{
while(SensorValue[Encoder] > 500 * diff)
{
motor[Cable] = -63;
}
}
else if(diff > 0)
{
while(SensorValue[Encoder] < 500 * diff)
{
motor[Cable] = 63;
}
}
halt();
}/
void moveTime(int i)
{
writeDebugStreamLine("int i is:%i ", i);
if(i < 0 && i >= -2)
{
motor[cable] = 63;
wait(1000);
}
if(i > 0 && i <= 2)
{
motor[cable] = -63;
wait(1000);
}
halt();
wait(1000);
}
task main()
{
int x = 1;
int y = 1;
SensorValue[Encoder] = 0;
while(true)
{
//waitUntil(SensorValue[Floorone] == 1 || SensorValue[Floortwo] == 1 || SensorValue[Floorthree] == 1);
for(int i = 0; i < 4; i++)
{
y = yValue(y);
writeDebugStreamLine(“int y and x is:%i “, y ,”,”, x);
int diff = y - x;
moveTime(diff);
halt();
x = y;
}
halt();
}
}
Note: I have two functions, move and moveTime. move uses the encoder and moveTime uses time to function. I don’t mind a fix for either one, however I would like a solution to not require any other sensors as we are short on resources and time to implement them. Thank you again.