DJI_VirtualRC.cpp
Go to the documentation of this file.
00001 
00013 #include "DJI_VirtualRC.h"
00014 
00015 using namespace DJI::onboardSDK;
00016 
00017 VirtualRC::VirtualRC(CoreAPI *ControlAPI)
00018 {
00019   api = ControlAPI;
00020   resetData();
00021 }
00022 
00023 void VirtualRC::setControl(bool enable, VirtualRC::CutOff cutoffType)
00024 {
00025   VirtualRCSetting setting;
00026   setting.cutoff = cutoffType;
00027   setting.enable = enable ? 1 : 0;
00028   api->send(0, encrypt, SET_VIRTUALRC, CODE_VIRTUALRC_SETTINGS, &setting, sizeof(setting));
00029 }
00030 
00031 void VirtualRC::sendData(VirtualRCData Data)
00032 {
00033   vrcData = Data; 
00035   api->send(0, encrypt, SET_VIRTUALRC, CODE_VIRTUALRC_DATA, &vrcData, sizeof(vrcData));
00036 }
00037 
00039 void VirtualRC::sendData()
00040 {
00041   api->send(0, encrypt, SET_VIRTUALRC, CODE_VIRTUALRC_DATA, &vrcData, sizeof(vrcData));
00042 }
00043 
00045 void VirtualRC::resetData()
00046 {
00047   vrcData.roll = 1024;
00048   vrcData.pitch = 1024;
00049   vrcData.throttle = 1024;
00050   vrcData.yaw = 1024;
00051   vrcData.gear = 1024;
00052   vrcData.reserved = 1024;
00053   vrcData.mode = 1024;
00054   vrcData.Channel_07 = 1024;
00055   vrcData.Channel_08 = 1024;
00056   vrcData.Channel_09 = 1024;
00057   vrcData.Channel_10 = 1024;
00058   vrcData.Channel_11 = 1024;
00059   vrcData.Channel_12 = 1024;
00060   vrcData.Channel_13 = 1024;
00061   vrcData.Channel_14 = 1024;
00062   vrcData.Channel_15 = 1024;
00063 }
00064 
00066 void VirtualRC::sendSafeModeData()
00067 {
00068   resetData();
00069   sendData();
00070 }
00071 
00072 void VirtualRC::neutralVRCSticks()
00073 {
00074   resetData();
00075   sendData();
00076 }
00077 
00079 RadioData VirtualRC::getRCData() const { return api->getBroadcastData().rc; }
00080 
00081 CoreAPI *VirtualRC::getApi() const { return api; }
00082 void VirtualRC::setApi(CoreAPI *value) { api = value; }
00083 
00084 VirtualRCData VirtualRC::getVRCData() const { return vrcData; }
00085 void VirtualRC::setVRCData(const VirtualRCData &value) 
00086 { 
00087   vrcData = value;         
00088 }
00089 
00090 bool VirtualRC::isVirtualRC() const
00091 {
00092   return api->getBroadcastData().ctrlInfo.vrcStatus == 0 ? false : true;
00093 }
00094 
00096 RadioData VirtualRC::toRadioData(VirtualRCData &vData)
00097 {
00098   RadioData rd;
00099   rd.gear = (vData.gear == 1324) ? -454 : -10000;
00100   rd.mode = (1024 - vData.mode ) * 10000 / 660;
00101   rd.pitch = (vData.pitch - 1024) * (10000) / 660;
00102   rd.roll = (vData.roll - 1024) * (10000) / 660;
00103   rd.yaw = (vData.yaw - 1024) * (10000) / 660;
00104   rd.throttle = (vData.throttle - 1024) * (10000) / 660;
00105   return rd;
00106 }
00107 
00108 RCData VirtualRC::toRCData(VirtualRCData &vData)
00109 {
00110   RCData rcData;
00111   rcData.gear = (vData.gear == 1324) ? -454 : -10000;
00112   rcData.mode = (1024 - vData.mode ) * 10000 / 660;
00113   rcData.pitch = (vData.pitch - 1024) * (10000) / 660;
00114   rcData.roll = (vData.roll - 1024) * (10000) / 660;
00115   rcData.yaw = (vData.yaw - 1024) * (10000) / 660;
00116   rcData.throttle = (vData.throttle - 1024) * (10000) / 660;
00117   return rcData;
00118 }
00119 
00120 VirtualRCData VirtualRC::toVirtualRCData(RadioData &rData)
00121 {
00122   VirtualRCData vd;
00123   vd.yaw = rData.yaw * 660 / 10000 + 1024;
00124   vd.throttle = rData.throttle * 660 / 10000 + 1024;
00125   vd.pitch = rData.pitch * 660 / 10000 + 1024;
00126   vd.roll = rData.roll * 660 / 10000 + 1024;
00127   vd.gear = (rData.gear == -4545) ? 1324 : 1684;
00128   vd.reserved = 1024;
00129   vd.mode = rData.mode * 660 / (-10000) + 1024;
00130   vd.Channel_07 = 1024;
00131   vd.Channel_08 = 1024;
00132   vd.Channel_09 = 1024;
00133   vd.Channel_10 = 1024;
00134   vd.Channel_11 = 1024;
00135   vd.Channel_12 = 1024;
00136   vd.Channel_13 = 1024;
00137   vd.Channel_14 = 1024;
00138   vd.Channel_15 = 1024;
00139   return vd;
00140 }


dji_sdk_lib
Author(s):
autogenerated on Thu Jun 6 2019 17:55:25