Hello, my autonomous doesn’t start when i put switch to the competition template can you guys help?
What coding platform are you using, to start?
what do you mean, wel I’m using c++
Are you using VexCode, VCS, Robotmesh Studio, etc.
I am using Vexcode…
Post your code so people can see what’s the problem.
Also are you using a competition switch/match play to start auton
#include “vex.h”
using namespace vex;
#include “robot-config.h”
// A global instance of competition
competition Competition;
// define your global instances of motors and other devices here
vex::motor ClawMotor = vex::motor(vex::PORT16);
vex::motor LeftMotor = vex::motor(vex::PORT18);
vex::motor RightMotor = vex::motor(vex::PORT1);
vex::motor Motor1 = vex::motor(vex::PORT10, true);
vex::motor Motor2 = vex::motor(vex::PORT15, true);
vex::controller Controller1 = vex::controller();
/---------------------------------------------------------------------------/
/* 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){
// Insert autonomous user code here.
LeftMotor.setVelocity(50, vex::velocityUnits::pct);
RightMotor.setVelocity(50, vex::velocityUnits::pct);
LeftMotor.rotateFor(1.2, vex::rotationUnits::rev,false);
RightMotor.rotateFor(-1.2, vex::rotationUnits::rev);
LeftMotor.rotateFor(-0.5, vex::rotationUnits::rev,false);
RightMotor.rotateFor(0.5, vex::rotationUnits::rev);
}
/---------------------------------------------------------------------------/
/* /
/ 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) {
while (true) {
if (Controller1.ButtonR1.pressing()){
LeftMotor.spin (directionType::fwd,(Controller1.Axis1.value() + Controller1.Axis2.value())/10, velocityUnits::pct);
RightMotor.spin(directionType::fwd,(Controller1.Axis1.value() - Controller1.Axis2.value())/10, velocityUnits::pct);
}
//following codes: speed setting two
else if (Controller1.ButtonR2.pressing()){
LeftMotor.spin(directionType::fwd, (Controller1.Axis1.value() + Controller1.Axis2.value())/1, velocityUnits::pct);
RightMotor.spin(directionType::fwd,(Controller1.Axis1.value() - Controller1.Axis2.value())/1, velocityUnits::pct);
}
//following codes: speed setting three
else{
LeftMotor.spin (directionType::fwd, (Controller1.Axis1.value() + Controller1.Axis2.value())/2.5, velocityUnits::pct);
RightMotor.spin(directionType::fwd, (Controller1.Axis1.value() - Controller1.Axis2.value())/2.5, velocityUnits::pct);
}
Motor1.spin (directionType::fwd, (Controller1.Axis4.value() - Controller1.Axis3.value())/1, velocityUnits::pct);
Motor2.spin (directionType::fwd, (Controller1.Axis4.value() + Controller1.Axis3.value())/1, velocityUnits::pct);
//following codes control clawmotor motion
if (Controller1.ButtonL1.pressing()){
ClawMotor.spin(directionType::fwd, 50, velocityUnits::pct);
}
else if(Controller1.ButtonL2.pressing()){
ClawMotor.spin(directionType::rev, 50, velocityUnits::pct);
}
else{
ClawMotor.stop(brakeType::hold);
}
}
// 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.
It’s just the autonomous part
wait what do you mean switch/match?
cuz i am using a competition template
When you aren’t hooked up to a competition switch the code defaults to usercontrol. If you want to test your autonomous try copying it into a regular project (not competition)
Thank You
…
Just making sure but u have the int main() part in your code right?
In future, please wrap your code in [code]...[/code]
tags or triple backticks (```) to get it nicely formatted when posting it on the forum.
If the code you posted above is your complete program, I noticed a couple of things wrong with it, some of which should cause the program not to compile. If indeed your code won’t compile, it would be helpful to see the entire contents of the “output” tab in VEXcode that appear when you try to compile the code.
First, the function usercontrol
is missing a closing brace.
Second, you probably want the call to wait
in usercontrol
inside the infinite loop, that way it runs every time through the loop. In its current position it will never execute since it’s placed after an infinite loop.
Third, and most critically, every c++ program must have a function called main
, which is the first thing to execute when the program starts. All other user code that runs during program execution is called from main
in some way. In the particular case of setting up the autonomous/driver control modes in VEX c++, main
needs to contain a couple of function calls to tell your code what part of the program to run when it enters autonomous mode or driver control mode. In your case, the main
that comes with the competition template should work unmodified:
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);
}
}
you should also be able to do this from the controller i believe you load your program up and it is either a match button or a tournament button but in there there should be an option to run auton
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.