Aircraft stops responding to joystick API
Hi
I wrote an app to control the drone via keyboard in simulation and after multiple calls to setJoystickCommand and joystickAction the aircraft stops responding to commands and can only be brought back by restarting the simulation. Any ideas?
Here's the code for a better idea
FlightController::JoystickMode joystickMode = {
FlightController::HorizontalLogic::HORIZONTAL_VELOCITY,
FlightController::VerticalLogic::VERTICAL_VELOCITY,
FlightController::YawLogic::YAW_RATE,
FlightController::HorizontalCoordinate::HORIZONTAL_BODY,
FlightController::StableMode::STABLE_ENABLE,
};
// Swithc to manual control by user
bool exit_flag = false;
// initscr();
// timeout(-1);
// noecho();
float speed = 20;
vehicle->flightController->setJoystickMode(joystickMode);
while (!exit_flag) {
auto c = getchar();
switch (c) {
case 'y': {
auto err_code =
vehicle->flightController->obtainJoystickCtrlAuthoritySync(timeout);
if (err_code != ErrorCode::FlightControllerErr::SetControlParam::
ObtainJoystickCtrlAuthoritySuccess) {
DERROR("Failed to obtain joystick control authority");
exit(EXIT_FAILURE);
}
break;
}
case 'r': {
auto err_code =
vehicle->flightController->releaseJoystickCtrlAuthoritySync(
timeout);
if (err_code != ErrorCode::FlightControllerErr::SetControlParam::
ReleaseJoystickCtrlAuthoritySuccess) {
DERROR("Failed to release joystick control authority");
exit(EXIT_FAILURE);
}
break;
}
case 't': {
vehicle->flightController->turnOnMotorsSync(10);
break;
}
case 'w': {
// vehicle->flightController->setJoystickMode(joystickMode);
vehicle->flightController->setJoystickCommand({speed, 0, 0, 0});
vehicle->flightController->joystickAction();
break;
}
case 's': {
// vehicle->flightController->setJoystickMode(joystickMode);
vehicle->flightController->setJoystickCommand({-speed, 0, 0, 0});
vehicle->flightController->joystickAction();
break;
}
case 'd': {
// vehicle->flightController->setJoysstickMode(joystickMode);
vehicle->flightController->setJoystickCommand({0, +speed, 0, 0});
vehicle->flightController->joystickAction();
break;
}
case 'a': {
// vehicle->flightController->setJoystickMode(joystickMode);
vehicle->flightController->setJoystickCommand({0, -speed, 0, 0});
vehicle->flightController->joystickAction();
break;
}
case 'c': {
auto err_code = vehicle->flightController->startConfirmLandingSync(10);
break;
}
case 'q': {
// vehicle->flightController->setJoystickMode(joystickMode);
vehicle->flightController->setJoystickCommand({0, 0, +speed, 0});
vehicle->flightController->joystickAction();
break;
}
case 'z': {
// vehicle->flightController->setJoystickMode(joystickMode);
vehicle->flightController->setJoystickCommand({0, 0, -speed, 0});
vehicle->flightController->joystickAction();
break;
}
case 'l': {
vehicle->flightController->startLandingSync(10);
break;
}
case 'f': {
vehicle->flightController->startForceLandingSync(10);
break;
}
case 'e': {
endwin();
exit_flag = true;
break;
}
case 'm': {
vehicle->flightController->turnOffMotorsSync(10);
break;
}
case 'k': {
vehicle->flightController->cancelLandingSync(10);
break;
}
case 'p': {
vehicle->flightController->killSwitch(
FlightController::KillSwitch::ENABLE, 10, "You should have paid!");
break;
}
case 'o': {
vehicle->flightController->killSwitch(
FlightController::KillSwitch::DISABLE, 10, "You should have paid!");
break;
}
}
}
Agent comment from kyle.cai in Zendesk ticket #67046:
Dear developer ,
Thank you for contacting DJI.
It is recommended to confirm that the OSDK continues to send the joystick command during the operation. Once the sending stops, the drone will hover.In addition, when the simulator stops responding, you can use the remote control to test whether it can be controlled.
Thank you for your understanding and support, hope you have a nice day.
Best Regards,
DJI SDK Support Team
°°°