def test_points_in_poly(): fence = [ (50.863862, 4.678861), (50.863613, 4.678992), (50.863613, 4.678625), (50.863809, 4.678590), (50.863862, 4.678861), ] assert Polygonal.points_in_poly(Polygonal.random_coordinates((50.863743, 4.678677), 0.000110, 200), fence) == False
def run(self): """Executes the geo-fencing behaviour, returning a message either (halt, do_nothing).""" if self.vehicle.mode.name != "BRAKE" and self.vehicle.mode.name != "ALT_HOLD" and self.vehicle.mode.name != "LAND" and self.vehicle.mode.name != "RTL": gps_precision_in_decimal_degrees = Polygonal.centimetersToDecimalDegrees(self.vehicle.gps_0.eph) probable_drone_locations = Polygonal.random_coordinates((self.vehicle.location.lat, self.vehicle.location.lon), gps_precision_in_decimal_degrees, self.precision) # Adaptive fence, predicts the location of the drone according to its velocity, after 1 second if self.adaptive_fence: def add_velocity(x): return (x[0] + self.vehicle.velocity[0], x[1] + self.vehicle.velocity[1]) probable_drone_locations = map(add_velocity, probable_drone_locations) if Polygonal.points_in_poly(probable_drone_locations, self.fence) is False: print "Broke circular fence." print self.vehicle.location print gps_precision_in_decimal_degrees return SafeBehaviour.SafeBehaviour.halt if self.vehicle.location.alt >= self.maximum_altitude or self.vehicle.location.alt <= self.minimum_altitude: print "Broke altitude geo-fence." print self.vehicle.location print gps_precision_in_decimal_degrees return SafeBehaviour.SafeBehaviour.halt return SafeBehaviour.SafeBehaviour.do_nothing # class BrakeCommand: # def __call__(self): # self.vehicle.mode = VehicleMode("BRAKE") # self.vehicle.flush() # # # class NullCommand: # def __call__(self): # pass