The solution you presented is correct -- if you use the Simscape Multibody Multiphysics Library, you can apply a penalty torque when the joints hit their limits. This works fine if you're actuating your joint using torque signal.
What didn't work in that solution?
- Sebastian