Epidural electrical stimulation (EES) of the spinal cord and real-time processing of gait kinematics are powerful methods for the study of locomotion and the improvement of motor control after injury or in neurological disorders. Here, we describe equipment and surgical procedures that can be used to acquire chronic electromyographic (EMG) recordings from leg muscles and to implant targeted spinal cord stimulation systems that remain stable up to several months after implantation in rats and nonhuman primates. We also detail how to exploit these implants to configure electrical spinal cord stimulation policies that allow control over the degree of extension and flexion of each leg during locomotion. This protocol uses real-time processing of gait kinematics and locomotor performance, and can be configured within a few days. Once configured, stimulation bursts are delivered over specific spinal cord locations with precise timing that reproduces the natural spatiotemporal activation of motoneurons during locomotion. These protocols can also be easily adapted for the safe implantation of systems in the vicinity of the spinal cord and to conduct experiments involving real-time movement feedback and closed-loop controllers.