我一直在研究这个万向节代码,现在试图让我的 DJI Matrice 100 无人机上的相机万向节在每次按下按钮方向时略微移动。我尝试使用 for 和 while 循环来增加角度值,但它似乎只读取循环内的角度而不是循环本身。有没有人对如何让云台在点击时增加角度有任何建议?这是云台旋转的代码。(注意:我正在测试的 for 循环行已被注释掉。最后测试了 while 循环。):
private void rotateGimbalToMin (Button button) {
DJIGimbal gimbal = getGimbalInstance();
if (gimbal == null){
return;
}
Object key = getCorrespondingKeyWithButton(button);
Number minValue = ((DJIParamMinMaxCapability)(gimbal.gimbalCapability().get(key))).getMin();
if (key == DJIGimbalCapabilityKey.AdjustPitch){ //down
//for(double anglex = 0; anglex >= -180;anglex+= -20) {
while(anglex != -180){
mPitchRotation.direction = DJIGimbalRotateDirection.Clockwise;
mPitchRotation.angle = -20; //TODO minValue.floatValue()
anglex+= -20;
}
}
if(key == DJIGimbalCapabilityKey.AdjustYaw){ //left
//for(double anglex = 0; anglex <= 180; anglex+=20) {//test for loop
while(anglex != 180){
mYawRotation.direction = DJIGimbalRotateDirection.Clockwise;
mYawRotation.angle = 20; //TODO minValue.floatValue()
anglex+=20;
}
}
sendRotateGimbalCommand();
}
private void rotateGimbalToMax(Button button) {
DJIGimbal gimbal = getGimbalInstance();
if (gimbal == null){
return;
}
Object key = getCorrespondingKeyWithButton(button);
Number maxValue = ((DJIParamMinMaxCapability)(gimbal.gimbalCapability().get(key))).getMax();
if (key == DJIGimbalCapabilityKey.AdjustPitch){ //up
//for(double anglex = 0; anglex <= 40; anglex+=20) {//test for loop
while(anglex != 40){
mPitchRotation.direction = DJIGimbalRotateDirection.Clockwise;
mPitchRotation.angle = 10; //TODO maxValue.floatValue()
this.anglex+=10;
}
}
if(key == DJIGimbalCapabilityKey.AdjustYaw){ //right
//for(double anglex = 0; anglex >= -180; anglex+=-20) {
while(anglex != -180){
mYawRotation.direction = DJIGimbalRotateDirection.Clockwise;
mYawRotation.angle = -20; //TODO maxValue.floatValue()
anglex+= -20;
}
}
// if(key == DJIGimbalCapabilityKey.AdjustRoll){
// mRollRotation.direction = DJIGimbalRotateDirection.Clockwise;
// mRollRotation.angle = maxValue.floatValue();
// }
sendRotateGimbalCommand();
}
下面是 OnClick 代码:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_capture:{
captureAction();
break;
}
case R.id.btn_shoot_photo_mode:{
switchCameraMode(DJICameraSettingsDef.CameraMode.ShootPhoto);
break;
}
case R.id.btn_record_video_mode:{
switchCameraMode(DJICameraSettingsDef.CameraMode.RecordVideo);
break;
}
case R.id.btn_goLeft:{
rotateGimbalToMax((Button)v);
break;
}
case R.id.btn_goRight:{
rotateGimbalToMin((Button) v);
break;
}
case R.id.btn_goDown:{
rotateGimbalToMin((Button) v);
break;
}
case R.id.btn_goUp:{
rotateGimbalToMax((Button) v);
break;
}
case R.id.btn_reset:{
mPitchRotation.angle = 0;
mYawRotation.angle = 0;
default:
break;
}
}