Beispiel #1
0
  def decide(self):
    # Tell each robot to make the decion
    for repairer in self.repairers:
      self.repairers[repairer].decide()

      # Add location data for visualization of simulation
      loc = self.repairers[repairer].get_true_location()
      location = (loc[0], loc[1], 0) if helpers.compare(loc[2],0) else loc
      self.visualization_data += "{}:{}<>".format(repairer,str(
        helpers.round_tuple(location,3)))

      # Get color data based on what the robot is doing
      color = (1,0,1) if not self.repairers[repairer].repair_mode else (0,1,0)
      self.color_data += "{}:{}<>".format(repairer,str(color))

    self.visualization_data += "\n"
    self.color_data += "\n"
Beispiel #2
0
  def failed(self,program):
    '''
    Checks the entire SAP2000 structure for any possible structural errors.
    '''
    def get_max_moment(beam):
      '''
      Returns the largest moment along a beam
      '''
      results = program.model.Results.FrameForce(beam.name,0)
      if results[0] != 0:
        pdb.set_trace()
        return 0

      def total(index):
        '''
        Calculates the total moment for a specified index
        '''
        m22 = results[13][index]
        m33 = results[14][index]
        return math.sqrt(m22**2 + m33**2)

      # Calculate individual moments, and from them choose maximum
      moments = [total(i) for i in range(results[1])]
      max_val = max(moments)

      # Store max value along with beam name 
      if (beam.name,max_val) not in self.structure_data[-1]:
        self.structure_data[-1].append((beam.name,max_val))

      # Calculate gradiant color and store
      ratio = round(max_val/construction.beam['structure_check'],2)
      color = (ratio,round(max(1-ratio,0),2),0)
      try:
        self.color_data += "{}:{}<>".format(beam.name,str(color)) 
      except MemoryError:
        pass

      # Return maximum value
      return max_val

    def update_deflection(beam):
      '''
      Updates the deflection of the specified beam
      '''
      # Assert that the local axes are still the default
      results = program.model.FrameObj.GetLocalAxes(beam.name)
      if not (results[0] == 0 and results[1] == 0 and not results[2]):
        pdb.set_trace()
        return (0,0,0)

      # Obtain joint axes - these are, by default, the global axes
      axis_1,axis_2,axis_3 = beam.global_joint_axes()

      # Placed here for access to local axes
      def get_deflection(joint_name):
        '''
        Returns the correct displacement in absolute coordinates for the named
        joint
        '''
        # Get displacements
        results = program.model.Results.JointDisplAbs(joint_name,0)
        if results[0] != 0:
          pdb.set_trace()
          return (0,0,0)
        u1,u2,u3 = results[7][0], results[8][0], results[9][0]

        # Return the total deflection based on the local axes
        return helpers.sum_vectors(helpers.scale(u1,axis_1),helpers.sum_vectors(
          helpers.scale(u2,axis_2),helpers.scale(u3,axis_3)))

      return beam.update_deflection(get_deflection(beam.endpoint_names.i),
        get_deflection(beam.endpoint_names.j))

    bool_data = False
    seen = []
    data = ''
    for wall in self.model:
      for column in wall:
        for cell in column:
          for name,beam in cell.items():
            # Only if this is the first time we are collecting data 
            if name not in seen:
              moment = get_max_moment(beam)
              if moment > construction.beam['structure_check']:
                data += "Beam {} is structurally unstable with moment {}.\n".format(
                  name,str(moment))
                bool_data = True

              # Update deflection of beams :)
              if update_deflection(beam) and variables.deflection:
                # Add the deflection data for the beam if it's changed significantly
                # since last time we updated it
                try:
                  self.visualization_data += "{}:{}-{}<>".format(str(name),str(
                    helpers.round_tuple(beam.deflected_endpoints.i,3)),str(
                    helpers.round_tuple(beam.deflected_endpoints.j,3)))
                except MemoryError:
                  pdb.set_trace()

                # Update the previous endpoints
                beam.previous_write_endpoints = beam.deflected_endpoints

              seen.append(name)

    if not bool_data:
      return bool_data
    else:
      return data
Beispiel #3
0
  def add_beam(self,p1,p1_name,p2,p2_name,name):
    ''' 
    Function to add the name and endpoint combination of a beam
    to all of the boxes that contain it. Returns the number of boxes (which 
    should be at least 1)
    '''
    def addbeam(beam,p):
      '''
      Function to add an arbitrary beam to its respective box. Returns number of
      boxes changed. Also takes care of finding intersecting beams to the added
      beam and adding the joints to both beams. Uses the point p (which should 
      be on the beam), to calculate the box it should be added to
      '''
      # Getting indeces
      xi,yi,zi = self.__get_indeces(p)

      # Getting the box and all of the other beams in the box
      try:
        box = self.model[xi][yi][zi]
      except IndexError:
        print ("Addbeam is incorrect. Accessing box not defined.")
        return False

      # Finding intersection points with other beams
      for key in box:
        point = helpers.intersection(box[key].endpoints, beam.endpoints)
        # If they intersect, add the joint to both beams
        if point != None:
          assert key == box[key].name
          if not beam.addjoint(point, box[key]):
            sys.exit("Could not add joint to {} at {}".format(beam.name,
              str(point)))
          if not box[key].addjoint(point, beam):
            sys.exit("Could not add joint to {} at {}".format(box[key].name,
              str(point)))

      # update the box
      self.model[xi][yi][zi] = box

      # Adding beam to boxes that contain it based on the point p.
      try:
        if beam.name in self.model[xi][yi][zi]:
          return 0
        else:
          self.model[xi][yi][zi][beam.name] = beam
          return 1
      except IndexError:
        raise OutofBox ("The coordinate {}, is not in the structure. Something\
          went wront in addpoint()".format(p))

    # Create the beam
    new_beam = Beam(name,(p1,p2),(p1_name,p2_name))

    # Add to all boxes it is located in
    total_boxes = 0
    try:
      for point in self.__path(p1, p2):
        total_boxes += addbeam(new_beam,point)
    except OutofBox as e:
      print (e)
      return False

    # If something went wrong, kill the program
    assert total_boxes > 0

    # If showing the visualization, add the cylinder to the structure
    if self.visualization:
      temp = cylinder(pos=p1,axis=helpers.make_vector(p1,p2),
        radius=variables.outside_diameter)
      temp.color = (0,1,1)

    # Safe visualization data
    self.visualization_data += "{}:{}-{}<>".format(str(new_beam.name),str(
      helpers.round_tuple(p1,3)),str(helpers.round_tuple(p2,3)))

    # Add a beam to the structure count and increase height if necessary
    self.tubes += 1
    self.height = max(p1[2],p2[2],self.height)

    return total_boxes