Created
February 7, 2017 20:10
-
-
Save talobin/4c47d1784d49d7cc3ff0aa88e495673e to your computer and use it in GitHub Desktop.
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
@Action(GimbalKeys.ROTATE) | |
public void rotate(InnerCallback callback, final Rotation rotation) { | |
if (rotation == null) { | |
CallbackUtils.onFailure(callback, DJIGimbalError.COMMON_PARAM_ILLEGAL); | |
return; | |
} | |
if (rotation.getMode() == null) { | |
callback.onFails(DJIError.COMMON_PARAM_ILLEGAL); | |
return; | |
} | |
if ((rotation.getPitch() != Rotation.NO_ROTATION && !gimbalCapability.get(CapabilityKey.ADJUST_PITCH).isSuppported()) | |
|| | |
(rotation.getRoll() != Rotation.NO_ROTATION && !gimbalCapability.get(CapabilityKey.ADJUST_ROLL).isSuppported()) | |
|| | |
(rotation.getYaw() != Rotation.NO_ROTATION && !gimbalCapability.get(CapabilityKey.ADJUST_YAW).isSuppported())) { | |
callback.onFails(DJIError.COMMON_PARAM_ILLEGAL); | |
return; | |
} | |
if (rotation.getMode() == RotationMode.ABSOLUTE_ANGLE || rotation.getMode() == RotationMode.RELATIVE_ANGLE) { | |
double time = rotation.getTime(); | |
if (time > 25.5) time = 25.5; | |
if (time < 0.1) time = 0.1; | |
DataGimbalAbsAngleControl absAngleControl = DataGimbalAbsAngleControl.getInstance().setControlMode(true); | |
absAngleControl.setPitch((short) 0); | |
absAngleControl.setRoll((short) 0); | |
absAngleControl.setYaw((short) 0); | |
//pitch | |
if (rotation.getPitch() != Rotation.NO_ROTATION ) { | |
if (rotation.getMode() == RotationMode.ABSOLUTE_ANGLE) { | |
short needSetPitch; | |
float angle = rotation.getPitch(); | |
if (angle < getMinValueFromCapability(ADJUST_PITCH).intValue() || angle > getMaxValueFromCapability( | |
ADJUST_PITCH).intValue()) { | |
if (null != callback) callback.onFails(DJIError.COMMON_PARAM_ILLEGAL); | |
return; | |
} | |
needSetPitch = (short) (angle * 10); | |
absAngleControl.setPitch(needSetPitch); | |
absAngleControl.setPitchInvalid(false); | |
absAngleControl.setControlMode(true); //ABSOLUTE_ANGLE | |
} else if (rotation.getMode() == RotationMode.RELATIVE_ANGLE) { | |
short needSetPitch; | |
float angle = rotation.getPitch(); | |
needSetPitch = (short) (angle * 10); | |
absAngleControl.setPitch(needSetPitch); | |
absAngleControl.setPitchInvalid(false); | |
absAngleControl.setControlMode(false); //RELATIVE_ANGLE | |
} | |
} else { | |
absAngleControl.setPitchInvalid(true); | |
} | |
//resetGimbalAbsAnglControl(absAngleControl); | |
//roll | |
if (rotation.getRoll() != Rotation.NO_ROTATION ) { | |
if (rotation.getMode() == RotationMode.ABSOLUTE_ANGLE) { | |
short needSetRoll; | |
float angle = rotation.getRoll(); | |
if (angle < getMinValueFromCapability(CapabilityKey.ADJUST_ROLL).intValue() | |
|| angle > getMaxValueFromCapability(CapabilityKey.ADJUST_ROLL).intValue()) { | |
if (null != callback) callback.onFails(DJIError.COMMON_PARAM_ILLEGAL); | |
return; | |
} | |
needSetRoll = (short) (angle * 10); | |
absAngleControl.setRoll(needSetRoll); | |
absAngleControl.setRollInvalid(false); | |
absAngleControl.setControlMode(true); | |
} else if (rotation.getMode() == RotationMode.RELATIVE_ANGLE) { | |
short needSetRoll; | |
float angle = rotation.getRoll(); | |
needSetRoll = (short) (angle * 10); | |
absAngleControl.setRoll(needSetRoll); | |
absAngleControl.setRollInvalid(false); | |
absAngleControl.setControlMode(false); | |
} | |
} else { | |
absAngleControl.setRollInvalid(true); | |
} | |
// resetGimbalAbsAnglControl(absAngleControl); | |
//yaw | |
if (rotation.getYaw() != Rotation.NO_ROTATION ) { | |
if (rotation.getMode() == RotationMode.ABSOLUTE_ANGLE) { | |
short needSetYaw; | |
float angle = rotation.getYaw(); | |
if (angle < getMinValueFromCapability(CapabilityKey.ADJUST_YAW).intValue() | |
|| angle > getMaxValueFromCapability(CapabilityKey.ADJUST_YAW).intValue()) { | |
if (null != callback) { | |
callback.onFails(DJIError.COMMON_PARAM_ILLEGAL); | |
} | |
return; | |
} | |
needSetYaw = (short) (angle * 10); | |
absAngleControl.setYaw(needSetYaw); | |
absAngleControl.setYawInvalid(false); | |
absAngleControl.setControlMode(true); | |
} else if (rotation.getMode() == RotationMode.RELATIVE_ANGLE) { | |
short needSetYaw; | |
float angle = rotation.getYaw(); | |
needSetYaw = (short) (angle * 10); | |
absAngleControl.setYaw(needSetYaw); | |
absAngleControl.setYawInvalid(false); | |
absAngleControl.setControlMode(false); | |
} | |
} else { | |
absAngleControl.setYawInvalid(true); | |
} | |
absAngleControl.setOvertime((int) (time * 10f)); | |
absAngleControl.start(); | |
CallbackUtils.onSuccess(callback, null); | |
return; | |
} | |
if (rotation.getMode() == RotationMode.SPEED) { | |
DataGimbalSpeedControl.getInstance() | |
.setPitch((int) rotation.getPitch() * 10); | |
DataGimbalSpeedControl.getInstance() | |
.setRoll((int) rotation.getRoll() * 10); | |
DataGimbalSpeedControl.getInstance() | |
.setYaw((int) rotation.getYaw() * 10); | |
DataGimbalSpeedControl.getInstance() | |
.setPermission(rotation.getPitch() != 0 | |
|| rotation.getRoll() != 0 | |
|| rotation.getYaw() != 0); | |
DataGimbalSpeedControl.getInstance().start(); | |
CallbackUtils.onSuccess(callback, null); | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment