Thread: LimitSwitches
View Single Post
  #4   Spotlight this post!  
Unread 02-24-2016, 02:27 PM
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: LimitSwitches

Alternatively, you can do fairly sophisticated software control on your lift such that it knows when it's approaching the limit switches (via encoder/potentiometer) and applies PID control to slow it down. So eventually, it will gently "hit" the limit switch and stop. In fact with this capability, you don't even need the upper limit switch, this is called "soft limit". This is especially useful because while it is generally easy to add a lower limit switch, it is sometimes difficult to add an upper limit switch. For example, if you have an extending arm, it is sometimes impossible to find a place to mount an upper limit switch because it extends into open space. We have a PIDMotor class in our library that implements this capability. There is a method in this class:
Code:
public void setPidPower(double power, double minPos, double maxPos, boolean holdTarget)
In this method, you tell it what maximum motor power you want to drive the motor (typically, it receives this value from the joystick). You also provide the range of motion the motor can travel. It will check against this range using the encoder (or potentiometer). A lower limit switch is used to "zero calibrate" the encoder (or potentiometer). An optional upper limit switch can be used as an additional safety for the upper range. Finally, the holdTarget boolean specifies whether it should use active PID to hold the current position when you stop the motor (i.e. power is set to zero). The code for this class can be found here.
https://github.com/trc492/Frc2016Fir...cPidMotor.java
__________________
Reply With Quote