The steps are
- We use a rotation sensor from the sensors menu and set it to reset the sensor on motor B
- Set motor B and C to drive unlimited ...
- ... until the US sensor senses something closer than e.g. 50 cm.
- Then we read the rotation sensor. Here we use the data hub on the sensor to find out how many degrees the sensor has rotated since last reset. This is why we needed to reset the sensor just before we started to move forward.
- The last move block is set to run a specific number of degrees backwards. The actual amount doesn't matter, because it will read the actual amount from the data hubs "duration" entry. This is tied by a datawire to the rotation sensor, which in turn knows how many degrees that the motor turned when it went forward. That way it will turn backwards just as many degrees and therefore end up where it started.
You can download the .rbt file here: forwards_and_backwards.rbt
No comments:
Post a Comment