How to slowly stop a robot when a sensor is triggered?

I want to make the robot smoothly stop when a sensor is active. How can I do that?

One easy way is to have a thread running that is monitoring for this sensor. When you see this sensor come on, issue a stopj() command, then a halt.


You can experiment with the value inside the stopj() command. A larger value will stop faster, a lower value will stop slower.