Gyro Sensor


Is there any reason why the following code:

	SensorType[in3] = sensorNone;
	SensorType[in3] = sensorGyro;

would not set the gyro back to being a gyro sensor after the three seconds? I have been attempting this code in a separate task main, with the debugger sensor up, and without fail, everytime, the Gyro Sensor Value does not show up… Thank you for your help.

I don’t think the debugger live updates it’s list of sensors and assume that it uses the pragma statements to configure sensor type and name.

Actually, whenever I set it to sensorNone, it goes off of the list, and won’t even return when I run the function again. I have to reset RobotC to get it to come back up, but once I run a program that sets in3 to sensorNone, it won’t show up…

We have our’s in the pre-auton section of the code, as a function. And it appears to work correctly.

It should only need to execute once when the robot first starts executing

We’ve had no trouble with it using it as @NattyMan0007 is suggesting. However, we did call the function multiple times in our autonomous code, so that we could “reset” the gyro before each turn. What we found that was actually easier for these mini resets was to do this instead:

SensorValue[gyro] = 0;

This kept the value available on the debugger and didn’t require any waiting between turns.

That is also a way to do it. However there is a reason why you have to disable then re-enable instead of setting the value to just zero when you first load. I just can’t remember.

Yeah we still do that on the first load in preauton, but for subsequent resets the single-line method works better.

@ShadowIQ If your results are oscillating, try changing the sensor port or make sure its in the right analog port. For the debugger stream, try setting up the gyro in the “motors and sensors setup”(I am not certain about this but might be helpful - never mind if you already did it).

Just in case none of these work, try this code:

SensorType[in3] = sensorNone;
SensorType[in3] = sensorGyro;
wait1Msec(2000); // sets analog 3 to gyro.

Your code does not seem to have a wait statement after " SensorType[in3] = sensorGyro;"

Good luck!

Thanks for all of your help. I didn’t realize that if this was not done without the Vex Competition Includes File it wouldn’t work, as I was just plugging it into a task main. I put it in a competition template and it worked.