Competition Coding Issue

Can anyone offer suggestions? This is a code my team did - When we tried it in just normal template, it ran all 4 motors. When we put it in the competition template, nothing happened - at all. Then, when we copied it into block and the competition template, it only runs the first claw code and then just stops. Pasting the code below - would really appreciate a good set of eyes and help. Thanks!

void autonomous(void)
{clawMotor.spinToPosition(.25,turns);
Drivetrain.setDriveVelocity(50, percent);
Drivetrain.driveFor(5,inches);
clawMotor.spinToPosition(.25,turns);
armMotor.spinToPosition(2,turns);
Drivetrain.turnFor(left,90,degrees);
Drivetrain.driveFor(25,inches);
Drivetrain.setTurnVelocity(50, percent);
Drivetrain.turnFor(left,45, degrees);
armMotor.spinToPosition(0,turns);
clawMotor.spinToPosition(.25,turns);
armMotor.spinToPosition(2,turns);
Drivetrain.turn(right);
Drivetrain.drive(reverse);
Drivetrain.driveFor(5,inches);
armMotor.spinToPosition(.25,turns);
Drivetrain.turnFor(right,90,degrees);
armMotor.spinToPosition(1,turns);
clawMotor.spinToPosition(0,turns);
Drivetrain.drive(forward);
Drivetrain.driveFor(47,inches);
armMotor.spinToPosition(0,degrees);
Drivetrain.turnFor(right,45,degrees);
Drivetrain.driveFor(2,inches);
clawMotor.spinToPosition(.25,turns);
Drivetrain.driveFor(reverse,2,inches);
// …
// Insert autonomous user code here.
// …
}

1 Like

Can you be so kind to post your full program code enclosed in the [code]...[/code] tags?

It is not possible to answer your question with non easy to read unformatted fragment of your program.

When nothing happens, you may have forgotten to declare vex::competition variable and set which functions are called for user and autonomous modes.

https://help.vexcodingstudio.com/#cpp/namespacevex/classvex_1_1competition/autonomous

1 Like

Are you using a competition switch? You can’t test your autonomous in the competition template without it

2 Likes

You can test your competition template auto code without a competition switch. Although having a physical competition switch is easier.

IIRC when you select your program instead of hitting run, you want to hit the competition option. This will bring up another 3 options which let you simulate a competition (15 sec auto and then teleop, teleop only, and auto only).

2 Likes

If none of the reasons are true from above, I would suggest putting a clawMotor.stop(brakeType::brake); In between each of your motor commands. Similar thing was happening to me.

1 Like

I agree, try this:

void autonomous(void) {

clawMotor.spinToPosition(.25,turns);

clawMotor.stop(brakeType::brake);

Drivetrain.setDriveVelocity(50, percent);

Drivetrain.driveFor(5,inches);

Drivetrain.stop(brakeType::brake);

clawMotor.spinToPosition(.25,turns);

clawMotor.stop(brakeType::brake);

armMotor.spinToPosition(2,turns);

armMotor.stop(brakeType::brake);

Drivetrain.turnFor(left,90,degrees);

Drivetrain.driveFor(25,inches);

Drivetrain.setTurnVelocity(50, percent);

Drivetrain.turnFor(left,45, degrees);

Drivetrain.stop(brakeType::brake);

armMotor.spinToPosition(0,turns);

armMotor.stop(brakeType::brake);

clawMotor.spinToPosition(.25,turns);

clawMotor.stop(brakeType::brake);

armMotor.spinToPosition(2,turns);

armMotor.stop(brakeType::brake);

Drivetrain.turn(right);

Drivetrain.drive(reverse);

Drivetrain.driveFor(5,inches);

Drivetrain.stop(brakeType::brake);

armMotor.spinToPosition(.25,turns);

armMotor.stop(brakeType::brake);

Drivetrain.turnFor(right,90,degrees);

Drivetrain.stop(brakeType::brake);

armMotor.spinToPosition(1,turns);

armMotor.stop(brakeType::brake);

clawMotor.spinToPosition(0,turns);

clawMotor.stop(brakeType::brake);

Drivetrain.drive(forward);

Drivetrain.driveFor(47,inches);

Drivetrain.stop(brakeType::brake);

armMotor.spinToPosition(0,degrees);

armMotor.stop(brakeType::brake);

Drivetrain.turnFor(right,45,degrees);

Drivetrain.driveFor(2,inches);

Drivetrain.stop(brakeType::brake);

clawMotor.spinToPosition(.25,turns);

clawMotor.stop(brakeType::brake);

Drivetrain.driveFor(reverse,2,inches);

Drivetrain.stop(brakeType::brake);

// …

// Insert autonomous user code here.

// …

}

