VRC Code Help

Hello!

We have our motors connected to our robot by selecting motor groups and assigning buttons on the controller for each group (all in the top right corner of the screen). We are in the block code mode but we don’t have any code there right now so I don’t think that should make a difference.

For some reason all of our motors are moving really slow (like 25% the speed I remember them going last year). A couple days ago there was some kind of glitch I guess because for a few seconds the motors actually went full speed so I know the motors are capable of it (I also switched out motors in case they were burned out but it made no difference).

Can someone please offer a suggestion of what to try? Thanks!

I would suggest coding the robot using blocks instead of using the controller to select them. Vexcode has good example projects for this scenario. I would check out the tank drive control example. (You could do one of the arcade controls based off preference as well)

I believe the issue is that motors start at %50 speed when you start the program for some reason.

In block code when the program is started set the drive train and all the motor group’s velocities to %100.

This should improve the speed but another reason could be that you have a different gearbox in the motors than last year.

Hopefully, this should fix the issue but I haven’t done Vexcode for a while so if this isn’t the problem I’m going to tap out and let someone with more experience help.

Hope this helps. :slight_smile:

The default motor velocity is 50 rpm if all you use is m.spin(forward); etc. The reason is that for first time users it was safer to have the robot (usually a V5 clawbot or similar) move more slowly and be controllable rather than have it run at full speed.

2 Likes

Makes sense.

Does this also affect the speed of motor groups and drive trains when bound to the controller without code?

Ok, lets look at an example, this is very easy to test.

I created the following graphical configuration

One motor, one motor_group and a two motor drivetrain.

Lets look at (some of) the code it generates.

motor and motor_group code
      // check the ButtonL1/ButtonL2 status to control MotorGroup1
      if (Controller1.ButtonL1.pressing()) {
        MotorGroup1.spin(forward);
        Controller1LeftShoulderControlMotorsStopped = false;
      } else if (Controller1.ButtonL2.pressing()) {
        MotorGroup1.spin(reverse);
        Controller1LeftShoulderControlMotorsStopped = false;
      } else if (!Controller1LeftShoulderControlMotorsStopped) {
        MotorGroup1.stop();
        // set the toggle so that we don't constantly tell the motor to stop when the buttons are released
        Controller1LeftShoulderControlMotorsStopped = true;
      }
      // check the ButtonR1/ButtonR2 status to control Motor3
      if (Controller1.ButtonR1.pressing()) {
        Motor3.spin(forward);
        Controller1RightShoulderControlMotorsStopped = false;
      } else if (Controller1.ButtonR2.pressing()) {
        Motor3.spin(reverse);
        Controller1RightShoulderControlMotorsStopped = false;
      } else if (!Controller1RightShoulderControlMotorsStopped) {
        Motor3.stop();
        // set the toggle so that we don't constantly tell the motor to stop when the buttons are released
        Controller1RightShoulderControlMotorsStopped = true;
      }

you can see the motor and motor_group code is only using Motor.spin(forward), Motor.spin(reverse) and Motor.stop(). This means that they will both use the default velocity for motors which, as I said, is 50 rpm. If these motors have green gears then they will be running at 25% of their maximum free speeds (ie. 25% of 200rpm).

You can change this by adding setVelocity commands at the beginning of the code. I was using a C++ project, so that could be (block would be essentially the same).

int main() {
    Motor3.setVelocity( 100, percent );
    MotorGroup1.setVelocity( 100, percent );
}

easy.

Now lets look at the drivetrain code, a bit more complicated (and really verbose and messy, that’s always a problem with auto generated code).

drivetrain control
  // calculate the drivetrain motor velocities from the controller joystick axies
  // left = Axis3 + Axis4
  // right = Axis3 - Axis4
  int drivetrainLeftSideSpeed = Controller1.Axis3.position() + Controller1.Axis4.position();
  int drivetrainRightSideSpeed = Controller1.Axis3.position() - Controller1.Axis4.position();
  
  // check if the values are inside of the deadband range
  if (abs(drivetrainLeftSideSpeed) < 5 && abs(drivetrainRightSideSpeed) < 5) {
    // check if the motors have already been stopped
    if (DrivetrainNeedsToBeStopped_Controller1) {
      // stop the drive motors
      LeftDriveSmart.stop();
      RightDriveSmart.stop();
      // tell the code that the motors have been stopped
      DrivetrainNeedsToBeStopped_Controller1 = false;
    }
  } else {
    // reset the toggle so that the deadband code knows to stop the motors next time the input is in the deadband range
    DrivetrainNeedsToBeStopped_Controller1 = true;
  }
  
  // only tell the left drive motor to spin if the values are not in the deadband range
  if (DrivetrainNeedsToBeStopped_Controller1) {
    LeftDriveSmart.setVelocity(drivetrainLeftSideSpeed, percent);
    LeftDriveSmart.spin(forward);
  }
  // only tell the right drive motor to spin if the values are not in the deadband range
  if (DrivetrainNeedsToBeStopped_Controller1) {
    RightDriveSmart.setVelocity(drivetrainRightSideSpeed, percent);
    RightDriveSmart.spin(forward);
  }

Ignore all the DrivetrainNeedsToBeStopped_Controller1 stuff, the important parts are these

    int drivetrainLeftSideSpeed = Controller1.Axis3.position() + Controller1.Axis4.position();
    LeftDriveSmart.setVelocity(drivetrainLeftSideSpeed, percent);
    LeftDriveSmart.spin(forward);

you can see that drivetrainLeftSideSpeed is sent as a percentage to setVelocity which is followed by spin(forward). This means that there’s no point in using setDriveVelocity or setTurnVelocity when in driver control with the drivetrain mapped to the controller joystick, you are getting all the speed from the motors that is available.

4 Likes

I would add, I’m not a fan of the auto generated controller code. You can replace the over complicated drivetrain code on V5 with something like this.

int main() {
    while(1) {
      int left_drive  = Controller1.Axis3.position() + Controller1.Axis4.position();
      int right_drive = Controller1.Axis3.position() - Controller1.Axis4.position();

      if( abs(left_drive) < 5 )
        left_drive = 0;
      if( abs(right_drive) < 5 )
        right_drive = 0;
      
      LeftDriveSmart.spin(forward, left_drive, percent );
      RightDriveSmart.spin(forward, right_drive, percent );

      this_thread::sleep_for(20);
    }
}

so much cleaner and easier to read.

and a note on all the DrivetrainNeedsToBeStopped_Controller1 extra stuff.

This is generic code that VEXcode creates, it’s used on IQ Generation 1, Generation 2 and EXP as well as V5. On IQ 1&2, we try and limit the amount of communication with the motors, once the motors are stopped there little point in sending stop over and over, so the code uses a variable to remember if it has already sent stop, On V5 that’s completely unnecessary as motor communication is very different.

6 Likes

Great easy to read but thorough explanation.

Hopefully, this solves your issue 12345.

Thanks for the help.

One last issue is that we have a 4 motor drive, and the motors on each side need to spin in opposite directions. However, if we use a 4 motor drivetrain, I don’t believe it allows us to spin the motors on each side in opposite directions. Does anyone have any ideas on how to fix this?

Maybe you have the Torque set high?? IDK, but it’s gotta be a coding issue.

Please elaborate on this more.

If you mean in general one of the sides needs to be reversed to go straight then when you set up the dive you can choose to reverse certain motors.

Otherwise, if you mean turning using code there are blocks to turn which reverse one side to tank turn on the spot.

Need a bit more information on what your issue is.

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