precision current sink for battery discharge
This is pretty simple.







simulate this circuit &ndash; Schematic created using CircuitLab

The comparator is any open-collector comparator which will run from your op amp supply. The Ref input can be any handy voltage less than the battery. For instance, if your op amp is run from 5 volts, dividing down to 2.5 would be simple enough. R3 and R4 produce a comparator voltage which is comfortably above the Ref voltage when the battery is connected. For this example, a 2:1 ratio will give 3 volts, compared to the 2.5 Ref. When the battery is present, the comparator output will not affect the op amp input, but when the battery is disconnected the divider output will go to 0, the comparator output will go low, and the op amp input will be pulled to ground.

Depending on your op amp voltage, you might not even need a divider. If you use a 12 or 15 volt supply, you could sense both the supply and the battery directly, assuming neither condition violates your comparator input limits.