示例#1
0
    def _update_proximity_sensors(self):
        robots = self.world.robots
        solids = self.world.solids()

        for robot in robots:
            sensors = robot.ir_sensors

            for sensor in sensors:
                dmin = float('inf')
                detector_line = sensor.detector_line

                for solid in solids:

                    if solid is not robot:  # assume that the sensor does not detect it's own robot
                        solid_polygon = solid.global_geometry

                        if geometrics.check_nearness(
                                detector_line, solid_polygon
                        ):  # don't bother testing objects that are not near each other
                            intersection_exists, intersection, d = geometrics.directed_line_segment_polygon_intersection(
                                detector_line, solid_polygon)

                            if intersection_exists and d < dmin:
                                dmin = d

                # if there is an intersection, update the sensor with the new delta value
                if dmin != float('inf'):
                    sensor.detect(dmin)
                else:
                    sensor.detect(None)
示例#2
0
  def _update_proximity_sensors( self ):
    robots = self.world.robots
    solids = self.world.solids()
    
    for robot in robots:
      sensors = robot.ir_sensors

      for sensor in sensors:
        dmin = float('inf')
        detector_line = sensor.detector_line

        for solid in solids:

          if solid is not robot:  # assume that the sensor does not detect it's own robot
            solid_polygon = solid.global_geometry
            
            if geometrics.check_nearness( detector_line, solid_polygon ): # don't bother testing objects that are not near each other
              intersection_exists, intersection, d = geometrics.directed_line_segment_polygon_intersection( detector_line, solid_polygon )
              
              if intersection_exists and d < dmin:
                dmin = d

        # if there is an intersection, update the sensor with the new delta value
        if dmin != float('inf'):
          sensor.detect( dmin )
        else:
          sensor.detect( None )
示例#3
0
  def _detect_collisions( self ):
    colliders = self.world.colliders()
    solids = self.world.solids()

    for collider in colliders:
      polygon1 = collider.global_geometry     # polygon1

      for solid in solids:
        if solid is not collider: # don't test an object against itself
          polygon2 = solid.global_geometry    # polygon2
          
          if geometrics.check_nearness( polygon1, polygon2 ): # don't bother testing objects that are not near each other
            if geometrics.convex_polygon_intersect_test( polygon1, polygon2 ):
              raise CollisionException()
示例#4
0
    def _detect_collisions(self):
        """
        Checks the world for any collisions between colliding objects (robots) and solid objects (obstacles)
        Raises a CollisionException if a collision is detected
        """
        colliders = self.world.colliders()
        solids = self.world.solids()

        for collider in colliders:
            polygon1 = collider.global_geometry  # polygon1

            for solid in solids:
                if solid is not collider:  # don't test an object against itself
                    polygon2 = solid.global_geometry  # polygon2

                    if geometrics.check_nearness(polygon1,
                                                 polygon2):  # don't bother testing objects that are not near each other
                        if geometrics.convex_polygon_intersect_test(polygon1, polygon2):
                            raise CollisionException()
示例#5
0
    def _update_proximity_sensors(self):
        """
        Update any proximity sensors that are in range of solid objects
        """
        robots = self.world.robots
        solids = self.world.solids()

        for robot in robots:
            sensors = robot.ir_sensors

            for sensor in sensors:
                dmin = float('inf')
                detector_line = sensor.detector_line
                solid_object = None
                for i, solid in enumerate(solids):

                    if solid is not robot:  # assume that the sensor does not detect it's own robot
                        solid_polygon = solid.global_geometry

                        if geometrics.check_nearness(detector_line,
                                                     solid_polygon):  # don't bother testing objects that are not near each other
                            intersection_exists, intersection, d = geometrics.directed_line_segment_polygon_intersection(
                                detector_line, solid_polygon)

                            if intersection_exists and d < dmin:
                                dmin = d
                                solid_object = solid

                # if there is an intersection, update the sensor with the new delta value
                if dmin != float('inf'):
                    sensor.detect(dmin)  # distance to the nearest solid
                else:
                    sensor.detect(None)

                # if a feature has been extracted from the environment, update the identifiers with the feature identifiers
                if dmin != float('inf') and type(solid_object) == FeaturePoint:
                    robot.feature_detector.detect(sensor.id, solid_object.id)
                else:
                    robot.feature_detector.detect(sensor.id, -1)