Can’t figure out how to code moving and turning simultaneously

We’re working on our code for states, and wanted to adjust the code so as an example we could move forward while also turning. We’ve struggling to figure this out and as of now our robot can only move forward/backward or turn not be able to do both at the same time. Any help to allow us to do both is greatly appreciated. I attached our code below:

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       VEX                                                       */
/*    Created:      Thu Sep 26 2019                                           */
/*    Description:  Competition Template                                      */
/*                                                                            */
/*----------------------------------------------------------------------------*/
 
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Controller1          controller                   
// Motor6               motor         6              
// Motor8               motor         8              
// Motor10              motor         10             
// ---- 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
//vex::controller Controller1 = vex::controller();
vex::motor backRight = vex::motor(vex::PORT1);
vex::motor backLeft = vex::motor(vex::PORT2, true);
vex::motor frontLeft = vex::motor(vex::PORT3, true);
vex::motor frontRight = vex::motor(vex::PORT4);
//vex::motor middle = vex::motor(vex::PORT5);
//vex::motor lift = vex::motor(vex::PORT6);
vex::motor intake = vex::motor(vex::PORT7, true);
motor_group allMotors = motor_group(frontLeft, frontRight, backRight, backLeft);
motor_group frontMotors = motor_group(frontLeft, frontRight);
motor_group backMotors = motor_group(backRight, backLeft);
motor_group leftMotors = motor_group(frontLeft, backLeft);
motor_group rightMotors = motor_group(frontRight, backRight);
motor_group leftDrive = motor_group(frontLeft, backLeft);
motor_group rightDrive = motor_group(frontRight, backRight);
 
vex::drivetrain train = vex::drivetrain(leftDrive, rightDrive, 13.3, 17.5, 15, distanceUnits::in, 1.0);
 
