dji_sdk_node_services.cpp
Go to the documentation of this file.
00001 
00012 #include <dji_sdk/dji_sdk_node.h>
00013 
00014 
00015 bool DJISDKNode::activation_callback(dji_sdk::Activation::Request& request, dji_sdk::Activation::Response& response)
00016 {
00017         rosAdapter->coreAPI->activate(&user_act_data);
00018         response.result = true;
00019         return true;
00020 }
00021 
00022 
00023 bool DJISDKNode::attitude_control_callback(dji_sdk::AttitudeControl::Request& request, dji_sdk::AttitudeControl::Response& response)
00024 {
00025     DJI::onboardSDK::FlightData flight_ctrl_data;
00026     flight_ctrl_data.flag = request.flag;
00027     flight_ctrl_data.x = request.x;
00028     flight_ctrl_data.y = request.y;
00029     flight_ctrl_data.z = request.z;
00030     flight_ctrl_data.yaw = request.yaw;
00031 
00032     rosAdapter->flight->setFlight(&flight_ctrl_data);
00033 
00034     response.result = true;
00035     return true;
00036 }
00037 
00038 
00039 bool DJISDKNode::camera_action_control_callback(dji_sdk::CameraActionControl::Request& request, dji_sdk::CameraActionControl::Response& response)
00040 {
00041     if (request.camera_action == 0) {
00042         rosAdapter->camera->setCamera(DJI::onboardSDK::Camera::CAMERA_CODE::CODE_CAMERA_SHOT);
00043         response.result = true;
00044     }
00045     else if (request.camera_action == 1) {
00046         rosAdapter->camera->setCamera(DJI::onboardSDK::Camera::CAMERA_CODE::CODE_CAMERA_VIDEO_START);
00047         response.result = true;
00048     }
00049     else if (request.camera_action == 2) {
00050         rosAdapter->camera->setCamera(DJI::onboardSDK::Camera::CAMERA_CODE::CODE_CAMERA_VIDEO_STOP);
00051         response.result = true;
00052     }
00053     else {
00054         response.result = false;
00055     }
00056     return true;
00057 }
00058 
00059 
00060 bool DJISDKNode::drone_task_control_callback(dji_sdk::DroneTaskControl::Request& request, dji_sdk::DroneTaskControl::Response& response)
00061 {
00062     if (request.task== 4) {
00063         //takeoff
00064         rosAdapter->flight->task(DJI::onboardSDK::Flight::TASK::TASK_TAKEOFF);
00065         response.result = true;
00066     }
00067     else if (request.task == 6) {
00068         //landing
00069         rosAdapter->flight->task(DJI::onboardSDK::Flight::TASK::TASK_LANDING);
00070         response.result = true;
00071     }
00072     else if (request.task == 1) {
00073         //gohome
00074         rosAdapter->flight->task(DJI::onboardSDK::Flight::TASK::TASK_GOHOME);
00075         response.result = true;
00076     }
00077     else
00078         response.result = false;
00079     return true;
00080 }
00081 
00082 
00083 bool DJISDKNode::gimbal_angle_control_callback(dji_sdk::GimbalAngleControl::Request& request, dji_sdk::GimbalAngleControl::Response& response) 
00084 {
00085     DJI::onboardSDK::GimbalAngleData gimbal_angle;
00086     gimbal_angle.yaw = request.yaw;
00087     gimbal_angle.roll = request.roll;
00088     gimbal_angle.pitch = request.pitch;
00089     gimbal_angle.duration = request.duration;
00090     gimbal_angle.mode = 0;
00091     gimbal_angle.mode |= request.absolute_or_incremental;
00092     gimbal_angle.mode |= request.yaw_cmd_ignore << 1;
00093     gimbal_angle.mode |= request.roll_cmd_ignore << 2;
00094     gimbal_angle.mode |= request.pitch_cmd_ignore << 3;
00095 
00096     rosAdapter->camera->setGimbalAngle(&gimbal_angle);
00097 
00098     response.result = true;
00099     return true;
00100 }
00101 
00102 
00103 bool DJISDKNode::gimbal_speed_control_callback(dji_sdk::GimbalSpeedControl::Request& request, dji_sdk::GimbalSpeedControl::Response& response)
00104 {
00105     DJI::onboardSDK::GimbalSpeedData gimbal_speed;
00106     gimbal_speed.yaw = request.yaw_rate;
00107     gimbal_speed.roll = request.roll_rate;
00108     gimbal_speed.pitch = request.pitch_rate;
00109     gimbal_speed.reserved = 0x80; //little endian. enable
00110 
00111     rosAdapter->camera->setGimbalSpeed(&gimbal_speed);
00112 
00113     response.result = true;
00114     return true;
00115 }
00116 
00117 
00118 bool DJISDKNode::global_position_control_callback(dji_sdk::GlobalPositionControl::Request& request, dji_sdk::GlobalPositionControl::Response& response)
00119 {
00120     float dst_x;
00121     float dst_y;
00122     float dst_z = request.altitude;
00123 
00124     if(global_position_ref_seted == 0)
00125     {
00126         printf("Cannot run global position navigation because home position haven't set yet!");
00127         response.result = false;
00128         return false;
00129     }
00130 
00131     gps_convert_ned(dst_x, 
00132             dst_y,
00133             request.longitude, request.latitude,
00134             global_position.longitude,  global_position.latitude);
00135 
00136     DJI::onboardSDK::FlightData flight_ctrl_data;
00137     flight_ctrl_data.flag = 0x90;
00138     flight_ctrl_data.x = dst_x - local_position.x;
00139     flight_ctrl_data.y = dst_y - local_position.y;
00140     flight_ctrl_data.z = dst_z;
00141     flight_ctrl_data.yaw = request.yaw;
00142 
00143     rosAdapter->flight->setFlight(&flight_ctrl_data);
00144 
00145     response.result = true;
00146     return true;
00147 }
00148 
00149 
00150 bool DJISDKNode::local_position_control_callback(dji_sdk::LocalPositionControl::Request& request, dji_sdk::LocalPositionControl::Response& response)
00151 {
00152     float dst_x = request.x;
00153     float dst_y = request.y;
00154     float dst_z = request.z;
00155 
00156     if(global_position_ref_seted == 0)
00157     {
00158         printf("Cannot run local position navigation because home position haven't set yet!");
00159         response.result = false;
00160         return false;
00161     }
00162 
00163     DJI::onboardSDK::FlightData flight_ctrl_data;
00164     flight_ctrl_data.flag = 0x90;
00165     flight_ctrl_data.x = dst_x - local_position.x;
00166     flight_ctrl_data.y = dst_y - local_position.y;
00167     flight_ctrl_data.z = dst_z;
00168     flight_ctrl_data.yaw = request.yaw;
00169 
00170     rosAdapter->flight->setFlight(&flight_ctrl_data);
00171 
00172     response.result = true;
00173     return true;
00174 }
00175 
00176 
00177 bool DJISDKNode::sdk_permission_control_callback(dji_sdk::SDKPermissionControl::Request& request, dji_sdk::SDKPermissionControl::Response& response)
00178 {
00179     if (request.control_enable == 1) {
00180         printf("Request Control");
00181         rosAdapter->coreAPI->setControl(1);
00182         response.result = true;
00183     }
00184     else if (request.control_enable == 0) {
00185         printf("Release Control");
00186         rosAdapter->coreAPI->setControl(0);
00187         response.result = true;
00188     }
00189     else
00190         response.result = false;
00191 
00192     return true;
00193 }
00194 
00195 
00196 bool DJISDKNode::velocity_control_callback(dji_sdk::VelocityControl::Request& request, dji_sdk::VelocityControl::Response& response)
00197 {
00198     DJI::onboardSDK::FlightData flight_ctrl_data;
00199     if (request.frame)
00200         //world frame 
00201         flight_ctrl_data.flag = 0x49;
00202     else
00203         //body frame
00204         flight_ctrl_data.flag = 0x4B;
00205 
00206     flight_ctrl_data.x = request.vx;
00207     flight_ctrl_data.y = request.vy;
00208     flight_ctrl_data.z = request.vz;
00209     flight_ctrl_data.yaw = request.yawRate;
00210 
00211     rosAdapter->flight->setFlight(&flight_ctrl_data);
00212 
00213     response.result = true;
00214     return true;
00215 }
00216 
00217 
00218 bool DJISDKNode::version_check_callback(dji_sdk::VersionCheck::Request& request, dji_sdk::VersionCheck::Response& response)
00219 {
00220     int sdkVer;
00221     sdkVer = rosAdapter->coreAPI->getSDKVersion();
00222     std::cout << std::hex << sdkVer << '\n';
00223         response.result = true;
00224         return true;
00225 }
00226 
00227 
00228 bool DJISDKNode::virtual_rc_enable_control_callback(dji_sdk::VirtualRCEnableControl::Request& request, dji_sdk::VirtualRCEnableControl::Response& response)
00229 {
00230     DJI::onboardSDK::VirtualRCSetting vrc_setting;
00231     vrc_setting.enable = request.enable;
00232     vrc_setting.cutoff = request.if_back_to_real;
00233     rosAdapter->virtualRC->setControl((bool)request.enable, (DJI::onboardSDK::VirtualRC::CutOff)request.if_back_to_real);
00234 
00235     response.result = true;
00236     return true;
00237 }
00238 
00239 
00240 bool DJISDKNode::virtual_rc_data_control_callback(dji_sdk::VirtualRCDataControl::Request& request, dji_sdk::VirtualRCDataControl::Response& response)
00241 {
00242         DJI::onboardSDK::VirtualRCData vrc_data;
00243         vrc_data.roll = request.channel_data[0];
00244         vrc_data.pitch = request.channel_data[1];
00245         vrc_data.throttle = request.channel_data[2];
00246         vrc_data.yaw = request.channel_data[3];
00247         vrc_data.gear = request.channel_data[4];
00248         vrc_data.reserved = request.channel_data[5];
00249         vrc_data.mode = request.channel_data[6];
00250         vrc_data.Channel_07 = request.channel_data[7];
00251         vrc_data.Channel_08 = request.channel_data[8];
00252         vrc_data.Channel_09 = request.channel_data[9];
00253         vrc_data.Channel_10 = request.channel_data[10];
00254         vrc_data.Channel_11 = request.channel_data[11];
00255         vrc_data.Channel_12 = request.channel_data[12];
00256         vrc_data.Channel_13 = request.channel_data[13];
00257         vrc_data.Channel_14 = request.channel_data[14];
00258         vrc_data.Channel_15 = request.channel_data[15];
00259         rosAdapter->virtualRC->sendData(vrc_data);
00260 
00261         response.result = true;
00262         return true;
00263 }
00264 
00265 
00266 bool DJISDKNode::drone_arm_control_callback(dji_sdk::DroneArmControl::Request& request, dji_sdk::DroneArmControl::Response& response)
00267 {
00268         uint8_t arm = request.arm;
00269         rosAdapter->flight->setArm((bool)arm);
00270 
00271         response.result = true;
00272         return true;
00273 }
00274 
00275 
00276 bool DJISDKNode::sync_flag_control_callback(dji_sdk::SyncFlagControl::Request& request, dji_sdk::SyncFlagControl::Response& response)
00277 {
00278         uint32_t frequency = request.frequency;
00279         rosAdapter->coreAPI->setSyncFreq(frequency);
00280 
00281         response.result = true;
00282         return true;
00283 }
00284 
00285 
00286 bool DJISDKNode::message_frequency_control_callback(dji_sdk::MessageFrequencyControl::Request& request, dji_sdk::MessageFrequencyControl::Response& response)
00287 {
00288         uint8_t message_frequency[16];
00289         std::copy(request.frequency.begin(), request.frequency.end(), message_frequency);
00290         rosAdapter->coreAPI->setBroadcastFreq(message_frequency);
00291 
00292         response.result = true;
00293         return true;
00294 }
00295 
00296 bool DJISDKNode::send_data_to_remote_device_callback(dji_sdk::SendDataToRemoteDevice::Request& request, dji_sdk::SendDataToRemoteDevice::Response& response)
00297 {
00298         memcpy(transparent_transmission_data, &request.data[0], request.data.size());
00299         rosAdapter->sendToMobile(transparent_transmission_data, request.data.size());
00300         response.result = true;
00301         return true;
00302 }


dji_sdk
Author(s): Botao Hu
autogenerated on Thu Jun 6 2019 17:55:30