ARDUINO ROBOT: enable motor when the robot is powered from the USB

Hello,
is there any easy way to enable motor when the robot is powered from the USB or adapter. Is it possible to make it "software way ?
Thx

By sensing the voltage on Vin using a voltage divider and an analog pin?

Thx. Not sure If I understand what you mean. Do you know how the "safe mechanism" works ? I just need to run robot without batteries, but when I connect usb or adapter power,that "safe block disables the motors". I work with original arduino robot.
Thanks