An optimal control approach to the design of periodic orbits for mechanical systems with impacts