Layered Control Architectures: Constructive Theory And Application To Legged Robots