(max_time=_MAX_TIME_SECONDS)
Runs the locomotion controller example.
Runs the locomotion controller example.
Runs the locomotion controller example .
def _run_example(max_time=_MAX_TIME_SECONDS):
  """Runs the locomotion controller example."""
  
  #recording video requires ffmpeg in the path
  record_video = False
  if record_video:
    p = pybullet
    p.connect(p.GUI, options="--width=1280 --height=720 --mp4=\"test.mp4\" --mp4fps=100")
    p.configureDebugVisualizer(p.COV_ENABLE_SINGLE_STEP_RENDERING,1)
  else:
     p = bullet_client.BulletClient(connection_mode=pybullet.GUI)    
         
  
  p.configureDebugVisualizer(p.COV_ENABLE_GUI,0)
  p.configureDebugVisualizer(p.COV_ENABLE_RENDERING,0)
  
  p.setAdditionalSearchPath(pd.getDataPath())
  
  num_bullet_solver_iterations = 30

  p.setPhysicsEngineParameter(numSolverIterations=num_bullet_solver_iterations)
  
  
  p.setPhysicsEngineParameter(enableConeFriction=0)
  p.setPhysicsEngineParameter(numSolverIterations=30)
  simulation_time_step = 0.001

  p.setTimeStep(simulation_time_step)
 
  p.setGravity(0, 0, -9.8)
  p.setPhysicsEngineParameter(enableConeFriction=0)
  p.setAdditionalSearchPath(pd.getDataPath())
  
  #random.seed(10)
  #p.configureDebugVisualizer(p.COV_ENABLE_RENDERING,0)
  heightPerturbationRange = 0.06
  
  plane = True
  if plane:
    p.loadURDF("plane.urdf")
    #planeShape = p.createCollisionShape(shapeType = p.GEOM_PLANE)
    #ground_id  = p.createMultiBody(0, planeShape)
  else:
    numHeightfieldRows = 256
    numHeightfieldColumns = 256
    heightfieldData = [0]*numHeightfieldRows*numHeightfieldColumns 
    for j in range (int(numHeightfieldColumns/2)):
      for i in range (int(numHeightfieldRows/2) ):
        height = random.uniform(0,heightPerturbationRange)
        heightfieldData[2*i+2*j*numHeightfieldRows]=height
        heightfieldData[2*i+1+2*j*numHeightfieldRows]=height
        heightfieldData[2*i+(2*j+1)*numHeightfieldRows]=height
        heightfieldData[2*i+1+(2*j+1)*numHeightfieldRows]=height
    
    terrainShape = p.createCollisionShape(shapeType = p.GEOM_HEIGHTFIELD, meshScale=[.05,.05,1], heightfieldTextureScaling=(numHeightfieldRows-1)/2, heightfieldData=heightfieldData, numHeightfieldRows=numHeightfieldRows, numHeightfieldColumns=numHeightfieldColumns)
    ground_id  = p.createMultiBody(0, terrainShape)

  #p.resetBasePositionAndOrientation(ground_id,[0,0,0], [0,0,0,1])
  
  #p.changeDynamics(ground_id, -1, lateralFriction=1.0)
  
  robot_uid = p.loadURDF(robot_sim.URDF_NAME, robot_sim.START_POS)

  robot = robot_sim.SimpleRobot(p, robot_uid, simulation_time_step=simulation_time_step)
  
  controller = _setup_controller(robot)
  controller.reset()
  
  p.configureDebugVisualizer(p.COV_ENABLE_RENDERING,1)
  #while p.isConnected():
  #  pos,orn = p.getBasePositionAndOrientation(robot_uid)
  #  print("pos=",pos)
  #  p.stepSimulation()
  #  time.sleep(1./240)  
  current_time = robot.GetTimeSinceReset()
  #logId = p.startStateLogging(p.STATE_LOGGING_PROFILE_TIMINGS, "mpc.json")
  
  while current_time < max_time:
    #pos,orn = p.getBasePositionAndOrientation(robot_uid)
    #print("pos=",pos, " orn=",orn)
    p.submitProfileTiming("loop")
    
    # Updates the controller behavior parameters.
    lin_speed, ang_speed = _generate_example_linear_angular_speed(current_time)
    #lin_speed, ang_speed = (0., 0., 0.), 0.
    _update_controller_params(controller, lin_speed, ang_speed)

    # Needed before every call to get_action().
    controller.update()
    hybrid_action, info = controller.get_action()
    
    robot.Step(hybrid_action)
    
    if record_video:
      p.configureDebugVisualizer(p.COV_ENABLE_SINGLE_STEP_RENDERING,1)

    #time.sleep(0.003)
    current_time = robot.GetTimeSinceReset()
    p.submitProfileTiming()
