虚拟摇杆原地旋转无人机后,云台的yaw没有随着无人机yaw改变
已完成我们在开发全景功能,是用虚拟摇杆旋转无人机45度后,云台的朝向还是之前的朝向,没有随着无人机改变而改变。需要怎么设置,不改变云台的yaw,使云台跟随无人机旋转呢,这是我设置云台的代码
gimbal.setMode(GimbalMode.YAW_FOLLOW, new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
}
});
gimbal.rotate(new Rotation.Builder().pitch(listPitch.get(i))
.mode(RotationMode.ABSOLUTE_ANGLE)
.time(1.25)
.build(), new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError error) {
}
});
-
云台应该是始终跟随机头的,你打遥控器摇杆是否跟随?你在官方app里是否跟随呢?你设置的云台模式也没问题,且你设置的云台转向也只是Pitch轴的,不应该会影响yaw才对。最好能提供个视频给我。 Link:https://pan-sec.djicorp.com/s/nDkAqGnM9pBocHj dji123 -
视频我这边已经上传给您了, 除了云台的问题外,还有一个问题就是我们是飞机旋转45度拍摄三张照片,旋转完后,飞机会漂一段距离,有的时候会漂几十公分,有的时候会飘一米多。整个的全景功能的代码,我贴在下面吧,您看一下是哪里设置的不对还是需要增加其他的设置呢
private FlightController flightController;
private double height, lat, lng;
private int pitch, yaw, newYaw;
private List<Integer> listPitch = new ArrayList<>();
private Timer timer, timeMission;
private int i = 0;
private void excutePanorama() {
i= 0;
Camera camera = DroneModelFactory.getAircraftCamera();
camera.setMode(SettingsDefinitions.CameraMode.SHOOT_PHOTO, new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
}
});
DroneModelFactory.getAircraftCamera().startShootPhoto(new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
}
});
flightController = DroneModelFactory.getAircraftInstance().getFlightController();
flightController.setStateCallback(new FlightControllerState.Callback() {
@Override
public void onUpdate(@NonNull FlightControllerState flightControllerState) {
height = flightControllerState.getAircraftLocation().getAltitude();
lat = flightControllerState.getAircraftLocation().getLatitude();
lng = flightControllerState.getAircraftLocation().getLongitude();
yaw = (int) Math.rint(flightControllerState.getAttitude().yaw);
Log.i("qqqqq全景", yaw + "偏航角");
}
});
Gimbal gimbal = DroneModelFactory.getAircraftInstance().getGimbal();
gimbal.setStateCallback(new GimbalState.Callback() {
@Override
public void onUpdate(@NonNull GimbalState gimbalState) {
pitch = (int) gimbalState.getAttitudeInDegrees().getPitch();
}
});
listPitch.add(-18);
listPitch.add(15);
listPitch.add(-55);
listPitch.add(-90);
listPitch.add(-55);
listPitch.add(-18);
listPitch.add(15);
listPitch.add(15);
listPitch.add(-18);
listPitch.add(-55);
listPitch.add(-55);
listPitch.add(-18);
listPitch.add(15);
listPitch.add(15);
listPitch.add(-18);
listPitch.add(-55);
listPitch.add(-55);
listPitch.add(-18);
listPitch.add(15);
listPitch.add(15);
listPitch.add(-18);
listPitch.add(-55);
listPitch.add(-55);
listPitch.add(-18);
listPitch.add(15);
flightController.setVirtualStickModeEnabled(true, new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
if (djiError != null) {
Log.i("qqqqq开启虚拟", djiError.toString());
}
}
});
flightController.setFlightOrientationMode(FlightOrientationMode.AIRCRAFT_HEADING, new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
}
});
gimbal.setMode(GimbalMode.FPV, new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
}
});
flightController.setYawControlMode(YawControlMode.ANGLE);
//设置虚拟操纵杆垂直控制器是否改变飞机的高度或垂直速度,将虚拟操纵杆垂直控制值设置为垂直速度
flightController.setVerticalControlMode(VerticalControlMode.VELOCITY);
// for (int i = 0; i <listPitch.size() ; i++) {
timeMission = new Timer();
//
timeMission.schedule(new TimerTask() {
@Override
public void run() {
if (i == 4 || i == 7 || i == 10 || i == 13 || i == 16 || i == 19 || i == 22) {
if (yaw > 0) {
newYaw = yaw + 45;
if (newYaw > 180) {
newYaw = 180 - newYaw;
}
} else {
newYaw = yaw - 45;
if (newYaw < -180) {
newYaw = 180 + newYaw;
}
}
Log.i("qqqq循环", "执行了" + newYaw);
FlightControlData flightControlDat = new FlightControlData(0, 0, newYaw, 0);
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
flightController.sendVirtualStickFlightControlData(flightControlDat,
new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
Log.i("qqqqq虚拟", "当前偏航角:" + yaw + " " + "指定偏航角" + newYaw);
if (djiError != null) {
Log.i("qqqqq虚拟错误", djiError.getDescription());
}
if (yaw == newYaw) {
timer.cancel();
}
}
});
}
}, 0, 50);
gimbal.rotate(new Rotation.Builder().pitch(listPitch.get(i))
.mode(RotationMode.ABSOLUTE_ANGLE)
.time(1.25)
.build(), new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError error) {
}
});
Log.i("qqqqq循环", i + "");
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(3000); //线程休眠10秒执行
DroneModelFactory.getAircraftCamera().startShootPhoto(new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
}
});
i++;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
if (i == 24) {
ToastUtil.showToast("全景拍摄完成");
timeMission.cancel();
flightController.setVirtualStickModeEnabled(false, new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
if (djiError != null) {
Log.i("qqqqq关闭虚拟", djiError.toString());
}
}
});
return;
}
} else {
gimbal.rotate(new Rotation.Builder().pitch(listPitch.get(i))
.mode(RotationMode.ABSOLUTE_ANGLE)
.time(1.25)
.build(), new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError error) {
}
});
Log.i("qqqqq循环", i + "");
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(3000); //线程休眠10秒执行
DroneModelFactory.getAircraftCamera().startShootPhoto(new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
}
});
i++;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
if (i == 24) {
ToastUtil.showToast("全景拍摄完成");
timeMission.cancel();
flightController.setVirtualStickModeEnabled(false, new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
if (djiError != null) {
Log.i("qqqqq关闭虚拟", djiError.toString());
}
}
});
return;
}
}
}
}, 0, 5000);
} -
尊敬的开发者, 您好,感谢您联系DJI 大疆创新。 首先我建议你SDK的命令最好放在回调上一个命令的回调里,不然你会第二个SDK命令可能会发送在接收到第一个SDK命令回调前,会报错。解决漂移的问题就是开启setVirtualStickAdvancedModeEnabled。你的云台模式设置成YAW_FOLLOW就可以。设置云台的角度的时候选择pitch(X),yaw(0),roll(0)。在以上这些设置还是云台不跟随的话,回退到4.16版本再试试。我现在不能确定是不是4.16.1的一个改动引发了这个bug。 感谢您的邮件,祝您生活愉快! Best Regards, DJI 大疆创新SDK技术支持
请先登录再写评论。
评论
3 条评论