Modeling and control of locomotion in complex environments