Sample Code For Locomotion

This is the content of the script used in Introduction to Junior and Dynamism for locomotion.

import dy
import math
import time
import sys
 
hostname = 'localhost'
host = None
speed = 1.0
walk_interval = 5.0
if len(sys.argv) >= 2:
    hostname = sys.argv[1]
host = dy.network.connect(hostname,8650)
 
ds = dy.data.path(hostname)
 
dyspeed = dy.data.create_at(ds, dy.DY_FLOAT, 'gait.speed')
 
while 1:
    dy.signal.send_to(host,'calibrate_start')
    raw_input('Hit ENTER once the calibration is done...')
    s=raw_input('Was the calibration succesful?(y or n)\n>>')
    if s == 'y':
        break
 
dy.signal.send_to(host,'stand_start')
raw_input('Hit ENTER once the robot is at a standing posture...')
 
dy.signal.send_to(host,'gaitrunner_start')
print 'Gaitrunner is activated'
dy.data.set_float(dyspeed,speed)
dy.network.push_to(host, '%s.gait.speed' % hostname)
print 'Speed is set to:', speed
 
time.sleep(walk_interval)
 
dy.data.set_float(dyspeed,0.0)
dy.network.push_to(host, '%s.gait.speed' % hostname)
print 'Speed is set back to 0.0'
time.sleep(1.0)
dy.signal.send_to(host,"gaitrunner_stop")
dy.signal.send_to(host,'stand_start')
print 'Gaitrunner is deactivated'
raw_input('Hit ENTER once the robot is at a standing posture...')
dy.signal.send_to(host,'sit_start')
time.sleep(2)
print 'Robot is sitting now.'
print 'Terminating the application'