Autocalibrate function

I think we can all agree in saying that this years joysticks were really lousy. Ours lost calibration even with tape on the wheels.

I want to write an auto calibration function for the sticks so they we can compensate for a reasonable error (say, 10 -15). I have been programming for years but i am rather new to C and more importantly, to the default code. The way i had in mind was to use the user initialization function to grab the values of the sticks (assume they are at center) and calculate offsets that would later be applied to the drive function. I realize that issues that can come up regarding the drive curve when doing this and i have already solved them. What i need to know is if joystick values can be read AT COMPETITIONS in the user initialization function.

Thanks ahead of time!!

The joystick values should be able to be read during initialization, but just to be safe you could read them in the whole time during which the robot is disabled (by checking the disable bit).

We do almost the same thing, since our joysticks often become decalibrated, but instead of reading the joystick values at initialization or while in disable mode, we read them whenever p1_sw_top is depressed. That way we can quickly recalibrate during a match if the trim tab somehow gets moved. To calibrate before the match, we simply hit the button while the robot is on but disabled.

Hope this helps.

I did it slightly differnt.

I read the joystick value at all times. If its greater then the max, or smaller then the lowest, I set either the high/low to the new value, update it in eeprom, and set the new center to (high+low)/2, after that, joystick deadbands are achieved by dividing (high-low) by 30.

I just looked through my code, and realized that I never actually used the center point. Weird, I should probably fix that.