Stopping PID with a limitswitch

I’m using the PID from de Neo motors and I want to know how to stop a motor using the PID with a limit switch?

1 Like

Can you be more specific? Do you want the motor to stop moving while the limit switch is held down, or do you want to disable output in a particular direction? Do you want the limit switch to “zero” your sensors or reset your setpoints? Can you post the code you do have?

1 Like

I want to use the limitswitch to set the zero. For example, at the end of a mach the arm finish up, I tell the PID to go down until the limitswitch is activated and then set the zero.

1 Like

Depending on your programming language, this would require a simple if statement or case structure. if(limit_switch.get() == TRUE) { motor.power(0); encoder.zero(); }. You would need some more logic to be able to get out of this case.

1 Like

You can’t just set the motor output to zero when you hit the limit switch though, or else you won’t be able to move the arm for the rest of the match. You need to disable output in only one direction.

1 Like

For your logic to stop the motors, check for when the PID setpoint is set to the home position and the limit switch is being hit, otherwise let the PID do the work. For encoder zeroing, do it every time the elevator hits the limit switch

Thanks!

Yeah, hence the “more logic to get out of this case”.