Elevator top limit doesn't work properly

So, we are using an elevator this year. Currently, we’re trying to use a soft limit on the top and the bottom to stop the elevator at its endpoints. This is the code:

public void translateElevator(double speed) {
        if (m_ElevatorEncoder.getPosition() <= Constants.k_ElevatorMax && speed > 0) {
            m_ElevatorLeader.set(speed);
        } else if (m_ElevatorEncoder.getPosition() >= 0 && speed < 0){
            m_ElevatorLeader.set(speed);
        } else {
            m_ElevatorLeader.set(0);
        }
    }

the bottom limit works perfectly. It stops at the bottom and can go back up.

The problem is that on the top limit, it stops when it reaches it but then it can’t go back down. The spark maxes are showing that the motors aren’t even trying to go back down. Is my logic bad?

Thanks!!

are you passing a negative value for speed when trying to go down? based on your “if” that is what should be happening and seems like the only thing that might be out of sync.

Yes I am passing a negative value.

you might need to confirm that your encoder value you are getting back is moving to a correct position/value then to satisfy your if

The encoder value is stopping just above the limit. I verified with the smart dashboard.

The logic says that if you are at your ElevatorMax and your speed is positive, it should drive it positive (I’m assuming that a positive drive is going up).

That’s not what you’re looking for I would assume.

Edit to add:
You may be looking at something like this instead:

public void translateElevator(double speed) {
        double pos = m_ElevatorEncoder.getPosition();
        if (speed > 0 ) {
            if( pos >= ElevantorMax ){
                     // Don't want to go higher anymore
                     speed = 0
            }
        } else if ( speed < 0){
            if( pos <= 0 ) {
                    // Don't want to go downward anymore
                    speed = 0;    
        } else {
            // Speed = 0, or in some  case that's odd , just be safe
            speed = 0;
        }
        m_ElevatorLeader.set(speed);
    }