I have a stepper motor that moves a trolley on rails over a distance of 300 mm. The steps from the start position is fixed, but if the motor is knocked or slips, then it won’t know its position. Therefore, is there a way I include stopper sensors (such as an IR beam break) that once the sensor value changes, the motor direction will change? Any help with the code on this? Any other ideas?