Robot won't respond to controller

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    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    11, 12, 19, 20  
// uptake2              motor         2               
// Motor10              motor         10              
// Motor1               motor         1               
// Motor9               motor         9               
// Controller1          controller                    
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"
#include "robot-config.h"

using namespace vex;

// A global instance of competition
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 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.
  // ..........................................................................
}

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              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 (true) {
    // define variables
    bool r1pressing = Controller1.ButtonR1.pressing();
    bool l1pressing = Controller1.ButtonL1.pressing();
    bool r2pressing = Controller1.ButtonR2.pressing();
    bool l2pressing = Controller1.ButtonL2.pressing();
    bool axis4 = Controller1.Axis4.position();
    bool axis3 = Controller1.Axis3.position();
    bool turning = Controller1.Axis1.position() + Controller1.Axis2.position();



  //turning
  if (turning) {
    rightMotorA.setVelocity(100, percent);
    leftMotorA.setVelocity(-100, percent);
    rightMotorB.setVelocity(100, percent);
    leftMotorB.setVelocity(-100, percent);
  }
   //Foward
  if (axis3) {
    rightMotorA.setVelocity(100, percent);
    leftMotorA.setVelocity(100, percent);
    rightMotorB.setVelocity(100, percent);
    leftMotorB.setVelocity(100, percent);
  }

    // strafe
    if (axis4) {
      rightMotorA.setVelocity(100, percent);
      leftMotorA.setVelocity(-100, percent);
      leftMotorB.setVelocity(100, percent);
      rightMotorA.setVelocity(-100, percent);
    }

    // if r1 is pressing everything will spin at full speed
    if (r1pressing) {
      intake1.setVelocity(-100, percent);
      intake2.setVelocity(-100, percent);
      uptake1.setVelocity(00, percent);
      uptake2.setVelocity(00, percent);
    }
    // if l1 is pressing only uptakes will spin at full speed
    if (l1pressing) {
      intake1.setVelocity(0, percent);
      intake2.setVelocity(0, percent);
      uptake1.setVelocity(100, percent);
      uptake2.setVelocity(70, percent);

    }
    // if both l1 and r1 are being pressed then both functions will activate
    if (l1pressing && r1pressing) {
      intake1.setVelocity(-100, percent);
      intake2.setVelocity(-100, percent);
      uptake1.setVelocity(100, percent);
      uptake2.setVelocity(70, percent);
    }

    if (r2pressing) {
    intake1.setVelocity(100, percent);
    intake2.setVelocity(100, percent);

    }
    if(l2pressing) {
    uptake1.setVelocity(-100, percent);
    uptake2.setVelocity(-70, percent);
    }

    if (l2pressing && r2pressing) {
    intake1.setVelocity(100, percent);
    intake2.setVelocity(100, percent);
    uptake1.setVelocity(-100, percent);
    uptake2.setVelocity(-70, percent);
    }

    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);
  }
}

this is my main.ccp

Hello! Welcome to the forums! Could you describe in detail exactly what happens to make it easier to troubleshoot? Does it disconnect? Does it just not respond to button presses? Etc.

yes, I the robot wont respong to button clicks at all.

It could be due to you having the position of the joysticks be a boolean. You should store it as an integer and then have deadband values instead. So, it should look like:

int axis4 = Controller1.Axis4.position();
if( axis4 >= 5){
//stuff
}

setVelocity does not necessarily control the motors.
If a previous spin command has been sent, it will change the current velocity.
If a spin has not been sent, it controls the velocity for the next spin command.

I prefer to not use it at all, I would replace them all with (for example)

rightMotorA.spin(forward, 100,  percent);

You can read about the motor API here.
https://api.vexcode.cloud/v5/html/classvex_1_1motor.html

The description for setVelocity says this.

Sets the velocity of the motor based on the parameters set in the command. This command will not run the motor. Any subsequent call that does not contain a specified motor velocity will use this value.

5 Likes