We use the CS2n.org Curriculum for my class. The kids are doing a final delivery challenge. I have two groups where they have code that has no errors, but it just simply stops executing life halfway through. I have never had this happen before, but it is happening to two groups and not in the same place in their code. I though maybe it was the file itself so I had them create a new file, but that didn’t fix it. Any help would be appreciated.
Welcome to the forum.
Would you be able to supply the code and/or any extra information? There’s little we can do with only knowing that the code stops executing halfway through.
Without the code itself it will be hard to diagnose it completely but there are a few common things that can be tricky with vex:
-
Some commands will prevent the following code from executing if they aren’t completed. An example of this would be a robot arm that cannot go higher than 200 degrees with a spinFor(250, degrees) command passed.
-
Occasionally the program will build fine but will run into a runtime error when the program itself executes. To diagnose this you should check the robot brain for any red error messages that appear as the program itself runs
-
If there is some command that utilizes a while loop then the logic of the program itself may be creating an infinite loop. While this is often caught by the compiler and would spit out a warning there are some edge cases where it isn’t apparent until the code runs.
Again, feel free to post the code itself for more specialized support, otherwise what I mention should cover 90% of cases you’ll encounter.
Here is the code. It does not have any errors when you load it. It also does not give any errors on the robot screen, but it stops executing the code when it is supposed to reverse(about halfway through). Thanks for the help.
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();{
armMotor.spinToPosition(100, degrees);
clawMotor.setMaxTorque(35, percent);
clawMotor.spinToPosition(-180, degrees);
armMotor.spinToPosition(300, degrees);
Drivetrain.driveFor(forward, 1500, mm);
Drivetrain.turnFor(left, 79, degrees);
Drivetrain.driveFor(forward, 400, mm);
armMotor.spinToPosition(100, degrees);
clawMotor.setMaxTorque(30, percent);
clawMotor.spinToPosition(180,degrees);
Drivetrain.driveFor(reverse, 400, mm);
Drivetrain.turnFor(right, 90, degrees);
Drivetrain.driveFor(1500, mm);
armMotor.spinToPosition(100, degrees);
clawMotor.setMaxTorque(30, percent);
clawMotor.spinToPosition(-180, degrees);
armMotor.spinToPosition(300, degrees);
Drivetrain.turnFor(right, 200, degrees);}
}
So we accidentally just discovered something. at the point in the program(I have another group also dealing with this) that it stops working, if you unplug the claw motor, the program will continue. So my new question is why is that the case? The positioning of the claw closes at the exact same degree it opened earlier so it should not prevent anything I would think. Yet…it does.
My guess?
The claw motor can’t actually make it to the position of 180 degrees (the command directly before the reverse command). It will continuously attempt to spin until it reaches 180 degrees, and never get there, and so never move on.
The fix would be to repeatedly test different values there until you find the right value for the command that makes it move to the position you physically want but also programmatically completes and moves on.
I would reccomend that you configure the velocities before running the motors, for more control over motion and better predictability.