Yes, we were. Thanks, though.

Here is the entire code using the vex competition template.

/----------------------------------------------------------------------------/
/* /
/
Module: main.cpp /
/
Author: VEX /
/
Created: Thu Sep 26 2019 /
/
Description: Competition Template /
/
/
/
----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// Drivetrain drivetrain 10, 1
// clawMotor motor 3
// armMotor motor 8
// ---- END VEXCODE CONFIGURED DEVICES ----

#include “vex.h”

using namespace vex;

// A global instance of competition
competition Competition;

// define your global instances of motors and other devices here

/---------------------------------------------------------------------------/
/* Pre-Autonomous Functions /
/
/
/
You may want to perform some actions before the competition starts. /
/
Do them in the following function. You must return from this function /
/
or the autonomous and usercontrol tasks will not be started. This /
/
function is only called once after the V5 has been powered on and /
/
not every time that the robot is disabled. /
/
---------------------------------------------------------------------------*/

void pre_auton(void) {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();

// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, …
}

/---------------------------------------------------------------------------/
/* /
/
Autonomous Task /
/
/
/
This task is used to control your robot during the autonomous phase of /
/
a VEX Competition. /
/
/
/
You must modify the code to add your own robot specific commands here. /
/
---------------------------------------------------------------------------*/

void autonomous(void) {clawMotor.spinToPosition(.25,turns);
Drivetrain.setDriveVelocity(50, percent);
Drivetrain.driveFor(5,inches);
clawMotor.spinToPosition(.25,turns);
armMotor.spinToPosition(2,turns);
Drivetrain.turnFor(left,90,degrees);
Drivetrain.driveFor(25,inches);
Drivetrain.setTurnVelocity(50, percent);
Drivetrain.turnFor(left,45, degrees);
armMotor.spinToPosition(0,turns);
clawMotor.spinToPosition(.25,turns);
armMotor.spinToPosition(2,turns);
Drivetrain.turn(right);
Drivetrain.drive(reverse);
Drivetrain.driveFor(5,inches);
armMotor.spinToPosition(.25,turns);
Drivetrain.turnFor(right,90,degrees);
armMotor.spinToPosition(1,turns);
clawMotor.spinToPosition(0,turns);
Drivetrain.drive(forward);
Drivetrain.driveFor(47,inches);
armMotor.spinToPosition(0,degrees);
Drivetrain.turnFor(right,45,degrees);
Drivetrain.driveFor(2,inches);
clawMotor.spinToPosition(.25,turns);
Drivetrain.driveFor(reverse,2,inches);
// …
// Insert autonomous user code here.
// …
}

/---------------------------------------------------------------------------/
/* /
/
User Control Task /
/
/
/
This task is used to control your robot during the user control phase of /
/
a VEX Competition. /
/
/
/
You must modify the code to add your own robot specific commands here. /
/
---------------------------------------------------------------------------*/

void usercontrol(void) {
// User control code here, inside the loop
while (1) {
// This is the main execution loop for the user control program.
// Each time through the loop your program should update motor + servo
// values based on feedback from the joysticks.

// ........................................................................
// Insert user code here. This is where you use the joystick values to
// update your motors, etc.
// ........................................................................

wait(20, msec); // Sleep the task for a short amount of time to
                // prevent wasted resources.

}
}

//
// Main will set up the competition functions and callbacks.
//
int main() {
// Set up callbacks for autonomous and driver control periods.
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);

// Run the pre-autonomous function.
pre_auton();

// Prevent main from exiting with an infinite loop.
while (true) {
wait(100, msec);
}
}

Thank you. We were using a switch, but nothing happened.

Giving that a try. Thanks

@Terri_Simpson, could you be so kind and put your program code in the [code]...[/code] tags next time?
It makes it not easy to understand the unformatted structure of your code.

Your main function seems fine in setting up competition template.

By the way you describing it the next possible issue could be the way you call clawMotor.spinToPosition(.25,turns); function.

According to online reference VEX Help
bool spinToPosition (double rotation, rotationUnits units, bool waitForCompletion=true)
function takes three arguments, where the third waitForCompletion argument defaults to true if you didn’t set it to false.

If your claw motor couldn’t complete .25 turns that function will never return and the next statement will never run.

Try passing false as the last argument to clawMotor.spinToPosition(.25,turns,false);

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.