Vex Coding Studio Gyro endless counting

i was programming for my 3 different teams 785B E and Z as team A has their own programmer and the team decided using a gyro sensor in order to get more accurate turns would be better for competitions while programming the first bot i got the code to work fine the gyro is working and nice but the second bot the gyro sensor doesn’t stop counting up one problem i did run into was the fact i was translating old code I wrote last year from robotC to C++ for VCS i used absolute values and a lot of voids just to make things easier in the long run even after the is calibrating the gyro still continues to count up

a bit of my code

#include "robot-config.h"
void preauton()
{
    Gyro.isCalibrating();
}


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*.4, speed2*.4);
}
autoturntime(-speed/2, 50);
}

int main ()
{




	preauton();

	if (Gyro.value(vex::rotationUnits::deg)<90)
	{
	elip(-50, 100, 91);
    }


}

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);

Wait, are you a student or an educator? If you are an educator you can’t work on the code, only explain programming concepts and stuff like that.

i am a student im a junior in high school

@stonedagger the problem with gyro counting up, usually occurs when robot starts moving before gyro calibration is done.

Take a look at the vex Gyro API: https://www.robotmesh.com/docs/vexv5-cpp/html/classvex_1_1gyro.html

The correct usage of isCalibrating() would be:

void preauton()
{
  while(Gyro.isCalibrating())
  {
    vex::task::sleep(1);
  }
}
1 Like

this stopped the counting but now it isn’t even moving and giving a value of 65534
image

First of all, make sure that the wire is fully inserted into 3-wire port and connected to the Gyro with proper polarity (black wire is Ground).

Then try to change your preauton as follows and see if it helps:

void preauton()
{
  vex::task::sleep(300);
  Gyro.startCalibration();
  while(Gyro.isCalibrating())
  {
    vex::task::sleep(1);
  }
}

V5 has a quirk, where reading values of sensors, connected to legacy 3-wire ports (analog and digital), were returning 0 if you try to read them right after V5 startup.

So if you are trying running autonomous right after program starts you would need to delay reading those sensors for a short period of time to let it properly initialize.

More details are in this topic:

Finally, you can edit your original post (pencil button) and put [code]...[/code] tags around your code for better readability.

2 Likes

before u get to into vcs i would switch over to vexcode its just all around beter and vex discontinued vcs

ive been on vcs for the past year i switched mid year last year so im already in it

ill try this and see if it works thanks for your help

it worked thank you so much :smiley:

2 Likes