This is an interesting problem which I am tackling as well.
In industrial applications (my day job), we would normally monitor the rotation of a non-driven wheel, such as the pivot wheel on the mBot. We would do this with an encoder of some sort. If the non-driven wheel is not turning…the bot isn’t going anywhere and should undertake extrication maneuvers.
Monitoring the drive wheels would tell you if they had stalled, but if they were slipping it would appear that the bot was still moving.
Since the pivot wheel is small and space constricted, an alternative is to mount another non-driven wheel with a monitoring system.
To monitor the wheel, an encoder could be used but it would have to be very low drag. For the drive wheels, one could position an infrared sensor to monitor the holes in the wheel. Reflective spots could be used, or a small protruding flag which rotates with the wheel could be detected. The simplest method is probably to glue one or more magnets near the rim of the wheel. There are many mechanical and electronic sensors which can detect the magnets passing by.
Now…let’s get inventive…using what you’ve got…
If the ultrasonic sensor value seems to be frozen in a very narrow range for several seconds (30?)…you might be stuck. Or you might be in the middle of a very, very large area like a gymnasium. Determining which is the trick!
Like all organisms, the bot might be tuned for his environment. In a typical house, the bot might expect to reach a barrier every 30 seconds…a wall, furniture, etc. If that doesn’t happen, the bot should become claustrophobic and begin extrication maneuvers.
I see the bot’s plight as similar to the ancient mariners. As long as the bot hugs the coast (a wall), then he has a reference point. If the bot journeys away from the wall out of sight distance (ultrasonic range), then it can be pretty confusing. Monitoring the movement of the stars (the overhead room lights) or variations in the floor might be the only navigation clues.
It would be nice if the IR sensor returned a value instead of being go/no-go. Monitoring slight changes might give clues as to whether or not the bot is moving. Perhaps the light sensor module could be pointed at the floor and used to monitor changes in reflectivity which might indicate motion.