Autonomous: Robot Isn't Turning - In Need of Help

Hey everyone,

My team has our final competition this Saturday, and we are trying to get our WP autonomous to work. However, whenever we try to get the robot to turn, it doesn’t turn properly, and it seems as if something is preventing the robot from finishing the full turn.

For context, when running autonomous, even when the robot seemingly stops, when we lift up the chassis, the wheels spin perfectly fine.

We have tried changing the velocities, tuning down the turning, and adding additional wait times in between each task.

Is there anything that could be done to fix this problem? For example, should we add a timeout between each step?

Side Note: Just in case this helps, we have a four motor tank drive with each wheel geared to a 3/5 ratio (output/input).

Thank you so much!

Here is our program:

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    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                    
// bclaw                motor         21              
// Claw                 motor         16              
// bLeft                motor         19              
// fLeft                motor         20              
// fRight               motor         18              
// bRight               motor         17              
// larm                 motor         12              
// rarm                 motor         2               
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"
#include "VisionSensor.h"

using namespace vex;

// A global instance of competition
competition Competition;

// define your global instances of motors and other devices here

/*---------------------------------------------------------------------------*/
/*                          Pre-Autonomous Functions                                                */
/*---------------------------------------------------------------------------*/

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                                                                */
/*---------------------------------------------------------------------------*/

//global statements (T-T)

void dt(int pos, int speed, bool stopping) {
  bRight.rotateFor(pos, rotationUnits::deg, speed, velocityUnits::pct, false);
  fRight.rotateFor(pos, rotationUnits::deg, speed, velocityUnits::pct, false);
  fLeft.rotateFor(pos, rotationUnits::deg, speed, velocityUnits::pct, stopping);
  bLeft.rotateFor(pos, rotationUnits::deg, speed, velocityUnits::pct, stopping);
}

void rd(int pos, int speed, bool stopping) {
  bRight.rotateFor(pos, rotationUnits::deg, speed, velocityUnits::pct, false);
  fRight.rotateFor(pos, rotationUnits::deg, speed, velocityUnits::pct, false);
}

void ld(int pos, int speed, bool stopping) {
  bLeft.rotateFor(pos, rotationUnits::deg, speed, velocityUnits::pct, false);
  //changed stopping to false, possible fix
  fLeft.rotateFor(pos, rotationUnits::deg, speed, velocityUnits::pct, false);
}

void Arm(int pos, int speed, bool stopping) {
  rarm.rotateFor(pos, rotationUnits::deg, speed, velocityUnits::pct, stopping);
  larm.rotateFor(pos, rotationUnits::deg, speed, velocityUnits::pct, stopping);
}

//rotates the claw
void cm(int pos, int speed, bool stopping) {
  Claw.rotateFor(pos, rotationUnits::deg, speed, velocityUnits::pct, stopping);
}

void bcm(int pos, int speed, bool stopping) {
  bclaw.rotateFor(pos, rotationUnits::deg, speed, velocityUnits::pct, stopping);
}

void autonomous(void) {
//TASK 1 - Dispenses the ring from the back claw
  bcm(600, 80, true);

  bcm(-600, 80, true);
 
  //TASK 2 - Drives forward 
  dt(110, 90, true);

  //TASK 3 - Turns left 
  ld(500, 70, false);
  rd(-500, 70, false);
  
  //TASK 4 - Drives Forward one block
  dt(110, 50, true);
  
  //TASK 5 - Turns Left to Reposition
  ld(500, 95, false);
  rd(-500, 50, false);

  //TASK 6 - Zooms across the field 

  dt(2300, 110, true);
 
  //TASK 7 - Dispenses ring from front claw 
  dt(90, 20, true);

  cm(450, 80, true);

  //TASK 8 - Drives out of the awl

  dt(-350, 100, true);

  wait(20, msec);

}

/*---------------------------------------------------------------------------*/
/*                              User Control Task                            */
/*---------------------------------------------------------------------------*/

void usercontrol(void) {
  // User control code here, inside the loop
  while (1) {
    // 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.
    // ........................................................................

    wait(20, msec); // Sleep the task for a short amount of time to
                    // prevent wasted resources.
    
  bLeft.spin(vex::directionType::fwd, Controller1.Axis3.position(), vex::velocityUnits::pct);
  fLeft.spin(vex::directionType::fwd, Controller1.Axis3.position(), vex::velocityUnits::pct);
  fRight.spin(vex::directionType::fwd, Controller1.Axis2.position(), vex::velocityUnits::pct);
  bRight.spin(vex::directionType::fwd, Controller1.Axis2.position(), vex::velocityUnits::pct);
   wait(20, msec); 
 
  if (Controller1.ButtonL1.pressing()){ 
    Claw.spin(directionType::fwd, 95, velocityUnits::pct);  
  }
  else if (Controller1.ButtonL2.pressing()){
    Claw.spin(directionType::rev, 95, velocityUnits::pct);
  }
  else{
    Claw.stop(brakeType::brake);
  }

  if (Controller1.ButtonUp.pressing()){ 
    bclaw.spin(directionType::fwd, 95, velocityUnits::pct);  
  }
  else if (Controller1.ButtonDown.pressing()){
    bclaw.spin(directionType::rev, 95, velocityUnits::pct);
  }
  else{
    bclaw.stop(brakeType::brake);
  }

 
   if(Controller1.ButtonR1.pressing()){
     larm.spin(directionType::fwd, 90, velocityUnits::pct);
     rarm.spin(directionType::fwd, 90, velocityUnits::pct);
   }
   else if(Controller1.ButtonR2.pressing()){
     larm.spin(directionType::rev, 90, velocityUnits::pct);
     rarm.spin(directionType::rev, 90, velocityUnits::pct);
   }
   else if(!Controller1.ButtonUp.pressing() && !Controller1.ButtonDown.pressing() && !Controller1.ButtonB.pressing() && !Controller1.ButtonX.pressing()){
     larm.stop(brakeType::brake);
     rarm.stop(brakeType::brake);
   }

  }
}

//
// 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);
 
  }
}
2 Likes

Is it you or your team?

The same code and question have already been answered.

Please spend some time searching and reading the post.

How did your tournament go?

Hihi! Yeahh that was my teammate, who also posted since we were kind of desperate for an answer at the time (T-T). But hey, we eventually figured out that it was an issue with the global statements, and auton ran pretty well!

Heyhey!

We actually won the Excellence Award, so I’d say it went pretty well :3

Great! Nice work!
20 char

1 Like