Automatic limit switch

I previously found out how to program a limit switch that i can manually use. Now my question is how do i program a limit switch that will cause my motor to automatically stop spinning when it reaches a certain speed or position?

Can you better describe your application?

It sounds like a sensor problem other than a limit switch.

A spinning motor speed is usually controlled by an digital encoder sensor.

I am guessing that you want to stop something like an arm or the robot when it touches something? If you already know how to use the digital switch, then it is simply using that input to switch between the commanded signal and a stationary command. More details would be helpful.
Screenshots of what you have so far would be helpful too.

we have the digital switch. we need something in the code that makes the motor stop when it starts binding or reaches a certain amount of rotations. So far we have been sent a digital input example.

That sounds like a good job for a digital encoder.

Programming the robot to stop a motor when a digital switch activates is easy. See the attached snippet for an example of something that will keep a motor from going forward if the limit switch input is true.

However, what you’re describing doesn’t sound like something a digital switch can detect. Can you give some more information about how your limit switch is going to be physically activated?

Limit Switch.png


Limit Switch.png

An encoder would work best for this. To detect a bind, you would have the encoder, on a turn of the encoder, start a timer. If that timer reaches a certain value before the encoder triggers again, you would stop the motor. If it triggers, you would restart the timer again at zero.

If you wanted to stop after a number of revolutions, you would use a variable that would increment or decrement after a certain number of ticks, and if that number got to be higher or lower than a threshold, you would stop the motor in that direction, but allow it to turn the other way.

Sidenote about limit switches: Even easier, you could use the built in limit switch functions on the Jaguars to stop the motor. This wouldn’t work for your application, but it is great for just about everything else! You just have to use a normally closed switch, and plug it into the limit switch ports (Removing the existing jumpers)! Simple, easy to use, save a DIO, and it relieves the cRIO of having to deal with the code!