M100,RPi2,Onboard-SDK相机示例失败

时间:2017-11-15 05:28:41

标签: dji-sdk

v3.2的相机旋转由于某种原因停止了我的无人机工作,所以我决定更新到最新的固件。 在RPi2上运行Onboard-SDK v3.3作为Matrice 100的板载计算机。运行相机样本失败,云台速度部件移动相机但通过绝对相机控制移动根本没有移动相机。稍微修改了相机样品,使得万向节速度部分进一步向上移动并增加了额外的旋转。无人机和飞行控制器已更新至最新版本。有人有什么建议吗?

相关输出

ubuntu@ubuntu:~/Drone/Onboard-SDK/build/bin$ ./djiosdk-cameragimbal-

sample UserConfig.txt
Read App ID
User Configuration read successfully. 


STATUS/1 @ init, L37: Attempting to open device /dev/ttyUSB0 with baudrate 230400...

STATUS/1 @ init, L47: ...Serial started successfully.

STATUS/1 @ parseDroneVersionInfo, L569: Device Serial No. = ---------

STATUS/1 @ parseDroneVersionInfo, L571: Hardware = M100

STATUS/1 @ parseDroneVersionInfo, L572: Firmware = 3.1.10.0

STATUS/1 @ parseDroneVersionInfo, L575: Version CRC = 0xA6453AAC

STATUS/1 @ functionalSetUp, L125: Subscriber not supported!

STATUS/1 @ functionalSetUp, L163: MFIO not supported!

ERROR/1 @ functionalSetUp, L181: Hardware Sync not supported!

STATUS/1 @ activate, L969: version 0x3010A00

STATUS/1 @ activate, L982: Activation successful
| Available commands:                                            |
| [a] Exercise gimbal and camera control                         |
a
Please note that the gimbal yaw angle you see in the telemetry is w.r.t absolute North, and the accuracy depends on your magnetometer calibration.

Initial Gimbal rotation angle: [0, 0, -27.4]

Setting new Gimbal rotation angle to [0,20,180] using incremental control:
New Gimbal rotation angle is [0 0 -27.4]

Gimbal Speed Description: 

Roll - unit 0.1 degrees/second input rate [-1800, 1800]
Pitch - unit 0.1 degrees/second input rate [-1800, 1800]
Yaw - unit 0.1 degrees/second input rate [-1800, 1800]

Setting Roll rate to 10, Pitch rate to 5, Yaw Rate to -20.
New Gimbal rotation angle is [15 30 6.8]

Ensure SD card is present.
Taking picture..
Check DJI GO App or SD card for a new picture.
Setting new Gimbal rotation angle to [0,-50, 0] using absolute control:
New Gimbal rotation angle is [15 30 6.8]

Ensure SD card is present.
Starting video..
Setting new Gimbal rotation angle to [0,-50, 0] using absolute control:
New Gimbal rotation angle is [15 29.9 6.8]

Resetting position...
New Gimbal rotation angle is [15 29.9 6.8]

Stopping video...
Check DJI GO App or SD card for a new video

以下是我尝试运行的示例代码

/*! @file camera_gimbal_sample.cpp
 *  @version 3.3
 *  @date Jun 05 2017
 *
 *  @brief
 *  Camera and Gimbal Control API usage in a Linux environment.
 *  Shows example usage of camera commands and gimbal position/speed control
 *  APIs
 *
 *  @copyright
 *  2017 DJI. All rights reserved.
 * */

#include "camera_gimbal_sample.hpp"

using namespace DJI::OSDK;
using namespace DJI::OSDK::Telemetry;

int
main(int argc, char** argv)
{

  // Setup the OSDK: Read config file, create vehicle, activate.
  Vehicle* vehicle = setupOSDK(argc, argv);
  if (vehicle == NULL)
  {
    std::cout << "Vehicle not initialized, exiting.\n";
    return -1;
  }

  // Display interactive prompt
  std::cout
    << "| Available commands:                                            |"
    << std::endl;
  std::cout
    << "| [a] Exercise gimbal and camera control                         |"
    << std::endl;
  char inputChar;
  std::cin >> inputChar;

  switch (inputChar)
  {
    case 'a':
      gimbalCameraControl(vehicle);
      break;
    default:
      break;
  }

  delete (vehicle);
  return 0;
}

