How to know distance mBot travels?


#1

The task my daughter invented for the mBot is bringing something (cookies) over from kitchen to her room. As of now it does it - we timed the legs and turns at given speeds and programmed them with going forward and then delay for appropriate time. The thing is, though, that I would love to add basic obstacle detection (make robot stop if something is in its path) and I wonder how would I do that? I could use milis() (even though it would require to write in C as I don’t think block has it) and some elaborate state switching to follow the path while looking for obstacles in the main loop - but maybe there is a better way?

Also, does “speed” officially translate into anything - is this mms/min or cms / hour?


#2

You can use the ultrasonic sensor to detect obstacles.

I dont know an obvious way to measure distance.

You could use the line follower to detect marks on the ground which indicate certain positions.


#3

I published an ebook (link) last May that has an obstacle avoidance exercise and other exercises related to controlled autonomous movement that you may or may not find helpful.

Normally one would use the ultrasonic sensor as @Andreas mentioned. Just be aware that the ultrasonic sensor is a bit jittery and that it will report zero (0) if there is no obstacle in range. There is a discussion (link) that you may find helpful with a code sample at the end of the discussion.

Regards,

Chuck


#4

Hi Chuck,

according to release logs: since mBlock version 3.3.5 is displayed “400” instead of “0”, if the ultrasonic sensor can not detect anything in the detection area.

Release Logs

Gerhard


#5

Thanks! I need to update my ebook because it was written before 3.35. :slight_smile:


#6