Hello,
so I’ve been having problems with the code running on the robot for a second or so, and then just stopping (until you turn it off and then back on again), so i was wondering if its an issue with the code or with the actual motors on the robot itself. Below is a copy of my code, as well as a screenshot from the code within robot c. There wasn’t any error in compiling so it might be the format messing up?? I’m not sure, I’m a new coder so please be easy on me.
/////////////////////////
task main()
{
while(1 == 1)
{
//Right side of the robot is controlled by the right joystick, Y-axis
motor[rightdrive] = vexRT[Ch2];
//Left side of the robot is controlled by the left joystick, Y-axis
motor[leftdrive] = vexRT[Ch3];
//moving the arm up (all together)
if(vexRT[Btn6U] == 1)
//moving the arm up (all together)
{
motor[leftliftoutup] = 127;
motor[leftliftoutdown] = 127;
motor[leftliftinup] = -127; //move up
motor[leftliftindown] = -127;
motor[rightliftoutup] = -127;
motor[rightliftoutdown] = -127;
motor[rightliftinup] = 127;
motor[rightliftindown] = 127;
}
else
if(vexRT[Btn6D] == 1)
//moving the arm down (all together)
{
motor[leftliftoutup] = -127;
motor[leftliftoutdown] = -127;
motor[leftliftinup] = 127; //move down
motor[leftliftindown] = 127;
motor[rightliftoutup] = 127;
motor[rightliftoutdown] = 127;
motor[rightliftinup] = -127;
motor[rightliftindown] = -127;
}
}
}
//end of task main
////////////////////////////////////////
Assuming that all the motors and wires are configured correctly all you have to do is add a
wait1msec(nNumberofMiliseconds);
These commands are as simple as what they read. Just replace nNumberofMiliseconds with 20. Add this right before the end of the while loop so the cortex has enough time to process all the information before cycling through the while loop. Wait commands are required in ALL while loops so it has enough time to do the calculations. If you don’t add a wait command, then the program will likely crash which is what your are experiencing.
The caps lock comments are the ones that I added. Usually its good to comment each curly brace so you know what command they belong to. That’s not absolutely necessary, but it improves the code’s organization.
Can you check the connections with your CORTEX and your battery to make sure nothing is loose? Also, by adding a 9V may potentially help. Did you also check the amount of friction on the lift? Is it not too shabby?
The code legitimately seems perfectly fine, other than telling the motors to stop when nothing is pressed. I am thinking it’s more of a hardware and not software issue.
looking at the various awesome robotC debuggers also may help. There’s one telling you the tasks running and another telling the values sent to motors that could be quite helpful.