(self,
                        motor_commands,
                        motor_angle,
                        motor_velocity,
                        true_motor_velocity,
                        motor_control_mode=None)
return self._convert_to_torque_from_pwm(pwm, true_motor_velocity)
Convert the commands (position control or pwm control) to torque.

    Args:
      motor_commands: The desired motor angle if the motor is in position
        control mode. The pwm signal if the motor is in torque control mode.
      motor_angle: The motor angle observed at the current time step. It is
        actually the true motor angle observed a few milliseconds ago (pd
        latency).
      motor_velocity: The motor velocity observed at the current time step, it
        is actually the true motor velocity a few milliseconds ago (pd latency).
      true_motor_velocity: The true motor velocity. The true velocity is used to
        compute back EMF voltage and viscous damping.
      motor_control_mode: A MotorControlMode enum.

    Returns:
      actual_torque: The torque that needs to be applied to the motor.
      observed_torque: The torque observed by the sensor.
Convert the commands (position control or pwm control) to torque.
Convert the commands ( position control or pwm control ) to torque .
def convert_to_torque(self,
                        motor_commands,
                        motor_angle,
                        motor_velocity,
                        true_motor_velocity,
                        motor_control_mode=None):
    """Convert the commands (position control or pwm control) to torque.

    Args:
      motor_commands: The desired motor angle if the motor is in position
        control mode. The pwm signal if the motor is in torque control mode.
      motor_angle: The motor angle observed at the current time step. It is
        actually the true motor angle observed a few milliseconds ago (pd
        latency).
      motor_velocity: The motor velocity observed at the current time step, it
        is actually the true motor velocity a few milliseconds ago (pd latency).
      true_motor_velocity: The true motor velocity. The true velocity is used to
        compute back EMF voltage and viscous damping.
      motor_control_mode: A MotorControlMode enum.

    Returns:
      actual_torque: The torque that needs to be applied to the motor.
      observed_torque: The torque observed by the sensor.
    """
    if not motor_control_mode:
      motor_control_mode = self._motor_control_mode

    if (motor_control_mode is robot_config.MotorControlMode.TORQUE) or (
        motor_control_mode is robot_config.MotorControlMode.HYBRID):
      raise ValueError("{} is not a supported motor control mode".format(
          motor_control_mode))

    kp = self._kp
    kd = self._kd

    if motor_control_mode is robot_config.MotorControlMode.PWM:
      # The following implements a safety controller that softly enforces the
      # joint angles to remain within safe region: If PD controller targeting
      # the positive (negative) joint limit outputs a negative (positive)
      # signal, the corresponding joint violates the joint constraint, so
      # we should add the PD output to motor_command to bring it back to the
      # safe region.
      pd_max = -1 * kp * (motor_angle -
                          MOTOR_POS_UB) - kd / 2. * motor_velocity
      pd_min = -1 * kp * (motor_angle -
                          MOTOR_POS_LB) - kd / 2. * motor_velocity
      pwm = motor_commands + np.minimum(pd_max, 0) + np.maximum(pd_min, 0)
    else:
      pwm = -1 * kp * (motor_angle - motor_commands) - kd * motor_velocity
    pwm = np.clip(pwm, -1.0, 1.0)
    return self._convert_to_torque_from_pwm(pwm, true_motor_velocity)
def convert_to_torque ( self , motor_commands , motor_angle , motor_velocity , true_motor_velocity , motor_control_mode = None ) : if not motor_control_mode : motor_control_mode = self . _motor_control_mode if ( motor_control_mode is robot_config . MotorControlMode . TORQUE ) or ( motor_control_mode is robot_config . MotorControlMode . HYBRID ) : raise ValueError ( "{} is not a supported motor control mode" . format ( motor_control_mode ) ) kp = self . _kp kd = self . _kd if motor_control_mode is robot_config . MotorControlMode . PWM : # The following implements a safety controller that softly enforces the # joint angles to remain within safe region: If PD controller targeting # the positive (negative) joint limit outputs a negative (positive) # signal, the corresponding joint violates the joint constraint, so # we should add the PD output to motor_command to bring it back to the # safe region. pd_max = - 1 * kp * ( motor_angle - MOTOR_POS_UB ) - kd / 2. * motor_velocity pd_min = - 1 * kp * ( motor_angle - MOTOR_POS_LB ) - kd / 2. * motor_velocity pwm = motor_commands + np . minimum ( pd_max , 0 ) + np . maximum ( pd_min , 0 ) else : pwm = - 1 * kp * ( motor_angle - motor_commands ) - kd * motor_velocity pwm = np . clip ( pwm , - 1.0 , 1.0 ) return self . _convert_to_torque_from_pwm ( pwm , true_motor_velocity )