(self,
               pybullet_client,
               num_motors=MINITAUR_NUM_MOTORS,
               dofs_per_leg=MINITAUR_DOFS_PER_LEG,
               time_step=0.01,
               action_repeat=1,
               self_collision_enabled=False,
               motor_control_mode=robot_config.MotorControlMode.POSITION,
               motor_model_class=minitaur_motor.MotorModel,
               motor_kp=1.0,
               motor_kd=0.02,
               motor_torque_limits=None,
               pd_latency=0.0,
               control_latency=0.0,
               observation_noise_stdev=SENSOR_NOISE_STDDEV,
               motor_overheat_protection=False,
               motor_direction=MINITAUR_DEFAULT_MOTOR_DIRECTIONS,
               motor_offset=MINITAUR_DEFAULT_MOTOR_OFFSETS,
               on_rack=False,
               reset_at_current_position=False,
               sensors=None,
               enable_action_interpolation=False,
               enable_action_filter=False,
               reset_time=-1)
Constructs a minitaur and reset it to the initial states.

    Args:
      pybullet_client: The instance of BulletClient to manage different
        simulations.
      num_motors: The number of the motors on the robot.
      dofs_per_leg: The number of degrees of freedom for each leg.
      time_step: The time step of the simulation.
      action_repeat: The number of ApplyAction() for each control step.
      self_collision_enabled: Whether to enable self collision.
      motor_control_mode: Enum. Can either be POSITION, TORQUE, or HYBRID.
      motor_model_class: We can choose from simple pd model to more accureate DC
        motor models.
      motor_kp: proportional gain for the motors.
      motor_kd: derivative gain for the motors.
      motor_torque_limits: Torque limits for the motors. Can be a single float
        or a list of floats specifying different limits for different robots. If
        not provided, the default limit of the robot is used.
      pd_latency: The latency of the observations (in seconds) used to calculate
        PD control. On the real hardware, it is the latency between the
        microcontroller and the motor controller.
      control_latency: The latency of the observations (in second) used to
        calculate action. On the real hardware, it is the latency from the motor
        controller, the microcontroller to the host (Nvidia TX2).
      observation_noise_stdev: The standard deviation of a Gaussian noise model
        for the sensor. It should be an array for separate sensors in the
        following order [motor_angle, motor_velocity, motor_torque,
        base_roll_pitch_yaw, base_angular_velocity]
      motor_overheat_protection: Whether to shutdown the motor that has exerted
        large torque (OVERHEAT_SHUTDOWN_TORQUE) for an extended amount of time
        (OVERHEAT_SHUTDOWN_TIME). See ApplyAction() in minitaur.py for more
        details.
      motor_direction: A list of direction values, either 1 or -1, to compensate
        the axis difference of motors between the simulation and the real robot.
      motor_offset: A list of offset value for the motor angles. This is used to
        compensate the angle difference between the simulation and the real
        robot.
      on_rack: Whether to place the minitaur on rack. This is only used to debug
        the walking gait. In this mode, the minitaur's base is hanged midair so
        that its walking gait is clearer to visualize.
      reset_at_current_position: Whether to reset the minitaur at the current
        position and orientation. This is for simulating the reset behavior in
        the real world.
      sensors: a list of sensors that are attached to the robot.
      enable_action_interpolation: Whether to interpolate the current action
        with the previous action in order to produce smoother motions
      enable_action_filter: Boolean specifying if a lowpass filter should be
        used to smooth actions.
