Kahl
January 2, 2017, 3:18pm
1
Hello I am trying to program my robot but I am having troubles doing so. My claw works great, but my lift is all messed up. The left side of the lift will not work. Then the right side stalls and works half the time. Any advise is awesome, thank you. The program is below.
task main()
{
while(true)
if(vexRT[Btn5U] == 1)
{
motor[rightclaw] = -127;
}
else if (vexRT[Btn5D] == 1)
{
motor[rightclaw] = 127;
}
else
{
motor[rightclaw] = 0;
if(vexRT[Btn5U] == 1)
{
motor[leftclaw] = -127;
}
else if (vexRT[Btn5D] == 1)
{
motor[leftclaw] = 127;
}
else
{
motor[leftclaw] = 0;
if(vexRT[Btn6U] == 1)
{
motor[middleliftleft] = -127;
}
else if (vexRT[Btn6D] == 1)
{
motor[middleliftleft] = 127;
}
else
{
motor[middleliftleft] = 0;
if(vexRT[Btn6U] == 1)
{
motor[middleliftright] = -127;
}
else if (vexRT[Btn6D] == 1)
{
motor[middleliftright] = 127;
}
else
{
motor[middleliftright] = 0;
if(vexRT[Btn6U] == 1)
{
motor[toprightlift] = -127;
}
else if (vexRT[Btn6D] == 1)
{
motor[toprightlift] = 127;
}
else
{
motor[toprightlift] = 0;
if(vexRT[Btn6U] == 1)
{
motor[topleftlift] = -127;
}
else if (vexRT[Btn6D] == 1)
{
motor[topleftlift] = 127;
}
else
{
motor[topleftlift] = 0;
}
}
}
}
}
}
}
Edit: @jpearman I formatted your code and placed in “code” tags (so the formatting is kept). Perhaps you can see some of the issues now.
Don’t just put closing brackets when your code doesn’t compile correctly. You are missing an open brace at the while loop. Also, at the end of each block of if statements for your buttons you are missing closing curly braces. When looking at code, unless you are doing nested if statements or something like that you shouldn’t have to close all your brackets at the end of your code.
This is what I was referring to:
if(vexRT[Btn6U] == 1)
{
motor[toprightlift] = -127;
}
else if (vexRT[Btn6D] == 1)
{
motor[toprightlift] = 127;
}
else
{
motor[toprightlift] = 0;
}//Forgot this
Now, if I was completely wrong, then you are probably asking too much from the lift. Add more elastics or increase the gear ratio.
Kahl
January 2, 2017, 3:47pm
3
The lift was working just fine but then I put another motor on the lift. Then I tried to re- program it started doing all of this weird stuff.
So you have two issues with the code that are causing the majority of your problems.
As @NightsRosario pointed out, your initial while statement does not use braces to keep all the following statements running.
On every if-then-else statement, the final else only has an opening brace, your next statement is part of the else condition.
A simple reformat with correct brace placement would look like this.
task main()
{
while(true) {
if(vexRT[Btn5U] == 1)
{
motor[rightclaw] = -127;
}
else if (vexRT[Btn5D] == 1)
{
motor[rightclaw] = 127;
}
else
{
motor[rightclaw] = 0;
}
if(vexRT[Btn5U] == 1)
{
motor[leftclaw] = -127;
}
else if (vexRT[Btn5D] == 1)
{
motor[leftclaw] = 127;
}
else
{
motor[leftclaw] = 0;
}
if(vexRT[Btn6U] == 1)
{
motor[middleliftleft] = -127;
}
else if (vexRT[Btn6D] == 1)
{
motor[middleliftleft] = 127;
}
else
{
motor[middleliftleft] = 0;
}
if(vexRT[Btn6U] == 1)
{
motor[middleliftright] = -127;
}
else if (vexRT[Btn6D] == 1)
{
motor[middleliftright] = 127;
}
else
{
motor[middleliftright] = 0;
}
if(vexRT[Btn6U] == 1)
{
motor[toprightlift] = -127;
}
else if (vexRT[Btn6D] == 1)
{
motor[toprightlift] = 127;
}
else
{
motor[toprightlift] = 0;
}
if(vexRT[Btn6U] == 1)
{
motor[topleftlift] = -127;
}
else if (vexRT[Btn6D] == 1)
{
motor[topleftlift] = 127;
}
else
{
motor[topleftlift] = 0;
}
wait1Msec(20);
} // end of while
}
however, there is a lot of duplication in the testing for joystick values and the code can be significantly simplified to this.
task main()
{
while(true) {
// claw control
if(vexRT[Btn5U] == 1)
{
motor[rightclaw] = -127;
motor[leftclaw] = -127;
}
else if (vexRT[Btn5D] == 1)
{
motor[rightclaw] = 127;
motor[leftclaw] = 127;
}
else
{
motor[rightclaw] = 0;
motor[leftclaw] = 0;
}
// lift control
if(vexRT[Btn6U] == 1)
{
motor[middleliftleft] = -127;
motor[middleliftright] = -127;
motor[toprightlift] = -127;
motor[topleftlift] = -127;
}
else if (vexRT[Btn6D] == 1)
{
motor[middleliftleft] = 127;
motor[middleliftright] = 127;
motor[toprightlift] = 127;
motor[topleftlift] = 127;
}
else
{
motor[middleliftleft] = 0;
motor[middleliftright] = 0;
motor[toprightlift] = 0;
motor[topleftlift] = 0;
}
wait1Msec(20);
} // end of while
}
Kahl
January 2, 2017, 5:39pm
5
Ok I did some testing and port 6 and 7 is not working any suggestions for that.
It might be the wire extenders that are not working. Try switching them with the wire extenders from different ports.
Yay, I was right. Also, the reason your ports are not working is likely your cables. It has happened to us sometimes. Switch your extension cables out for other ones. If that doesn’t work, then those ports are likely dead and you need a new Cortex.
NightsRosario:
Yay, I was right.
It would almost work the way it was written, because of the nested if-then-else statements the “while” only had one following statement, the first “if”, however, as soon as the rest of the code was refactored it would not run.