def _run_example ( max_time = _MAX_TIME_SECONDS ) : #recording video requires ffmpeg in the path record_video = False if record_video : p = pybullet p . connect ( p . GUI , options = "--width=1280 --height=720 --mp4=\"test.mp4\" --mp4fps=100" ) p . configureDebugVisualizer ( p . COV_ENABLE_SINGLE_STEP_RENDERING , 1 ) else : p = bullet_client . BulletClient ( connection_mode = pybullet . GUI ) p . configureDebugVisualizer ( p . COV_ENABLE_GUI , 0 ) p . configureDebugVisualizer ( p . COV_ENABLE_RENDERING , 0 ) p . setAdditionalSearchPath ( pd . getDataPath ( ) ) num_bullet_solver_iterations = 30 p . setPhysicsEngineParameter ( numSolverIterations = num_bullet_solver_iterations ) p . setPhysicsEngineParameter ( enableConeFriction = 0 ) p . setPhysicsEngineParameter ( numSolverIterations = 30 ) simulation_time_step = 0.001 p . setTimeStep ( simulation_time_step ) p . setGravity ( 0 , 0 , - 9.8 ) p . setPhysicsEngineParameter ( enableConeFriction = 0 ) p . setAdditionalSearchPath ( pd . getDataPath ( ) ) #random.seed(10) #p.configureDebugVisualizer(p.COV_ENABLE_RENDERING,0) heightPerturbationRange = 0.06 plane = True if plane : p . loadURDF ( "plane.urdf" ) #planeShape = p.createCollisionShape(shapeType = p.GEOM_PLANE) #ground_id  = p.createMultiBody(0, planeShape) else : numHeightfieldRows = 256 numHeightfieldColumns = 256 heightfieldData = [ 0 ] * numHeightfieldRows * numHeightfieldColumns for j in range ( int ( numHeightfieldColumns / 2 ) ) : for i in range ( int ( numHeightfieldRows / 2 ) ) : height = random . uniform ( 0 , heightPerturbationRange ) heightfieldData [ 2 * i + 2 * j * numHeightfieldRows ] = height heightfieldData [ 2 * i + 1 + 2 * j * numHeightfieldRows ] = height heightfieldData [ 2 * i + ( 2 * j + 1 ) * numHeightfieldRows ] = height heightfieldData [ 2 * i + 1 + ( 2 * j + 1 ) * numHeightfieldRows ] = height terrainShape = p . createCollisionShape ( shapeType = p . GEOM_HEIGHTFIELD , meshScale = [ .05 , .05 , 1 ] , heightfieldTextureScaling = ( numHeightfieldRows - 1 ) / 2 , heightfieldData = heightfieldData , numHeightfieldRows = numHeightfieldRows , numHeightfieldColumns = numHeightfieldColumns ) ground_id = p . createMultiBody ( 0 , terrainShape ) #p.resetBasePositionAndOrientation(ground_id,[0,0,0], [0,0,0,1]) #p.changeDynamics(ground_id, -1, lateralFriction=1.0) robot_uid = p . loadURDF ( robot_sim . URDF_NAME , robot_sim . START_POS ) robot = robot_sim . SimpleRobot ( p , robot_uid , simulation_time_step = simulation_time_step ) controller = _setup_controller ( robot ) controller . reset ( ) p . configureDebugVisualizer ( p . COV_ENABLE_RENDERING , 1 ) #while p.isConnected(): #  pos,orn = p.getBasePositionAndOrientation(robot_uid) #  print("pos=",pos) #  p.stepSimulation() #  time.sleep(1./240)   current_time = robot . GetTimeSinceReset ( ) #logId = p.startStateLogging(p.STATE_LOGGING_PROFILE_TIMINGS, "mpc.json") while current_time < max_time : #pos,orn = p.getBasePositionAndOrientation(robot_uid) #print("pos=",pos, " orn=",orn) p . submitProfileTiming ( "loop" ) # Updates the controller behavior parameters. lin_speed , ang_speed = _generate_example_linear_angular_speed ( current_time ) #lin_speed, ang_speed = (0., 0., 0.), 0. _update_controller_params ( controller , lin_speed , ang_speed ) # Needed before every call to get_action(). controller . update ( ) hybrid_action , info = controller . get_action ( ) robot . Step ( hybrid_action ) if record_video : p . configureDebugVisualizer ( p . COV_ENABLE_SINGLE_STEP_RENDERING , 1 ) #time.sleep(0.003) current_time = robot . GetTimeSinceReset ( ) p . submitProfileTiming ( )