/*---------------------------------------------------------------------------*/
/*                          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.                                        
 // ..........................................................................
 // allMotors.spinFor(forward, 58, degrees);
 
}
 
/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              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
 
 intake.setVelocity(100, percent);
 Motor6.setVelocity(60, percent);
 Motor8.setVelocity(60, percent);
 Motor10.setVelocity(8, percent);
 
 bool taking = false;
   // 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.
   // ........................................................................
  while (true) {
  
   //Backwards
   if ((Controller1.Axis3.position() < 0) && (Controller1.Axis1.position() == 0)){
 
       if (Controller1.Axis3.position() < -75)
       {
         train.setDriveVelocity(100, percent);
       }
    
       else if (Controller1.Axis3.position() < -50)
       {
         train.setDriveVelocity(75, percent);
       }
        else if (Controller1.Axis3.position() < -25)
       {
         train.setDriveVelocity(50, percent);
       }
 
       else
       {
         train.setDriveVelocity(25, percent);
       } 
    
     train.drive(forward);        
 
   }
 
 
 
 
 
   //Forward
   else if ((Controller1.Axis3.position() > 0) && (Controller1.Axis1.position() == 0)){
 
       if (Controller1.Axis3.position() > 75)
       {
         train.setDriveVelocity(-100, percent);
       }
             
       else if (Controller1.Axis3.position() > 50)
       {
         train.setDriveVelocity(-75, percent);
       }
   
       else if (Controller1.Axis3.position() > 25)
       {
         train.setDriveVelocity(-50, percent);
       }
 
       else
       {
         train.setDriveVelocity(-25, percent);
       } 
     train.drive(forward);
 
   }
 
 
 
 
   //Right
   else if ((Controller1.Axis1.position() < 0) && (Controller1.Axis3.position() == 0)){
 
       if (Controller1.Axis1.position() < -75)
       {
         train.setTurnVelocity(100, percent);
       }
 
       else if (Controller1.Axis1.position() < -50)
       {
         train.setTurnVelocity(75, percent);
       }
    
       else if (Controller1.Axis1.position() < -25)
       {
         train.setTurnVelocity(50, percent);
       }
 
       else
       {
         train.setTurnVelocity(25, percent);
       }
 
       train.turn(right);
 
   }   
 
 
 
 
   //left
   else if (((Controller1.Axis1.position() > 0) && (Controller1.Axis3.position() == 0))){
 
     if (Controller1.Axis1.position() > 75)
     {
       train.setTurnVelocity(100, percent);
     }
 
     else if (Controller1.Axis1.position() > 50)
     {
       train.setTurnVelocity(75, percent);
     }
      else if (Controller1.Axis1.position() > 25)
     {
       train.setTurnVelocity(50, percent);
     }
 
     else
     {
       train.setTurnVelocity(25, percent);
     }
    
     train.turn(left);
    
   }
 
   //Backwards Left
   else if ((Controller1.Axis3.position() < 0) && (Controller1.Axis1.position() > 0)){
 
       if (Controller1.Axis3.position() < -75)
       {
         train.setDriveVelocity(100, percent);
       }
    
       else if (Controller1.Axis3.position() < -50)
       {
         train.setDriveVelocity(75, percent);
       }
        else if (Controller1.Axis3.position() < -25)
       {
         train.setDriveVelocity(50, percent);
       }
 
       else
       {
         train.setDriveVelocity(25, percent);
       } 
    
     train.drive(forward);        
 
 
     if (Controller1.Axis1.position() > 75)
     {
       train.setTurnVelocity(100, percent);
     }
 
     else if (Controller1.Axis1.position() > 50)
     {
       train.setTurnVelocity(75, percent);
     }
      else if (Controller1.Axis1.position() > 25)
     {
       train.setTurnVelocity(50, percent);
     }
 
     else
     {
       train.setTurnVelocity(25, percent);
     }
    
     train.turn(left);
    
   }
 
   //Backwards right
   else if ((Controller1.Axis3.position() < 0) && (Controller1.Axis1.position() < 0)){
 
       if (Controller1.Axis3.position() < -75)
       {
         train.setDriveVelocity(100, percent);
       }
    
       else if (Controller1.Axis3.position() < -50)
       {
         train.setDriveVelocity(75, percent);
       }
        else if (Controller1.Axis3.position() < -25)
       {
         train.setDriveVelocity(50, percent);
       }
 
       else
       {
         train.setDriveVelocity(25, percent);
       } 
 
     train.drive(forward);        
 
       if (Controller1.Axis1.position() < -75)
       {
         train.setTurnVelocity(100, percent);
       }
 
       else if (Controller1.Axis1.position() < -50)
       {
         train.setTurnVelocity(75, percent);
       }
    
       else if (Controller1.Axis1.position() < -25)
       {
         train.setTurnVelocity(50, percent);
       }
 
       else
       {
         train.setTurnVelocity(25, percent);
       }
 
       train.turn(right);
 
   }
 
 
   //Forward Right
   else if ((Controller1.Axis3.position() > 0) && (Controller1.Axis1.position() < 0)){
 
       if (Controller1.Axis3.position() > 75)
       {
         train.setDriveVelocity(-100, percent);
       }
             
       else if (Controller1.Axis3.position() > 50)
       {
         train.setDriveVelocity(-75, percent);
       }
   
       else if (Controller1.Axis3.position() > 25)
       {
         train.setDriveVelocity(-50, percent);
       }
 
       else
       {
         train.setDriveVelocity(-25, percent);
       } 
     train.drive(forward);
 
       if (Controller1.Axis1.position() < -75)
       {
         train.setTurnVelocity(100, percent);
       }
 
       else if (Controller1.Axis1.position() < -50)
       {
         train.setTurnVelocity(75, percent);
       }
    
       else if (Controller1.Axis1.position() < -25)
       {
         train.setTurnVelocity(50, percent);
       }
 
       else
       {
         train.setTurnVelocity(25, percent);
       }
 
       train.turn(right);
 
   }
 
   //Forward left
   else if ((Controller1.Axis3.position() > 0) && (Controller1.Axis1.position() > 0)){
 
       if (Controller1.Axis3.position() > 75)
       {
         train.setDriveVelocity(-100, percent);
       }
             
       else if (Controller1.Axis3.position() > 50)
       {
         train.setDriveVelocity(-75, percent);
       }
   
       else if (Controller1.Axis3.position() > 25)
       {
         train.setDriveVelocity(-50, percent);
       }
 
       else
       {
         train.setDriveVelocity(-25, percent);
       } 
     train.drive(forward);
 
     if (Controller1.Axis1.position() > 75)
     {
       train.setTurnVelocity(100, percent);
     }
 
     else if (Controller1.Axis1.position() > 50)
     {
       train.setTurnVelocity(75, percent);
     }
      else if (Controller1.Axis1.position() > 25)
     {
       train.setTurnVelocity(50, percent);
     }
 
     else
     {
       train.setTurnVelocity(25, percent);
     }
    
     train.turn(left);
   }
 
   //Stop
   if (Controller1.Axis1.position() == 0 && Controller1.Axis3.position() == 0){
 
    train.stop();
   
   }
 
 
 
   //Control for intake conveyar belt
   //If B is pressed the intake spins, and otherwise it stops
   if (Controller1.ButtonA.pressing()){
     taking = true;  
   }  
 
   if (Controller1.ButtonY.pressing()){
     taking = false;  
   }     
 
 
   if (taking == true) {
     intake.spin(reverse);
   }
 
   else
   {
     intake.stop();
   }
 
 //lift controls are in the robot configuration menu
  Motor6.setStopping(hold);
  Motor8.setStopping(hold);
  Motor10.setStopping(hold);
 
   //Control for the genral speed of the robot
   //Pressing the right button sets the robot to a faster setting
   //Pressing the left button sets the robot to a slower setting
 
 
   //Stops the drivetrain and middle motor when there isn't any input
 
 
   wait(15, 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.
 //ompetition.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);
 }
}

edit: code tags added by mods

I didn’t look at your code but our team uses bézier curves, or we just do it manually by setting motor speed and time as we don’t need to turn and drive very often.

1 Like