A hybrid system approach to impedance and admittance control