Skip to content

Commit

Permalink
Code Clean and Speed up
Browse files Browse the repository at this point in the history
  • Loading branch information
KlemenDEV committed Aug 21, 2014
1 parent c5e8bf0 commit af71bf2
Show file tree
Hide file tree
Showing 16 changed files with 594 additions and 643 deletions.
441 changes: 219 additions & 222 deletions src/com/muhavision/Main.java

Large diffs are not rendered by default.

37 changes: 22 additions & 15 deletions src/com/muhavision/SplashScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,45 @@
import javax.swing.JFrame;
import javax.swing.JLabel;

public class SplashScreen extends JFrame{
public class SplashScreen extends JFrame {

//Very nice loading screen
/**
*
*/
private static final long serialVersionUID = 1L;

public static void main(String[] args) {
new SplashScreen();
}

// Very nice loading screen
public SplashScreen() {

//Some graphic magic I don't want to know what it does.
// Some graphic magic I don't want to know what it does.
setUndecorated(true);
setSize(600, 200);
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
setLocation(dim.width/2-getSize().width/2,
dim.height/2-getSize().height/2);
setLocation(dim.width / 2 - getSize().width / 2, dim.height / 2
- getSize().height / 2);
add(new JLabel(new ImageIcon("./res/logo.png")));
setVisible(true);
for (int i = 0; i < 5; i++) {
setLocation(
(dim.width/2-getSize().width/2)+((int)(Math.random()*1000)-500),
(dim.height/2-getSize().height/2)+((int)(Math.random()*1000)-500));
(dim.width / 2 - getSize().width / 2)
+ ((int) (Math.random() * 1000) - 500),
(dim.height / 2 - getSize().height / 2)
+ ((int) (Math.random() * 1000) - 500));
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
setLocation(dim.width/2-getSize().width/2,
dim.height/2-getSize().height/2);
setLocation(dim.width / 2 - getSize().width / 2, dim.height / 2
- getSize().height / 2);
add(new JLabel(new ImageIcon("./res/logo.png")));
setVisible(false);
}

public static void main(String[] args) {
new SplashScreen();
}


}
//Done with graphics (for now).
// Done with graphics (for now).
31 changes: 16 additions & 15 deletions src/com/muhavision/control/DroneController.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,54 @@
import com.muhavision.pid.PID;

public class DroneController {

PID roll = new PID(1, 1, 0, 10, PID.Direction.NORMAL);

OpticalFlowCalculator calc = new OpticalFlowCalculator();

ARDrone drone = null;
NavData data = null;

public DroneController(final VisualRenderer visual) {
System.out.println("Drone controller loading...");
try {

drone = new ARDrone();
drone.connect();

drone.addImageListener(new BufferedImageVideoListener() {

@Override
public void imageReceived(BufferedImage image) {
QuadrantFlowSpeed speed = null;
EulerAngles angle = null;
if(visual.global_main.flightMode.getMode()==FlightMode.eMode.MUHA_MODE)

if (visual.global_main.flightMode.getMode() == FlightMode.eMode.MUHA_MODE)
speed = calc.getFlowData(image);
else if(visual.global_main.flightMode.getMode()==FlightMode.eMode.TAG_MODE)
angle = MarkerControl.getControlDataAndPictureDataBasedOnNavData(data);

else if (visual.global_main.flightMode.getMode() == FlightMode.eMode.TAG_MODE)
angle = MarkerControl
.getControlDataAndPictureDataBasedOnNavData(data);

visual.reloadDatas(image, speed, data, angle);
}
});

drone.addNavDataListener(new NavDataListener() {

@Override
public void navDataReceived(NavData fdata) {
data = fdata;
}
});

} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public ARDrone getDrone(){

public ARDrone getDrone() {
return drone;
}

Expand Down
8 changes: 4 additions & 4 deletions src/com/muhavision/control/EulerAngles.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
public class EulerAngles {

public float roll, pitch, yaw;

public int picX, picY;

public int dist;

public boolean hasAngles = false;

}
13 changes: 7 additions & 6 deletions src/com/muhavision/control/ExpoController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
*/
public class ExpoController {

//If it crashes it's because of this + mami ne dotikaj se.
public static double getExpo(int power){
if (power<0) return-(0.6 * Math.exp(-0.035*(double)power) - 0.6);
return 0.6 * Math.exp(0.035*(double)power) - 0.6;
}

// If it crashes it's because of this + mami ne dotikaj se.
public static double getExpo(int power) {
if (power < 0)
return -(0.6 * Math.exp(-0.035 * power) - 0.6);
return 0.6 * Math.exp(0.035 * power) - 0.6;
}

}
53 changes: 24 additions & 29 deletions src/com/muhavision/control/FlightMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,37 @@
*/
public class FlightMode {

public enum eMode {
public enum eMode {

NORMAL_MODE(0),
MUHA_MODE(1),
TAG_MODE(2);
NORMAL_MODE(0), MUHA_MODE(1), TAG_MODE(2);

int mode = 0;
int mode = 0;

eMode(int mode){
this.mode = mode;
}
eMode(int mode) {
this.mode = mode;
}

}

public static String getFlightModeName(eMode mode){
if(mode == eMode.NORMAL_MODE)
return "NORMAL";
if(mode == eMode.MUHA_MODE)
return "MUHA";
if(mode == eMode.TAG_MODE)
return "TAG";
return "UNKNOWN";
}
}

private eMode mode = eMode.NORMAL_MODE;

public eMode getMode(){
return mode;
}

public void setMode(eMode mode){
this.mode = mode;
mode.toString();
}
public static String getFlightModeName(eMode mode) {
if (mode == eMode.NORMAL_MODE)
return "NORMAL";
if (mode == eMode.MUHA_MODE)
return "MUHA";
if (mode == eMode.TAG_MODE)
return "TAG";
return "UNKNOWN";
}

private eMode mode = eMode.NORMAL_MODE;

public eMode getMode() {
return mode;
}

public void setMode(eMode mode) {
this.mode = mode;
mode.toString();
}

}
6 changes: 3 additions & 3 deletions src/com/muhavision/control/JoystickController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
public class JoystickController {

public static void readUSB() {
}
public static void readUSB() {

}

}
20 changes: 10 additions & 10 deletions src/com/muhavision/control/MarkerControl.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.muhavision.control;

import java.util.ArrayList;
import java.util.List;

import com.codeminders.ardrone.NavData;
import com.codeminders.ardrone.Point;
import com.codeminders.ardrone.VisionTag;

public class MarkerControl {

public static EulerAngles getControlDataAndPictureDataBasedOnNavData(NavData nav){

if(nav.isVisionEnabled()){
List<VisionTag> tags = (ArrayList<VisionTag>) nav.getVisionTags();
if(!tags.isEmpty()){
VisionTag tag = tags.get(0);
if(tag!=null){

public static EulerAngles getControlDataAndPictureDataBasedOnNavData(
NavData nav) {

if (nav.isVisionEnabled()) {
List<VisionTag> tags = nav.getVisionTags();
if (!tags.isEmpty()) {
VisionTag tag = tags.get(0);
if (tag != null) {
EulerAngles angles = new EulerAngles();
Point point = tag.getPosition();
angles.picX = point.getX();
Expand All @@ -26,7 +26,7 @@ public static EulerAngles getControlDataAndPictureDataBasedOnNavData(NavData nav
}
}
}

return new EulerAngles();
}

Expand Down
Loading

0 comments on commit af71bf2

Please sign in to comment.