Skip to content

Commit

Permalink
Merge branch 'release/v1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rocboronat committed Feb 5, 2016
2 parents e8912ac + 7130962 commit 53e9303
Show file tree
Hide file tree
Showing 41 changed files with 990 additions and 148 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "com.fewlaps.flone"
minSdkVersion 15
targetSdkVersion 23
versionCode 6
versionName "0.5 beta"
versionCode 7
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
lintOptions {
Expand Down Expand Up @@ -42,6 +42,7 @@ dependencies {
testCompile "org.mockito:mockito-core:1.9.5"
testCompile 'org.apache.maven:maven-ant-tasks:2.1.3'
testCompile "org.robolectric:robolectric:3.0-rc3"
testCompile 'org.assertj:assertj-core:1.7.0'

// @see https://google.github.io/android-testing-support-library/docs/espresso
// @see https://google.github.io/android-testing-support-library/downloads
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@
android:screenOrientation="portrait" />
<activity
android:name=".view.activity.FlyActivity"
android:launchMode="singleInstance"
android:screenOrientation="portrait" />
<activity
android:name=".view.activity.CalibrationActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".view.activity.PreferenceActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />

<service android:name=".service.DroneService" />
</application>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.fewlaps.flone;

/**
* A tool to get the pitch and yaw the user wants to send to the drone.
* <p/>
* Usually, users won't want to send a 2000 or a 1000, because it's a too high value. So,
* we'll have to map the input of the user to the bounds he previously set.
* <p/>
* A limit of 100 makes the min to be 1100 and the max to be 1900.
*/
public class DesiredPitchRollCalculator {

public static final int MID = 1500;

public static final int MIN_LIMIT = 0;
public static final int MAX_LIMIT = 500;

private int limit = 0;

public DesiredPitchRollCalculator(int limit) {
this.limit = limit;
}

public void setLimit(int limit) {
this.limit = limit;
}

public int getValue(int value) {
int absolute = getAbsolute(value);

int calculatedValue = map(absolute, MIN_LIMIT, MAX_LIMIT, MIN_LIMIT, MAX_LIMIT - limit);

if (value > MID) {
return MID + calculatedValue;
} else {
return MID - calculatedValue;
}
}

public int getAbsolute(int value) {
if (value > MID) {
return value - MID;
} else {
int absolute = value - MID;
return absolute * -1;
}
}

/**
* This is the common Arduino map() function, expressed in Java
* http://stackoverflow.com/questions/7505991/arduino-map-equivalent-function-in-java
*/
private int map(int x, int inMin, int inMax, int outMin, int outMax) {
return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
}
}
3 changes: 0 additions & 3 deletions app/src/main/java/com/fewlaps/flone/DesiredYawCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
/**
* A tool to get the yaw the user wants to send to the drone. The idea is that
* droneHeading and desiresHeading are values from -180 to 180.
*
* @author Roc Boronat (roc@fewlaps.com)
* @date 05/07/2015
*/
public class DesiredYawCalculator {
public double getYaw(double droneHeading, double phoneHeading) {
Expand Down
38 changes: 28 additions & 10 deletions app/src/main/java/com/fewlaps/flone/data/CalibrationDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,55 @@
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.fewlaps.flone.data.bean.DroneCalibrationData;
import com.fewlaps.flone.data.bean.PhoneCalibrationData;
import com.google.gson.Gson;

/**
* @author Roc Boronat (roc@fewlaps.com)
* @date 19/02/2015
*/
public class CalibrationDatabase {

private static final Gson GSON = new Gson();

private static final String PREF_PHONE_CALIBRATION = "prefPhoneCalibration";
private static final String PREF_DRONE_CALIBRATION = "prefDroneCalibration";

private static PhoneCalibrationData cachedData = null;
private static PhoneCalibrationData phoneCacheData = null;
private static DroneCalibrationData droneCacheData = null;

public static PhoneCalibrationData getPhoneCalibrationData(Context context) {
if (cachedData == null) {
if (phoneCacheData == null) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String value = preferences.getString(PREF_PHONE_CALIBRATION, null);
if (value != null) {
cachedData = GSON.fromJson(value, PhoneCalibrationData.class);
phoneCacheData = GSON.fromJson(value, PhoneCalibrationData.class);
} else {
cachedData = new PhoneCalibrationData();
phoneCacheData = new PhoneCalibrationData();
}
}
return cachedData;
return phoneCacheData;
}

public static void setPhoneCalibrationData(Context context, PhoneCalibrationData data) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
preferences.edit().putString(PREF_PHONE_CALIBRATION, GSON.toJson(data)).commit();
cachedData = data;
phoneCacheData = data;
}

public static DroneCalibrationData getDroneCalibrationData(Context context, String droneNickName) {
if (droneCacheData == null) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String value = preferences.getString(PREF_DRONE_CALIBRATION + droneNickName, null);
if (value != null) {
droneCacheData = GSON.fromJson(value, DroneCalibrationData.class);
} else {
droneCacheData = new DroneCalibrationData();
}
}
return droneCacheData;
}

public static void setDroneCalibrationData(Context context, String droneNickName, DroneCalibrationData data) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
preferences.edit().putString(PREF_DRONE_CALIBRATION + droneNickName, GSON.toJson(data)).commit();
droneCacheData = data;
}
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/fewlaps/flone/data/DefaultValues.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.fewlaps.flone.data;

public class DefaultValues {

public static final double DEFAULT_PHONE_PITCH_ROLL = 100;

public static final int DEFAULT_PITCH_ROLL_LIMIT = 300; //low = expert, high = beginner, min = 0, max = 500
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.fewlaps.flone.data.bean;

public class DroneCalibrationData {

private double headingDifference = 0;

public double getHeadingDifference() {
return headingDifference;
}

public void setHeadingDifference(double headingDifference) {
this.headingDifference = headingDifference;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package com.fewlaps.flone.data.bean;

/**
* @author Roc Boronat (roc@fewlaps.com)
* @date 26/05/2015
*/
import com.fewlaps.flone.data.DefaultValues;

public class PhoneCalibrationData {
public Double minPitch;
public Double maxPitch;
public Double minRoll;
public Double maxRoll;

private Double minPitch = DefaultValues.DEFAULT_PHONE_PITCH_ROLL * -1;
private Double maxPitch = DefaultValues.DEFAULT_PHONE_PITCH_ROLL;
private Double minRoll = DefaultValues.DEFAULT_PHONE_PITCH_ROLL * -1;
private Double maxRoll = DefaultValues.DEFAULT_PHONE_PITCH_ROLL;

private int limit = DefaultValues.DEFAULT_PITCH_ROLL_LIMIT;

public PhoneCalibrationData() {
minPitch = -50d;
maxPitch = 50d;
minRoll = -50d;
maxRoll = 50d;

}

public double getAverageMaxPitch() {
Expand All @@ -24,4 +22,12 @@ public double getAverageMaxPitch() {
public double getAverageMaxRoll() {
return ((minRoll * -1) + maxRoll) / 2;
}

public int getLimit() {
return limit;
}

public void setLimit(int limit) {
this.limit = limit;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.fewlaps.flone.io.bean;

public class CalibrateDroneAccelerometerRequest {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.fewlaps.flone.io.bean;

public class CalibrateDroneMagnetometerRequest {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.fewlaps.flone.io.bean;

public class CalibrationDataChangedEvent {

}
10 changes: 10 additions & 0 deletions app/src/main/java/com/fewlaps/flone/io/bean/DelayData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.fewlaps.flone.io.bean;

public class DelayData {

public int delay;

public DelayData(int delay) {
this.delay = delay;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public byte getId() {

public static byte ROLL = 0;
public static byte PITCH = 1;
public static byte YAW = 2;
public static byte THROTTLE = 3;
public static byte YAW = 3;
public static byte THROTTLE = 2;
public static byte AUX1 = 4;
public static byte AUX2 = 5;
public static byte AUX3 = 6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import android.util.Log;

import com.fewlaps.flone.io.communication.Communication;
import com.fewlaps.flone.io.bean.DroneSensorData;
import com.fewlaps.flone.io.communication.Communication;

import java.util.ArrayList;
import java.util.LinkedList;
Expand Down Expand Up @@ -229,7 +229,7 @@ public void evaluateCommand(byte cmd, int dataSize) {
setIs_ATTITUDE_received(true);
attitudeReceivedTime = System.currentTimeMillis();
// Log.d("aaa", "MSP_ATTITUDE: angx = " + angx + ",angy = " + angy + ",head = " + head);
sensorInformation.update(head, angy, angx);
sensorInformation.update(head - 180, angy, angx); //180 to work with Cleanfight
EventBus.getDefault().post(sensorInformation);
break;
case MSP_ALTITUDE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ public void setThrottle(Integer screenPosition) {
this.throttle = RCSignals.RC_MIN + chosenThrottle;
}

public void setThrottleAtMid() {
this.throttle = RCSignals.RC_MID;
}

public float getThrottleScreenPosition() {
return screenHeight - ((throttle - RCSignals.RC_MIN) * screenHeight / RCSignals.RC_GAP);
}

public int getThrottlePorcentage() {
return (throttle - RCSignals.RC_MIN) * 100 / RCSignals.RC_GAP;
}

public void setThrottleAtMid() {
this.throttle = RCSignals.RC_MID;
}

public void setThrottleAtZero() {
this.throttle = RCSignals.RC_MIN;
}
}
Loading

0 comments on commit 53e9303

Please sign in to comment.