[Vex C++]: Competition Template is not working

  1. 2 months ago

    MTO967

    Oct 10 Arkansas 967A

    I have been trying to create some competition code using the template, but it will not function consistently. Basically, the code will run correctly about a quarter of the time. The code is below.
    Thanks for any help.

    #include "robot-config.h"
    /*---------------------------------------------------------------------------*/
    /*                                                                           */
    /*        Description: Competition template for VCS VEX V5                   */
    /*                                                                           */
    /*---------------------------------------------------------------------------*/
    
    //Creates a competition object that allows access to Competition methods.
    vex::competition    Competition;
    
    /*---------------------------------------------------------------------------*/
    /*                          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 cortex has been powered on and    */
    /*  not every time that the robot is disabled.                               */
    /*---------------------------------------------------------------------------*/
    
    void pre_auton( void ) {
      // 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.
      // ..........................................................................
    
        LeftDriveFront.rotateFor(3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
        LeftDriveMiddle.rotateFor(3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
        LeftDriveBack.rotateFor(3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
        RightDriveFront.rotateFor(3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
        RightDriveMiddle.rotateFor(3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
        RightDriveBack.rotateFor(3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
        while (LeftDriveFront.isSpinning() || LeftDriveMiddle.isSpinning() || LeftDriveBack.isSpinning())
        {
        }
        LeftDriveFront.rotateFor(-3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
        LeftDriveMiddle.rotateFor(-3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
        LeftDriveBack.rotateFor(-3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
        RightDriveFront.rotateFor(-3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
        RightDriveMiddle.rotateFor(-3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
        RightDriveBack.rotateFor(-3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
        Flywheel.spin(directionType::fwd,200,velocityUnits::rpm);
        while (LeftDriveFront.isSpinning() || LeftDriveMiddle.isSpinning() || LeftDriveBack.isSpinning())  
        {
        }
        Ball.spin(directionType::fwd,200,velocityUnits::rpm);
        vex::task::sleep(2000);
        
        
    }
    
    /*----------------------------------------------------------------------------*/
    /*                                                                            */
    /*                              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 ) {
     #include "robot-config.h"
        while (1==1)
        {
           LeftDriveFront.spin(directionType::fwd, Controller1.Axis3.value(),velocityUnits::pct);
           LeftDriveMiddle.spin(directionType::fwd, Controller1.Axis3.value(),velocityUnits::pct);
           LeftDriveBack.spin(directionType::fwd, Controller1.Axis3.value(),velocityUnits::pct);
           RightDriveFront.spin(directionType::fwd, Controller1.Axis2.value(),velocityUnits::pct);
           RightDriveFront.spin(directionType::fwd, Controller1.Axis2.value(),velocityUnits::pct);
           RightDriveBack.spin(directionType::fwd, Controller1.Axis2.value(),velocityUnits::pct);
                
            if (Controller1.ButtonL1.pressing()==1){
                Flywheel.spin(directionType::rev,200,velocityUnits::rpm);
            }
            else{
               Flywheel.stop(brakeType::coast);
            }
            if (Controller1.ButtonR1.pressing()==1) {
                Ball.spin(directionType::fwd,200,velocityUnits::rpm);
            }
            else{
               if (Controller1.ButtonR2.pressing()==1){
                  Ball.spin(directionType::rev,200,velocityUnits::rpm);
               }
                else{
                     Ball.stop(brakeType::brake);
                }
            }
               
        vex::task::sleep(20);
        }
    }
    
    
    //
    // Main will set up the competition functions and callbacks.
    //
    int main() { 
        //Run the pre-autonomous function. 
        pre_auton();    
        //Set up callbacks for autonomous and driver control periods.
        Competition.autonomous( autonomous );
        Competition.drivercontrol( usercontrol );
    
        //Prevent main from exiting with an infinite loop.                        
        while(1) {
          vex::task::sleep(100);//Sleep the task for a short amount of time to prevent wasted resources.
        }    
       }

    @MTO967 @jpearman
    By not functioning correctly, I mean that both the user control and autonomous sections will not consistently execute. About 1/4 times, the user control will allow the driver to control the base motors with the two joysticks. The other 3/4 times, the robot will do nothing when the play button is pressed, more specifically, when the play button is pressed and the competition switch is set to user control, the brain screen will go black with the blue line at the top like normal, but none of the motors will react to the changing of the joysticks or buttons.
    The same thing is happening with autonomous, when the play button is pressed and then the competition switch is set to autonomous, the screen goes to black with the blue stripe like normal, but the autonomous programming will not executive about 3/4 times, which is a rough estimate.
    I have also tried activating it using the control and going to the skills option, but that does not solve the problem either.
    The reason why I believe this is specifically a competition template problem is because the user control code will work perfectly fine in a regular file.

    ok, try starting with the competition switch set to disable and then move to enable after running the program. I think you have run into a known bug (ie. starting competition code with robot enabled) that will be fixed in the 1.0.2 vexos release (which is due out very soon)

  2. jpearman

    Oct 10 Moderator, ROBOTC Tech Support, V5 Beta Moderator Los Angeles 8888

    @MTO967 I have been trying to create some competition code using the template, but it will not function consistently. Basically, the code will run correctly about a quarter of the time. The code is below.

    What do you mean by not functioning correctly ? Are you using a competition switch ?
    (also, remove the extra #include "robot-config.h" you have in usercontrol, that's not necessary)

  3. MTO967

    Oct 10 Arkansas 967A
    Edited 2 months ago by MTO967

    @jpearman
    By not functioning correctly, I mean that both the user control and autonomous sections will not consistently execute. About 1/4 times, the user control will allow the driver to control the base motors with the two joysticks. The other 3/4 times, the robot will do nothing when the play button is pressed, more specifically, when the play button is pressed and the competition switch is set to user control, the brain screen will go black with the blue line at the top like normal, but none of the motors will react to the changing of the joysticks or buttons.
    The same thing is happening with autonomous, when the play button is pressed and then the competition switch is set to autonomous, the screen goes to black with the blue stripe like normal, but the autonomous programming will not executive about 3/4 times, which is a rough estimate.
    I have also tried activating it using the control and going to the skills option, but that does not solve the problem either.
    The reason why I believe this is specifically a competition template problem is because the user control code will work perfectly fine in a regular file.

  4. Hikaru Hitachiin

    Oct 10 Illinois 209F

    Then I see your issue, there are so many parts to your specific repetition that the robot won't take it in or you aren't waiting long enough.

  5. jpearman

    Oct 10 Moderator, ROBOTC Tech Support, V5 Beta Moderator Answer Los Angeles 8888

    @MTO967 @jpearman
    By not functioning correctly, I mean that both the user control and autonomous sections will not consistently execute. About 1/4 times, the user control will allow the driver to control the base motors with the two joysticks. The other 3/4 times, the robot will do nothing when the play button is pressed, more specifically, when the play button is pressed and the competition switch is set to user control, the brain screen will go black with the blue line at the top like normal, but none of the motors will react to the changing of the joysticks or buttons.
    The same thing is happening with autonomous, when the play button is pressed and then the competition switch is set to autonomous, the screen goes to black with the blue stripe like normal, but the autonomous programming will not executive about 3/4 times, which is a rough estimate.
    I have also tried activating it using the control and going to the skills option, but that does not solve the problem either.
    The reason why I believe this is specifically a competition template problem is because the user control code will work perfectly fine in a regular file.

    ok, try starting with the competition switch set to disable and then move to enable after running the program. I think you have run into a known bug (ie. starting competition code with robot enabled) that will be fixed in the 1.0.2 vexos release (which is due out very soon)

  6. 7 weeks ago

    I could use a little help in fixing these two errors

  7. jpearman

    Oct 18 Moderator, ROBOTC Tech Support, V5 Beta Moderator Los Angeles 8888

    @Mr.MoNkEy I could use a little help in fixing these two errors

    Which errors ?

 

or Sign Up to reply!