A few programming questions

Hi VEX forum… I have a few questions about gyro sensor.

First, How do I zero a gyroscope like how I would zero an encoder?
Can I use the SensorValue[Gyro] = 0; command to do this? Is this a command that can be executed in a short amount of time? Or is this more like re-initializing the gyroscope and it takes a few seconds?
Without using the command mentioned above, I still managed to pull together a small program that lets me manually reset gyro… I guess that Robotc does the same thing.


int gyrooutput;
int gyrocurrentvalue = 0;

void resetGyro (int value = 0)
{
	gyrocurrentvalue = SensorValue[Gyro] + value;
}

task GyroProcessingBlock () 
{
	while (true)
	{
		gyrooutput = SensorValue[Gyro] - gyrocurrentvalue;
	}
}

Just an idea that I had a long time ago. You use the global variable called gyrooutput as the sensor value. But today as I actually tested this out on LCD, there is a glitch. I display the gyro output on LCD, and every time I use the zero gyro command, the display of gyrooutput on LCD glitches between the real value and the processed output value, which is very weird…

The following is the command I run in a loop to display gyro values:


void DisplayGyroValue ()
{
	displayLCDCenteredString(0,"GyroRaw GyroFine");
	displayLCDNumber(1,0,SensorValue[Gyro],5);
	displayLCDNumber(1,7,gyrooutput,5);
	if (nLCDButtons == 2)
	{
		resetGyro();
	}
}

So is it my gyro processing loop’s issue, the LCD display program’s issue, or something else? Seems like two tasks are conflicting and they are both commanding the LCD, but I don’t see how this can happen.

Thanks!

Plus, THANK YOU Mr. Pearman for posting that wonderful thread of how to reduce gyro drift… I used rubber link on the base for mounting a gyro, and there was basically no drift. No drift! It was so awesome.

would it help to wait a few milliseconds in your task? Who knows how many cycles that is taking versus everything else.

Link to gyro drift thread?

https://vexforum.com/t/gyro-drift-mechanical-improvements/25343/1

Yes… thank you. I was so caught up elsewhere and I forgot to do that. Will try that tomorrow and see if there’s any improvements.

VEXMen thank you! I added 10 ms of delay in the loop and tested it out today. The issue disappeared. Thanks so much!