Try something like this. It's a little quickly done, so I'm sure there's room for optimization or elegance, but this works.
You need to track the velocity or direction command as a state in addition to the position. Pass the current one through if it's not outside of the upper or lower limit, and set the up/down direction if it passes it.
Take a look at the backlash (hysteresis) block too. It may not be useful here, but it's helpful to model things like stiction, which you might need if you're working with a hydraulic cylinder.