Skip to content
Permalink
Browse files

Basic zRanger support

  • Loading branch information...
fredg02 committed Nov 2, 2017
1 parent 8cc20b4 commit 090498e35eb0e29b8bd30bb6aaceb8529ea48bf9
@@ -32,14 +32,15 @@
private String mGroup;
private String mName;

public ParamListener(String completeName) {
if (completeName.indexOf(".") == -1) {
throw new IllegalArgumentException("Complete name must include a '.' as separator between group and name.");
}
String[] split = completeName.split(".");
this.mGroup = split[0];
this.mName = split[1];
}
//FIXME
// public ParamListener(String completeName) {
// if (completeName.isEmpty() || !completeName.contains(".")) {
// throw new IllegalArgumentException("Complete name must include a '.' as separator between group and name.");
// }
// String[] split = completeName.split(".");
// this.mGroup = split[0];
// this.mName = split[1];
// }

public ParamListener(String group, String name) {
this.mGroup = group;
@@ -42,8 +42,8 @@

protected static final int MAX_THRUST = 65000;
protected static final float MIN_TARGET_HEIGHT = 0.1f; // 10cm
protected static final float MAX_TARGET_HEIGHT = 1.2f; // 120cm
protected static final float INITIAL_TARGET_HEIGHT = 0.4f; // 40cm
protected static final float MAX_TARGET_HEIGHT = 1.0f; // 100cm
public static final float INITIAL_TARGET_HEIGHT = 0.4f; // 40cm
protected float targetHeight = INITIAL_TARGET_HEIGHT;

public AbstractController(Controls controls, MainActivity activity) {
@@ -118,6 +118,10 @@ public float getTargetHeight() {
return targetHeight;
}

public void setTargetHeight(float th) {
this.targetHeight = th;
}

/**
* Disabled by default
*
@@ -254,16 +254,25 @@ public float getThrustAbsolute() {
return 0;
}

/**
* Used for height hold with zRanger sensor
*
* @return
*/
public float getTargetHeight() {
float thrust = getThrust();
float vz = (thrust - 32767) / 32767;
targetHeight += vz;
if (targetHeight > MAX_TARGET_HEIGHT) {
targetHeight = MAX_TARGET_HEIGHT;
} else if (targetHeight < MIN_TARGET_HEIGHT) {
targetHeight = MIN_TARGET_HEIGHT;

if (isHover()) {
float vz = thrust / 10000;
targetHeight += vz;
if (targetHeight > MAX_TARGET_HEIGHT) {
targetHeight = MAX_TARGET_HEIGHT;
} else if (targetHeight < MIN_TARGET_HEIGHT) {
targetHeight = MIN_TARGET_HEIGHT;
}
return targetHeight;
}
return targetHeight;
return 0;
}

}
@@ -21,6 +21,7 @@
import se.bitcraze.crazyflie.lib.toc.Toc;
import se.bitcraze.crazyflie.lib.toc.VariableType;
import se.bitcraze.crazyfliecontrol.console.ConsoleListener;
import se.bitcraze.crazyfliecontrol.controller.AbstractController;
import se.bitcraze.crazyfliecontrol.controller.GamepadController;

public class MainPresenter {
@@ -142,7 +143,7 @@ public void updated(String name, Number value) {

private void checkForZRanger() {
//this should return true when either a zRanger or a flow deck is connected
mCrazyflie.getParam().addParamListener(new ParamListener("deck.bcZRanger") {
mCrazyflie.getParam().addParamListener(new ParamListener("deck", "bcZRanger") {
@Override
public void updated(String name, Number value) {
isZrangerAvailable = mCrazyflie.getParam().getValue("deck.bcZRanger").intValue() == 1;
@@ -185,10 +186,9 @@ public void run() {
float pitch = mainActivity.getController().getPitch();
float yaw = mainActivity.getController().getYaw();
float thrustAbsolute = mainActivity.getController().getThrustAbsolute();
float targetHeight = mainActivity.getController().getTargetHeight();
boolean xmode = mainActivity.getControls().isXmode();

if (heightHold) {
float targetHeight = mainActivity.getController().getTargetHeight();
mCrazyflie.sendPacket(new ZDistancePacket(roll, pitch, yaw, targetHeight));
} else {
mCrazyflie.sendPacket(new CommanderPacket(roll, pitch, yaw, (char) thrustAbsolute, xmode));
@@ -277,6 +277,10 @@ public void enableAltHoldMode(boolean hover) {
if (mCrazyflie != null && mCrazyflie.getDriver() instanceof RadioDriver && mainActivity.getController() instanceof GamepadController) {
if (isZrangerAvailable) {
heightHold = hover;
// reset target height, when hover is deactivated
if (!hover) {
((GamepadController) mainActivity.getController()).setTargetHeight(AbstractController.INITIAL_TARGET_HEIGHT);
}
} else {
// Log.i(LOG_TAG, "flightmode.althold: getThrust(): " + mController.getThrustAbsolute());
mCrazyflie.setParamValue("flightmode.althold", hover ? 1 : 0);

0 comments on commit 090498e

Please sign in to comment.
You can’t perform that action at this time.