public List<MissionItem> createDronie(Coord2D start, Coord2D end) { final int startAltitude = 4; final int roiDistance = -8; Coord2D slowDownPoint = GeoTools.pointAlongTheLine(start, end, 5); double defaultSpeed = myDrone.getSpeed().getSpeedParameter(); if (defaultSpeed == -1) { defaultSpeed = 5; } List<MissionItem> dronieItems = new ArrayList<MissionItem>(); dronieItems.add(new TakeoffImpl(this, startAltitude)); dronieItems.add( new RegionOfInterestImpl( this, new Coord3D(GeoTools.pointAlongTheLine(start, end, roiDistance), (1.0)))); dronieItems.add( new WaypointImpl( this, new Coord3D(end, (startAltitude + GeoTools.getDistance(start, end) / 2.0)))); dronieItems.add( new WaypointImpl( this, new Coord3D( slowDownPoint, (startAltitude + GeoTools.getDistance(start, slowDownPoint) / 2.0)))); dronieItems.add(new ChangeSpeedImpl(this, 1.0)); dronieItems.add(new WaypointImpl(this, new Coord3D(start, startAltitude))); dronieItems.add(new ChangeSpeedImpl(this, defaultSpeed)); dronieItems.add(new LandImpl(this, start)); return dronieItems; }
public double getDistanceFromLastWaypoint(SpatialCoordItem waypoint) throws IllegalArgumentException { int i = items.indexOf(waypoint); if (i > 0) { MissionItem previous = items.get(i - 1); if (previous instanceof SpatialCoordItem) { return GeoTools.getDistance( waypoint.getCoordinate(), ((SpatialCoordItem) previous).getCoordinate()); } } throw new IllegalArgumentException("Last waypoint doesn't have a coordinate"); }