Stability analysis using controlled invariant sets for piecewise-affine systems