Elipse turning with a gyro sensor

I was working on sensor programming for team 785 using the gyro sensor but i ran into a road block when trying to do ellipses my issue is once i turn one direction i cant turn back to the original direction there aren’t any errors in the code i just don’t know what i have to change in order to go in reverse after i already made a turn

#include "robot-config.h"
void preauton()
{
  vex::task::sleep(300);
  Gyro.startCalibration();
  while(Gyro.isCalibrating())
  {
    vex::task::sleep(1);
  }
}


void autodrive(int speed)
{
    leftMotor.spin(vex::directionType::fwd,speed,vex::velocityUnits::rpm);			
    rightMotor.spin(vex::directionType::fwd,speed,vex::velocityUnits::rpm);	
}


void autoturn(int speed)
{
    leftMotor.spin(vex::directionType::fwd,speed,vex::velocityUnits::rpm);			
    rightMotor.spin(vex::directionType::fwd,-speed,vex::velocityUnits::rpm);
}

void autoelip(int speed, int speed2)
{
	
    leftMotor.spin(vex::directionType::fwd,speed2,vex::velocityUnits::rpm);			
    rightMotor.spin(vex::directionType::fwd,speed,vex::velocityUnits::rpm);
}



void autoturntime(int speed, int mSec)
{
 autoturn(speed);
 vex::task::sleep(1000);
 autodrive(0);
}



void elip(int speed, int speed2, int deg)
{
    Gyro.isCalibrating();
	
    while( fabs(Gyro.value(vex::rotationUnits::deg)) < deg*.6)
	{
autoelip(speed, speed2);
}

while( fabs(Gyro.value(vex::rotationUnits::deg)) < deg*.8)
{
autoelip(speed*.8, speed2*.8);
}

while( fabs(Gyro.value(vex::rotationUnits::deg)) < deg)
{
autoelip(speed*.6, speed2*.6);
}
autoturntime(-speed/2, 50);
}



int main ()
{

    
	preauton();

    
	if (Gyro.value(vex::rotationUnits::deg)<60)
	{
    elip(50, -100, 60);
   }
    
preauton();
    
	if (Gyro.value(vex::rotationUnits::deg)>1)
	{
    elip(100, -50, 1);
   }
    



    
 
  

    
}

the robot config is

vex::brain Brain;
vex::motor rightMotor = vex::motor(vex::PORT1);
vex::motor leftMotor = vex::motor(vex::PORT2,false);
vex::gyro Gyro = vex::gyro(Brain.ThreeWirePort.A);

anything helps thank you

nvm i fixed it i just needed to put the destination degrees from 1 to 60 because preauton sets the sensor values back to zero and added a wait time so when the sensor values are being reset it has a little time to calibrate and reset instead of instantly going right after

1 Like

You don’t have to recalibrate the Gyro before every rotation.

Please, try to avoid using fabs(Gyro.value()) function.
For PID starting from any heading you can calculate error=Gyro.value(vex::rotationUnits::deg)-targetDeg
Then turn only as long as fabs(error)>someThreshold.
You may also refer to this example: Drivetrain gyro turning - #3 by jpearman