How would I setup 2x distance sensors for a buggy going along a linear track so that when one is close to the end it will only allow the motor to go in the reverse direction but not continue, then the same for the opposite end. Meanwhile as the buggy is away from the ends it may be controlled in either direction.
I will be using a RobotEq controller with PWM input and DC motor if it helps
There is not enough information here to give a detailed answer. Things like what computer/microcontroller is controlling your buggy, what distance sensors you are using, what have you tried, what do you have working? …
You might want to break this problem down into small pieces and first solve each piece and then put it all togeather. For example:
Make the buggy go forward.
Make the buggy go in reverse.
Maybe add code to ramp up or down the speed, as you probably don’t want to go instantly from full forward to full reverse…
Possibly read a value of some controller to change/set direction and speed? As you said something about it may be controlled in either direction? Get this working…
Read in the distance from one of your distance sensors.
Once you have these pieces working, you could start piecing it togeather where you would:
Start going forward
Check forward distance sensor. If it is below/above some threshold, you slow down and stop and then start in reverse.
Go in reverse and check the rear sensor if it is below/above some threshold you slow down and stop and then start going forward
…
Once this basically working you can start adding some enhancements, like at start-up you first ping forward and if you are above/below some threshold you start in reverse instead. Likewise depending on the range of your sensor and track and how long it takes to go from your crusing speed to a stop, you might add code that when you start getting closer to an end you start to slow down gradually. This would allow better control of how close you come to the end points…
Now if what I am reading in your problem statement is you use something like an RC controller or joystick that a user selects forward or reverse. The pieces go togeather in much the same way. Once you have the code in place to allow you to controll it in the direction the user selects, you then do the ping in the direction that the user chooses and if it is above/below some threshold you either ramp down and/or stop.
I am not sure if I answered your question very well, but Good Luck
Kurt