I'm hoping for a bit of help with a challenge I'm faced with solving.

I have a project that aims to "automatically" sort AA batteries by remaining voltage/capacity.

I believe I have a handle on the voltage sorting portion, yet the physical orientation of the batteries is tripping me up.

With a voltage reading of a positive number or negative number, I can determine if the battery is oriented incorrectly.

Yet, I'd like to find a circuit solution to possibly switch the negative and positive leads so the batteries polarity is correct and functions like a properly oriented battery.

I'm hoping this explanation makes sense -- I'm a lifelong newbie.

Thanks for any help!