Constructs a minitaur and reset it to the initial states.
Constructs a minitaur and reset it to the initial states .
def __init__(self,
               pybullet_client,
               num_motors=MINITAUR_NUM_MOTORS,
               dofs_per_leg=MINITAUR_DOFS_PER_LEG,
               time_step=0.01,
               action_repeat=1,
               self_collision_enabled=False,
               motor_control_mode=robot_config.MotorControlMode.POSITION,
               motor_model_class=minitaur_motor.MotorModel,
               motor_kp=1.0,
               motor_kd=0.02,
               motor_torque_limits=None,
               pd_latency=0.0,
               control_latency=0.0,
               observation_noise_stdev=SENSOR_NOISE_STDDEV,
               motor_overheat_protection=False,
               motor_direction=MINITAUR_DEFAULT_MOTOR_DIRECTIONS,
               motor_offset=MINITAUR_DEFAULT_MOTOR_OFFSETS,
               on_rack=False,
               reset_at_current_position=False,
               sensors=None,
               enable_action_interpolation=False,
               enable_action_filter=False,
               reset_time=-1):
    """Constructs a minitaur and reset it to the initial states.

    Args:
      pybullet_client: The instance of BulletClient to manage different
        simulations.
      num_motors: The number of the motors on the robot.
      dofs_per_leg: The number of degrees of freedom for each leg.
      time_step: The time step of the simulation.
      action_repeat: The number of ApplyAction() for each control step.
      self_collision_enabled: Whether to enable self collision.
      motor_control_mode: Enum. Can either be POSITION, TORQUE, or HYBRID.
      motor_model_class: We can choose from simple pd model to more accureate DC
        motor models.
      motor_kp: proportional gain for the motors.
      motor_kd: derivative gain for the motors.
      motor_torque_limits: Torque limits for the motors. Can be a single float
        or a list of floats specifying different limits for different robots. If
        not provided, the default limit of the robot is used.
      pd_latency: The latency of the observations (in seconds) used to calculate
        PD control. On the real hardware, it is the latency between the
        microcontroller and the motor controller.
      control_latency: The latency of the observations (in second) used to
        calculate action. On the real hardware, it is the latency from the motor
        controller, the microcontroller to the host (Nvidia TX2).
      observation_noise_stdev: The standard deviation of a Gaussian noise model
        for the sensor. It should be an array for separate sensors in the
        following order [motor_angle, motor_velocity, motor_torque,
        base_roll_pitch_yaw, base_angular_velocity]
      motor_overheat_protection: Whether to shutdown the motor that has exerted
        large torque (OVERHEAT_SHUTDOWN_TORQUE) for an extended amount of time
        (OVERHEAT_SHUTDOWN_TIME). See ApplyAction() in minitaur.py for more
        details.
      motor_direction: A list of direction values, either 1 or -1, to compensate
        the axis difference of motors between the simulation and the real robot.
      motor_offset: A list of offset value for the motor angles. This is used to
        compensate the angle difference between the simulation and the real
        robot.
      on_rack: Whether to place the minitaur on rack. This is only used to debug
        the walking gait. In this mode, the minitaur's base is hanged midair so
        that its walking gait is clearer to visualize.
      reset_at_current_position: Whether to reset the minitaur at the current
        position and orientation. This is for simulating the reset behavior in
        the real world.
      sensors: a list of sensors that are attached to the robot.
      enable_action_interpolation: Whether to interpolate the current action
        with the previous action in order to produce smoother motions
      enable_action_filter: Boolean specifying if a lowpass filter should be
        used to smooth actions.
    """

    self.num_motors = num_motors
    self.num_legs = self.num_motors // dofs_per_leg
    self._pybullet_client = pybullet_client
    self._action_repeat = action_repeat
    self._self_collision_enabled = self_collision_enabled
    self._motor_direction = motor_direction
    self._motor_offset = motor_offset
    self._observed_motor_torques = np.zeros(self.num_motors)
    self._applied_motor_torques = np.zeros(self.num_motors)
    self._max_force = 3.5
    self._pd_latency = pd_latency
    self._control_latency = control_latency
    self._observation_noise_stdev = observation_noise_stdev
    self._observation_history = collections.deque(maxlen=100)
    self._control_observation = []
    self._chassis_link_ids = [-1]
    self._leg_link_ids = []
    self._motor_link_ids = []
    self._foot_link_ids = []

    self._motor_overheat_protection = motor_overheat_protection
    self._on_rack = on_rack
    self._reset_at_current_position = reset_at_current_position
    self.SetAllSensors(sensors if sensors is not None else list())
    self._is_safe = True

    self._enable_action_interpolation = enable_action_interpolation
    self._enable_action_filter = enable_action_filter
    self._last_action = None

    if not motor_model_class:
      raise ValueError("Must provide a motor model class!")

    if self._on_rack and self._reset_at_current_position:
      raise ValueError("on_rack and reset_at_current_position "
                       "cannot be enabled together")

    if isinstance(motor_kp, (collections.Sequence, np.ndarray)):
      self._motor_kps = np.asarray(motor_kp)
    else:
      self._motor_kps = np.full(num_motors, motor_kp)

    if isinstance(motor_kd, (collections.Sequence, np.ndarray)):
      self._motor_kds = np.asarray(motor_kd)
    else:
      self._motor_kds = np.full(num_motors, motor_kd)

    if isinstance(motor_torque_limits, (collections.Sequence, np.ndarray)):
      self._motor_torque_limits = np.asarray(motor_torque_limits)
    elif motor_torque_limits is None:
      self._motor_torque_limits = None
    else:
      self._motor_torque_limits = motor_torque_limits

    self._motor_control_mode = motor_control_mode
    self._motor_model = motor_model_class(
        kp=motor_kp,
        kd=motor_kd,
        torque_limits=self._motor_torque_limits,
        motor_control_mode=motor_control_mode)

    self.time_step = time_step
    self._step_counter = 0

    # This also includes the time spent during the Reset motion.
    self._state_action_counter = 0
    _, self._init_orientation_inv = self._pybullet_client.invertTransform(
        position=[0, 0, 0], orientation=self._GetDefaultInitOrientation())

    if self._enable_action_filter:
      self._action_filter = self._BuildActionFilter()

    # reset_time=-1.0 means skipping the reset motion.
    # See Reset for more details.
    self.Reset(reset_time=reset_time)
    self.ReceiveObservation()
