Team2168 / 2022_Main_Robot

Other
3 stars 0 forks source link

added try/catch for division in colorsensor #54

Closed natejank closed 2 years ago

jcorcoran commented 2 years ago

Have the color sensor code changes been tested on the robot?

natejank commented 2 years ago

yes

this was just to fix an issue during drive practice where the color sensor reported zero and crashed the entire robot

it seemed like the most direct solution

natejank commented 2 years ago

I decided the easiest solution would just be to catch the exception in getAlliance to return Invalid directly instead of relying on side effects. The only potential downside do doing it this way is that ArithmeticExceptions are unchecked, so if we decide to call normRaw anywhere else, we'd have to also catch there and the method doesn't have any indication that it actually throws something (I'm not sure why we'd be calling it).

The other option would be to define an InvalidStateException to throw after getting a DivByZero to make sure we always catch, but I didn't think that would be necessary.