-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
382 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,34 @@ | ||
package jtello.core.control; | ||
|
||
import jtello.core.movment.NotValidPositionException; | ||
|
||
/** | ||
* Direction for flying | ||
* @author Ariel | ||
* | ||
*/ | ||
public interface Fliying { | ||
|
||
boolean takeOff(); | ||
boolean takeOff() ; | ||
|
||
boolean land(); | ||
|
||
boolean left(int cm); | ||
boolean left(int cm)throws NotValidPositionException; | ||
|
||
boolean right(int cm); | ||
boolean right(int cm)throws NotValidPositionException; | ||
|
||
boolean forward(int cm); | ||
boolean forward(int cm)throws NotValidPositionException; | ||
|
||
boolean back(int cm); | ||
boolean back(int cm)throws NotValidPositionException; | ||
|
||
boolean up(int cm); | ||
boolean up(int cm)throws NotValidPositionException; | ||
|
||
boolean down(int cm); | ||
boolean down(int cm)throws NotValidPositionException; | ||
|
||
boolean rotateRight(int deg); | ||
|
||
boolean rotateLeft(int deg); | ||
|
||
boolean flipForward(); | ||
boolean flipForward() throws NotValidPositionException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package jtello.core.movment; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import jtello.core.control.Fliying; | ||
|
||
/** | ||
* Track the drone position, allow validating the next position with | ||
* <code>SandboxValidator</code> | ||
* | ||
* @author Ariel | ||
* | ||
*/ | ||
public class FlightPosition implements Fliying { | ||
|
||
private final Fliying fliying; | ||
|
||
private Position position; | ||
|
||
private List<SandboxValidator> sandboxValidators = new ArrayList<SandboxValidator>(); | ||
|
||
public FlightPosition(Fliying fliying) { | ||
this.position = new Position(); | ||
this.fliying = fliying; | ||
} | ||
|
||
public Position getPosition() { | ||
return position; | ||
} | ||
|
||
public void addSandboxValidator(SandboxValidator sandboxValidator) { | ||
sandboxValidators.add(sandboxValidator); | ||
} | ||
|
||
void validatetMove(Position nextPosition) throws NotValidPositionException { | ||
for (SandboxValidator validator : sandboxValidators) { | ||
validator.newPosition(nextPosition); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean takeOff() { | ||
boolean result = fliying.takeOff(); | ||
if (result) { | ||
position.moveZ(50); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean land() { | ||
boolean result = fliying.land(); | ||
if (result) { | ||
this.position = new Position(); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean left(int cm) throws NotValidPositionException { | ||
validatetMove(position.clone().moveX(-cm)); | ||
boolean result = fliying.left(cm); | ||
if (result) | ||
position.moveX(-cm); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean right(int cm) throws NotValidPositionException { | ||
validatetMove(position.clone().moveX(cm)); | ||
boolean result = fliying.right(cm); | ||
if (result) | ||
position.moveX(cm); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean forward(int cm) throws NotValidPositionException { | ||
validatetMove(position.clone().moveY(cm)); | ||
boolean result = fliying.forward(cm); | ||
if (result) | ||
position.moveY(cm); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean back(int cm) throws NotValidPositionException { | ||
validatetMove(position.clone().moveY(-cm)); | ||
boolean result = fliying.back(cm); | ||
if (result) | ||
position.moveY(-cm); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean up(int cm) throws NotValidPositionException { | ||
validatetMove(position.clone().moveZ(cm)); | ||
boolean result = fliying.up(cm); | ||
if (result) | ||
position.moveZ(cm); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean down(int cm) throws NotValidPositionException { | ||
validatetMove(position.clone().moveZ(-cm)); | ||
boolean result = fliying.down(cm); | ||
if (result) | ||
position.moveZ(-cm); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean rotateRight(int deg) { | ||
boolean result = fliying.rotateRight(deg); | ||
if (result) | ||
position.rotate(deg); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean rotateLeft(int deg) { | ||
boolean result = fliying.rotateLeft(deg); | ||
if (result) | ||
position.rotate(-deg); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean flipForward() throws NotValidPositionException { | ||
validatetMove(position.clone().moveY(30)); | ||
boolean result = fliying.flipForward(); | ||
if (result) | ||
position.moveY(30); | ||
return result; | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/jtello/core/movment/NotValidPositionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package jtello.core.movment; | ||
|
||
/** | ||
* The position is not valid | ||
* @author Ariel | ||
* | ||
*/ | ||
public class NotValidPositionException extends Exception { | ||
|
||
private static final long serialVersionUID = -7126774839714087672L; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package jtello.core.movment; | ||
|
||
import javafx.geometry.Point3D; | ||
|
||
/** | ||
* An estimation of the drone location | ||
* @author Ariel | ||
* | ||
*/ | ||
public class Position { | ||
|
||
// in cm | ||
private Point3D location = new Point3D(0, 0, 0); | ||
|
||
// 0-359 | ||
private double direction = 0; | ||
|
||
public Position moveX(double value) { | ||
double x = Math.cos(Math.toRadians(direction))*value; | ||
location = location.add(x, 0, 0); | ||
double y = Math.sin(Math.toRadians(direction))*value; | ||
location = location.add(0, y, 0); | ||
return this; | ||
} | ||
|
||
public Position moveY(double value) { | ||
double x = Math.sin(Math.toRadians(direction))*value; | ||
location = location.add(x, 0, 0); | ||
double y = Math.cos(Math.toRadians(direction))*value; | ||
location = location.add(0, y, 0); | ||
return this; | ||
} | ||
|
||
public Position moveZ(double value) { | ||
location = location.add(0, 0, value); | ||
return this; | ||
} | ||
|
||
public Position rotate(double value) { | ||
direction += value; | ||
direction = direction % 360; | ||
return this; | ||
} | ||
|
||
public Point3D getLocation() { | ||
return location; | ||
} | ||
|
||
public Position clone() { | ||
Position clone = new Position(); | ||
clone.direction=direction; | ||
clone.location=new Point3D(location.getX(), location.getY(), location.getZ()); | ||
return clone; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Position [location=" + location + ", direction=" + direction + "]"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package jtello.core.movment; | ||
|
||
/** | ||
* Callback interface to validate that drone location | ||
* @author Ariel | ||
* | ||
*/ | ||
public interface SandboxValidator { | ||
|
||
/** | ||
* @param position the next position the drone will fly to. | ||
* @return true if valid and the drone can move to the new position; | ||
*/ | ||
public boolean newPosition(Position position) throws NotValidPositionException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.