def __init__ ( self , pybullet_client , num_motors = MINITAUR_NUM_MOTORS , dofs_per_leg = MINITAUR_DOFS_PER_LEG , time_step = 0.01 , action_repeat = 1 , self_collision_enabled = False , motor_control_mode = robot_config . MotorControlMode . POSITION , motor_model_class = minitaur_motor . MotorModel , motor_kp = 1.0 , motor_kd = 0.02 , motor_torque_limits = None , pd_latency = 0.0 , control_latency = 0.0 , observation_noise_stdev = SENSOR_NOISE_STDDEV , motor_overheat_protection = False , motor_direction = MINITAUR_DEFAULT_MOTOR_DIRECTIONS , motor_offset = MINITAUR_DEFAULT_MOTOR_OFFSETS , on_rack = False , reset_at_current_position = False , sensors = None , enable_action_interpolation = False , enable_action_filter = False , reset_time = - 1 ) : self . num_motors = num_motors self . num_legs = self . num_motors // dofs_per_leg self . _pybullet_client = pybullet_client self . _action_repeat = action_repeat self . _self_collision_enabled = self_collision_enabled self . _motor_direction = motor_direction self . _motor_offset = motor_offset self . _observed_motor_torques = np . zeros ( self . num_motors ) self . _applied_motor_torques = np . zeros ( self . num_motors ) self . _max_force = 3.5 self . _pd_latency = pd_latency self . _control_latency = control_latency self . _observation_noise_stdev = observation_noise_stdev self . _observation_history = collections . deque ( maxlen = 100 ) self . _control_observation = [ ] self . _chassis_link_ids = [ - 1 ] self . _leg_link_ids = [ ] self . _motor_link_ids = [ ] self . _foot_link_ids = [ ] self . _motor_overheat_protection = motor_overheat_protection self . _on_rack = on_rack self . _reset_at_current_position = reset_at_current_position self . SetAllSensors ( sensors if sensors is not None else list ( ) ) self . _is_safe = True self . _enable_action_interpolation = enable_action_interpolation self . _enable_action_filter = enable_action_filter self . _last_action = None if not motor_model_class : raise ValueError ( "Must provide a motor model class!" ) if self . _on_rack and self . _reset_at_current_position : raise ValueError ( "on_rack and reset_at_current_position " "cannot be enabled together" ) if isinstance ( motor_kp , ( collections . Sequence , np . ndarray ) ) : self . _motor_kps = np . asarray ( motor_kp ) else : self . _motor_kps = np . full ( num_motors , motor_kp ) if isinstance ( motor_kd , ( collections . Sequence , np . ndarray ) ) : self . _motor_kds = np . asarray ( motor_kd ) else : self . _motor_kds = np . full ( num_motors , motor_kd ) if isinstance ( motor_torque_limits , ( collections . Sequence , np . ndarray ) ) : self . _motor_torque_limits = np . asarray ( motor_torque_limits ) elif motor_torque_limits is None : self . _motor_torque_limits = None else : self . _motor_torque_limits = motor_torque_limits self . _motor_control_mode = motor_control_mode self . _motor_model = motor_model_class ( kp = motor_kp , kd = motor_kd , torque_limits = self . _motor_torque_limits , motor_control_mode = motor_control_mode ) self . time_step = time_step self . _step_counter = 0 # This also includes the time spent during the Reset motion. self . _state_action_counter = 0 _ , self . _init_orientation_inv = self . _pybullet_client . invertTransform ( position = [ 0 , 0 , 0 ] , orientation = self . _GetDefaultInitOrientation ( ) ) if self . _enable_action_filter : self . _action_filter = self . _BuildActionFilter ( ) # reset_time=-1.0 means skipping the reset motion. # See Reset for more details. self . Reset ( reset_time = reset_time ) self . ReceiveObservation ( )