bool
gimbalCameraControl(Vehicle* vehicle)
{

  int responseTimeout = 0;

  GimbalContainer              gimbal;
  RotationAngle                initialAngle;
  RotationAngle                currentAngle;
  DJI::OSDK::Gimbal::SpeedData gimbalSpeed;
  int                          pkgIndex;

  /*
   * Subscribe to gimbal data not supported in MAtrice 100
   */

  if (!vehicle->isM100() && !vehicle->isLegacyM600())
  {
    // Telemetry: Verify the subscription
    ACK::ErrorCode subscribeStatus;
    subscribeStatus = vehicle->subscribe->verify(responseTimeout);
    if (ACK::getError(subscribeStatus) != ACK::SUCCESS)
    {
      ACK::getErrorCodeMessage(subscribeStatus, __func__);
      return false;
    }

    // Telemetry: Subscribe to gimbal status and gimbal angle at freq 10 Hz
    pkgIndex                  = 0;
    int       freq            = 10;
    TopicName topicList10Hz[] = { TOPIC_GIMBAL_ANGLES, TOPIC_GIMBAL_STATUS };
    int       numTopic = sizeof(topicList10Hz) / sizeof(topicList10Hz[0]);
    bool      enableTimestamp = false;

    bool pkgStatus = vehicle->subscribe->initPackageFromTopicList(
      pkgIndex, numTopic, topicList10Hz, enableTimestamp, freq);
    if (!(pkgStatus))
    {
      return pkgStatus;
    }
    subscribeStatus =
      vehicle->subscribe->startPackage(pkgIndex, responseTimeout);
    if (ACK::getError(subscribeStatus) != ACK::SUCCESS)
    {
      ACK::getErrorCodeMessage(subscribeStatus, __func__);
      // Cleanup before return
      vehicle->subscribe->removePackage(pkgIndex, responseTimeout);
      return false;
    }
  }

  sleep(1);

  std::cout
    << "Please note that the gimbal yaw angle you see in the telemetry is "
       "w.r.t absolute North"
       ", and the accuracy depends on your magnetometer calibration.\n\n";

  // Get Gimbal initial values
  if (!vehicle->isM100() && !vehicle->isLegacyM600())
  {
    initialAngle.roll  = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().y;
    initialAngle.pitch = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().x;
    initialAngle.yaw   = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().z;
  }
  else
  {
    initialAngle.roll  = vehicle->broadcast->getGimbal().roll;
    initialAngle.pitch = vehicle->broadcast->getGimbal().pitch;
    initialAngle.yaw   = vehicle->broadcast->getGimbal().yaw;
  }

  std::cout << "Initial Gimbal rotation angle: [" << initialAngle.roll << ", "
            << initialAngle.pitch << ", " << initialAngle.yaw << "]\n\n";

  // Re-set Gimbal to initial values
  gimbal = GimbalContainer(0, 0, 0, 20, 1, initialAngle);
  doSetGimbalAngle(vehicle, &gimbal);

  std::cout << "Setting new Gimbal rotation angle to [0,20,180] using "
               "incremental control:\n";

  // Get current gimbal data to calc precision error in post processing
  if (!vehicle->isM100() && !vehicle->isLegacyM600())
  {
    currentAngle.roll  = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().y;
    currentAngle.pitch = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().x;
    currentAngle.yaw   = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().z;
  }
  else
  {
    currentAngle.roll  = vehicle->broadcast->getGimbal().roll;
    currentAngle.pitch = vehicle->broadcast->getGimbal().pitch;
    currentAngle.yaw   = vehicle->broadcast->getGimbal().yaw;
  }

  gimbal = GimbalContainer(0, 200, 1800, 20, 0, initialAngle, currentAngle);
  doSetGimbalAngle(vehicle, &gimbal);

  if (!vehicle->isM100() && !vehicle->isLegacyM600())
  {
    currentAngle.roll  = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().y;
    currentAngle.pitch = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().x;
    currentAngle.yaw   = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().z;
  }
  else
  {
    currentAngle.roll  = vehicle->broadcast->getGimbal().roll;
    currentAngle.pitch = vehicle->broadcast->getGimbal().pitch;
    currentAngle.yaw   = vehicle->broadcast->getGimbal().yaw;
  }

  displayResult(&currentAngle);

  // Speed control

  std::cout << "Gimbal Speed Description: \n\n"
            << "Roll - unit 0.1 degrees/second input rate [-1800, 1800]\n"
            << "Pitch - unit 0.1 degrees/second input rate [-1800, 1800]\n"
            << "Yaw - unit 0.1 degrees/second input rate [-1800, 1800]\n\n";

  std::cout << "Setting Roll rate to 10, Pitch rate to 5, Yaw Rate to -20.\n";
  gimbalSpeed.roll  = 1000;
  gimbalSpeed.pitch = 1000;
  gimbalSpeed.yaw   = -1500;

  int speedControlDurationMs = 4000;
  int incrementMs            = 100;
  for (int timer = 0; timer < speedControlDurationMs; timer += incrementMs)
  {
    vehicle->gimbal->setSpeed(&gimbalSpeed);
    usleep(incrementMs * 1000);
  }

  if (!vehicle->isM100() && !vehicle->isLegacyM600())
  {
    std::cout << "M100\n";
    currentAngle.roll  = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().y;
    currentAngle.pitch = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().x;
    currentAngle.yaw   = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().z;
  }
  else
  {
    currentAngle.roll  = vehicle->broadcast->getGimbal().roll;
    currentAngle.pitch = vehicle->broadcast->getGimbal().pitch;
    currentAngle.yaw   = vehicle->broadcast->getGimbal().yaw;
  }

  displayResult(&currentAngle);

  // Take picture
  std::cout << "Ensure SD card is present.\n";
  std::cout << "Taking picture..\n";
  vehicle->camera->shootPhoto();
  std::cout << "Check DJI GO App or SD card for a new picture.\n";

  std::cout << "Setting new Gimbal rotation angle to [0,-50, 0] using absolute "
               "control:\n";
  gimbal = GimbalContainer(0, -500, 0, 20, 1, initialAngle);
  doSetGimbalAngle(vehicle, &gimbal);

  if (!vehicle->isM100() && !vehicle->isLegacyM600())
  {
    currentAngle.roll  = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().y;
    currentAngle.pitch = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().x;
    currentAngle.yaw   = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().z;
  }
  else
  {
    currentAngle.roll  = vehicle->broadcast->getGimbal().roll;
    currentAngle.pitch = vehicle->broadcast->getGimbal().pitch;
    currentAngle.yaw   = vehicle->broadcast->getGimbal().yaw;
  }

  displayResult(&currentAngle);

  // Start video: We will keep the video doing for the duration of the speed
  // control.
  std::cout << "Ensure SD card is present.\n";
  std::cout << "Starting video..\n";
  vehicle->camera->videoStart();

  std::cout << "Setting new Gimbal rotation angle to [0,-50, 0] using absolute "
               "control:\n";
  gimbal = GimbalContainer(0, 500, 0, 20, 1, initialAngle);
  doSetGimbalAngle(vehicle, &gimbal);

  if (!vehicle->isM100() && !vehicle->isLegacyM600())
  {
    currentAngle.roll  = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().y;
    currentAngle.pitch = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().x;
    currentAngle.yaw   = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().z;
  }
  else
  {
    currentAngle.roll  = vehicle->broadcast->getGimbal().roll;
    currentAngle.pitch = vehicle->broadcast->getGimbal().pitch;
    currentAngle.yaw   = vehicle->broadcast->getGimbal().yaw;
  }

  displayResult(&currentAngle);


  // Reset the position
  std::cout << "Resetting position...\n";
  gimbal = GimbalContainer(0, 0, 0, 20, 1, initialAngle);
  doSetGimbalAngle(vehicle, &gimbal);

  if (!vehicle->isM100() && !vehicle->isLegacyM600())
  {
    currentAngle.roll  = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().y;
    currentAngle.pitch = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().x;
    currentAngle.yaw   = vehicle->subscribe->getValue<TOPIC_GIMBAL_ANGLES>().z;
  }
  else
  {
    currentAngle.roll  = vehicle->broadcast->getGimbal().roll;
    currentAngle.pitch = vehicle->broadcast->getGimbal().pitch;
    currentAngle.yaw   = vehicle->broadcast->getGimbal().yaw;
  }

  displayResult(&currentAngle);

  // Stop the video
  std::cout << "Stopping video...\n";
  vehicle->camera->videoStop();
  std::cout << "Check DJI GO App or SD card for a new video.\n";

  // Cleanup and exit gimbal sample
  if (!vehicle->isM100() && !vehicle->isLegacyM600())
  {
    ACK::ErrorCode ack =
      vehicle->subscribe->removePackage(pkgIndex, responseTimeout);
    if (ACK::getError(ack))
    {
      std::cout
        << "Error unsubscribing; please restart the drone/FC to get back "
           "to a clean state.\n";
    }
  }

  return true;
}

void
doSetGimbalAngle(Vehicle* vehicle, GimbalContainer* gimbal)
{
  DJI::OSDK::Gimbal::AngleData gimbalAngle;
  gimbalAngle.roll     = gimbal->roll;
  gimbalAngle.pitch    = gimbal->pitch;
  gimbalAngle.yaw      = gimbal->yaw;
  gimbalAngle.duration = gimbal->duration;
  gimbalAngle.mode |= 0;
  gimbalAngle.mode |= gimbal->isAbsolute;
  gimbalAngle.mode |= gimbal->yaw_cmd_ignore << 1;
  gimbalAngle.mode |= gimbal->roll_cmd_ignore << 2;
  gimbalAngle.mode |= gimbal->pitch_cmd_ignore << 3;

  vehicle->gimbal->setAngle(&gimbalAngle);
  // Give time for gimbal to sync
  sleep(4);
}

void
displayResult(RotationAngle* currentAngle)
{
  std::cout << "New Gimbal rotation angle is [";
  std::cout << currentAngle->roll << " ";
  std::cout << currentAngle->pitch << " ";
  std::cout << currentAngle->yaw;
  std::cout << "]\n\n";
}

0 个答案:

没有答案