diff --git a/src/main/java/org/jointheleague/jcodrone/Flight.java b/src/main/java/org/jointheleague/jcodrone/Flight.java index d1c1635..ba41117 100644 --- a/src/main/java/org/jointheleague/jcodrone/Flight.java +++ b/src/main/java/org/jointheleague/jcodrone/Flight.java @@ -48,14 +48,14 @@ public static void stop(CoDrone coDrone) throws MessageNotSentException { sendFlightEvent(coDrone, FlightEvent.STOP); } - public static void flyDirect(CoDrone coDrone, DirectControl control) throws MessageNotSentException { + public static void flyDirect(CoDrone coDrone, DirectControl control) { Control message = new Control( control.getRoll(), control.getPitch(), control.getYaw(), control.getThrottle() ); - coDrone.sendMessageWait(message); + coDrone.sendMessage(message); } private static void sendInFlightEvent(CoDrone coDrone, FlightEvent event) throws MessageNotSentException { diff --git a/src/main/java/org/jointheleague/jcodrone/LightModeBuilder.java b/src/main/java/org/jointheleague/jcodrone/LightModeBuilder.java index c61d77b..d8dfc88 100644 --- a/src/main/java/org/jointheleague/jcodrone/LightModeBuilder.java +++ b/src/main/java/org/jointheleague/jcodrone/LightModeBuilder.java @@ -44,7 +44,7 @@ public LightModeBuilder setColor(Color color) { log.warn("Value of colors is being overridden by setColor for light mode."); } this.color = color; - this.colorsSet = true; + this.colorSet = true; return this; } diff --git a/src/main/java/org/jointheleague/jcodrone/examples/DomDrone.java b/src/main/java/org/jointheleague/jcodrone/examples/DomDrone.java new file mode 100644 index 0000000..e2fda3c --- /dev/null +++ b/src/main/java/org/jointheleague/jcodrone/examples/DomDrone.java @@ -0,0 +1,50 @@ +package org.jointheleague.jcodrone.examples; + +import org.jointheleague.jcodrone.CoDrone; +import org.jointheleague.jcodrone.CoDroneNotFoundException; +import org.jointheleague.jcodrone.LightModeBuilder; +import org.jointheleague.jcodrone.MessageNotSentException; +import org.jointheleague.jcodrone.protocol.light.LightMode; +import org.jointheleague.jcodrone.protocol.light.LightModeDrone; + +public class DomDrone { + + public static final int TIME_UNIT = 250; + + public static void main(String args[]) { + try (CoDrone drone = new CoDrone()) { + drone.connect(); +// Thread.sleep(2000); +// LightMode mode= new LightModeBuilder().setColor("BLUE").setMode(LightModeDrone.EYE_HOLD).build(); +// drone.lightMode(mode); +// Thread.sleep(2000); +// mode= new LightModeBuilder().setColor("orange").setMode(LightModeDrone.ARM_NONE).build(); +// drone.lightMode(mode); +// Thread.sleep(2000); + drone.land(); + Thread.sleep(2000); + + String pattern = "...---..."; + for (byte a : pattern.getBytes()) { + int interval = a == '.' ? TIME_UNIT : 3 * TIME_UNIT; + System.out.format("%c %d", a, interval); + LightMode mode2 = new LightModeBuilder() + .setColor("magenta") + .setMode(LightModeDrone.EYE_HOLD) + .build(); + drone.lightMode(mode2); + Thread.sleep(interval); + mode2 = new LightModeBuilder() + .setColor("magenta") + .setMode(LightModeDrone.EYE_NONE) + .build(); + drone.lightMode(mode2); + Thread.sleep(TIME_UNIT); + } + Thread.sleep(2000); + drone.land(); + } catch (CoDroneNotFoundException | InterruptedException | MessageNotSentException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/org/jointheleague/jcodrone/TestPorts.java b/src/main/java/org/jointheleague/jcodrone/examples/TestPorts.java similarity index 72% rename from src/main/java/org/jointheleague/jcodrone/TestPorts.java rename to src/main/java/org/jointheleague/jcodrone/examples/TestPorts.java index 24665f9..d820dbf 100644 --- a/src/main/java/org/jointheleague/jcodrone/TestPorts.java +++ b/src/main/java/org/jointheleague/jcodrone/examples/TestPorts.java @@ -1,5 +1,8 @@ -package org.jointheleague.jcodrone; +package org.jointheleague.jcodrone.examples; +import org.jointheleague.jcodrone.CoDrone; +import org.jointheleague.jcodrone.DirectControl; +import org.jointheleague.jcodrone.LightModeBuilder; import org.jointheleague.jcodrone.protocol.light.LightMode; import org.jointheleague.jcodrone.protocol.light.LightModeDrone; @@ -10,8 +13,17 @@ public static void main(String argx[]) { Thread.sleep(2000); drone.flyDirect(new DirectControl((byte) 0, (byte) 0, (byte) 0, (byte) 0)); Thread.sleep(200); +// for(int i = 0; i < 1080; i++) { +// Color c = Color.getHSBColor(i / 360.0f, 1.0f, 1.0f); +// LightMode mode2 = new LightModeBuilder().setColor(c.getRed(), c.getGreen(), c.getBlue()).setMode(LightModeDrone.EYE_HOLD).build(); +// drone.lightMode(mode2); +// Thread.sleep(60); +// } drone.takeoff(); Thread.sleep(2000); + drone.flyDirect(new DirectControl((byte) 0, (byte) 0, (byte) 0, 30)); + Thread.sleep(2000); + for (int i = 0; i < 3; i++) { LightMode mode = new LightModeBuilder().setColor("BLUE").setInterval(5).setMode(LightModeDrone.EYE_HOLD).build(); drone.lightMode(mode); @@ -21,7 +33,7 @@ public static void main(String argx[]) { mode = new LightModeBuilder().setColor("RED").setInterval(5).setMode(LightModeDrone.EYE_HOLD).build(); drone.lightMode(mode); Thread.sleep(100); - drone.flyDirect(new DirectControl((byte) 0, (byte) 0, (byte) -55, -20)); + drone.flyDirect(new DirectControl((byte) 0, (byte) 0, (byte) -55, -15)); Thread.sleep(2000); } drone.flyDirect(new DirectControl((byte) 0, (byte) 0, (byte) 0, (byte) 0));