The createModel Method

The model consists of a block on a translational joint (axis along global z-axis) with four forces acting on it. The first is the disturbance force. The remaining three represent the PID controller (these could be combined into one force; but for the sake of clarity has been split into three).

def createModel(self):
    """
    Create the model
    """
      self.model = Model(output = "PID Controller Design")
      units  = Units()
      grav   = Accgrav()

      # Ground Part
      ground = Part(ground=True)
      self.oxyz = oxyz = Marker(label="Global CS", body = ground)

      # Reference Marker
      self.rm = rm = Marker(body = ground, qp = [0,0,2])

      # Design Variables
      self.dv_kp = kp = Dv(label='Kp', b=self.kp, blimit=[0,1])
      self.dv_ki = ki = Dv(label='Ki', b=self.ki, blimit=[0,1])
      self.dv_kd = kd = Dv(label='Kd', b=self.kd, blimit=[0,1])

      # Block
      self.block = Part(
          mass = self.mass , 
          ip = [10,10,10], 
          qg = [0,0,2])

      # Block cm
      self.block.cm = cm = Marker (label='block cm', body=self.block), 

      block_geo = Box(cm=cm, x=1, y=1, z=1)

      # Translational Joints
      joint1 = Joint(type='TRANSLATIONAL', i=cm, j=oxyz)

      # The Disturbance Force
      expr = 'STEP(TIME, 10, {}, 10.1, 0)'.format(self.force_mag)
      self.force = self.model.force = Sforce( 
          i        = cm,
          j        = oxyz,
          type     = 'TRANSLATION',
          function = expr,
          )

      # We add a PID controller on it
      expr = '-DVAL({Kp})*VZ({I},{J})'.format(Kp=kp.id, I=cm.id, J=rm.id)
      P_term = Sforce(
          i        = cm, 
          j        = oxyz, 
          type     = 'TRANSLATION',
          function = expr,
          )

      expr = '-DVAL({Ki})*DZ({I},{J})'.format(Ki=ki.id, I=cm.id, J=rm.id)
      I_term = Sforce(
          i        = cm, 
          j        = oxyz,
          type     = 'TRANSLATION',
          function = expr,
         )

      expr = '-DVAL({Kd})*ACCZ({I},{J})'.format(Kd=kd.id, I=cm.id, J=rm.id)
      D_term = Sforce(
          i        = cm, 
          j        = oxyz,
          type     = 'TRANSLATION',
          function = expr,
         )

    return  self.model