VEXcode Pro V5 motor intake isn't working in autonomous

During driver control the intake is working fine. It works perfectly with the code during that section of the match. But during autonomous it doesn’t function at all. here is our code for autonomous

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    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    7, 8, 9, 10     
// Motor1               motor         1               
// Motor2               motor         2               
// Motor3               motor         3               
// Motor4               motor         4               
// Controller1          controller                    
// ---- 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();
Motor1.setVelocity(100,percent);
Motor2.setVelocity(100,percent);
Motor3.setVelocity(100,percent);
Motor4.setVelocity(100,percent);
  // 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) {
  Drivetrain.setDriveVelocity(50, percent);
  Drivetrain.setTurnVelocity(50, percent);
  Drivetrain.driveFor(forward, 18, inches);
  Motor4.spinFor(forward, 2, seconds);
  Motor2.spin(forward);
  Motor3.spin(forward);// Won't spin (Needs fix)
  Drivetrain.turnFor(left, 50, degrees);
  Drivetrain.driveFor(forward, 3, inches);
  Motor1.spin(forward);
  Motor4.spin(forward);
  wait(5, seconds);

I can suggest you to use function
motorName.spin(forward,Speed,percent);
it replace spin and velocity functions

And i can’t see any intake motors in your code

What you need is a function above your pre auton code to do driving and such during a auton. For example a function to intake in would look like,

void intIn( float distance, int speed){
  IntL.rotateTo(distance, rotationUnits::rev,speed, velocityUnits::pct,false);
  IntR.rotateTo(-distance, rotationUnits::rev,speed, velocityUnits::pct);
}

and would be put behind your pre-auton, and you would call it in your auton with simply: IntIn(revs, %speed);

you also need to reset the encoders after every command in your auton. Even though V5 has built in encoders in motors, you still need to reset them, otherwise your auton will be very messed up. You can make a little reset encoders function with:

void resetEncoders(){
    BR.resetRotation();
    FR.resetRotation();
    BL.resetRotation();
    FL.resetRotation();
 }

and then just have resetEncoders( ); after every auton command. For example, if my auton was:

FrontLeft.spin(x,y);
FrontRight.spin(x,y);
BackLeft.spin(x,y);
BackRight.spin(x,y);

I would make a function such as:

  void forward1(float distance, int speed){
    FL.rotateTo(distance,vex::rotationUnits::rev,speed, vex::velocityUnits::pct,false);
    FR.rotateTo(distance,vex::rotationUnits::rev,speed, vex::velocityUnits::pct,false);
    BL.rotateTo(distance,vex::rotationUnits::rev,speed, vex::velocityUnits::pct,false);   
    BR.rotateTo(distance,vex::rotationUnits::rev,speed, vex::velocityUnits::pct);
    
 }

(its called forward1 because just saying forward will activate some weird autocorrect thing)

and then make my auton look like:

Forward1(x,y);
resetEncoders( );

and then build on that. BTW, when you make your own function to move multiple motors simultaneously, put “false” at the end of every line in the function except for the last one. This will turn off a built in thing that will run each motor one by one.

I know this might sound a little confusing but if you need any help just ask me. I’ve been coding for a very long time so I can most likely help you with all of your questions.

P.S. I recommend activating expert robot config. it gives you more control over thing like this.

1 Like

I like the idea of encoders they could be the solution for the intake to work. But the issue I have is how to set it up. I get what you’re saying but I’m getting confused on setting it up throughout my teams code.

What code are you using?

What do you mean about what code am I using?

The thread is in #programming-support:vexcode-tech-support .

I’m asking because you said that you don’t know how to add this to your code. Would you just like me to clarify, or are you using blocks or something like that?

Yeah I’m not using blocks. I just want more clarification to add on to this. Getting a bit confused on how to add this to the code.

So basically, there is a section above your pre-auton where you can add these types of functions for your auton. Let’s say that you have 2 intake motors, Int1 and Int2, and let’s say that intake 2 is already set to reversed, so having both motors spin forward will cause a ball to intake. So, let me walk you through the code.

You would make this function by:

void intIn( float distance, int speed){
IntL.rotateTo(distance, rotationUnits::rev,speed, velocityUnits::pct,false);
IntR.rotateTo(-distance, rotationUnits::rev,speed, velocityUnits::pct);
}

So, void IntIn is making the function called IntIn (shorthand for intake in). Float and int call variables, and as you see in the code, I call the variables directly by their names, distance and speed. Because of this, when I call the function in my auton with

IntIn(10,10);

The tens (which are examples) will get plugged into the function, therefore making the intakes move 10 rotations at 10 percent speed. And I can make these any numbers I want, making this a sort of “customizable” function. ( I don’t know the official name for it).

And what is also necessary to have, is a reset encoders function, which can be made with simply:

Void resetEncoders(){

MotorNameThatYouNeedHere.resetRotation();
}

And add as many motors as you need inside that function. Then, after every function you call in your auton, do a

resetEncoders();

to keep everything happy. If you’re still confused about a certain part, don’t be afraid to ask. I understand that trying to understand code through some text in a screen can be difficult.

2 Likes

Thanks for the help, but it’s not working for my issues.

Sorry to hear that. I’ll try to think of other things. In the meantime though, hope you figure it out!