Go to the documentation of this file.00001
00012 #include <dji_sdk/dji_sdk_mission.h>
00013
00014 DJI::onboardSDK::HotPointData new_hotpoint = {0};
00015 DJI::onboardSDK::FollowData new_follow = {0};
00016
00017 void DJISDKMission::mission_status_callback(uint8_t *buf, uint8_t len)
00018 {
00019 DJI::onboardSDK::GSPushData mission_status_data;
00020
00021 memcpy(&mission_status_data, buf, len);
00022
00023 mission_status.type = mission_status_data.type;
00024 mission_status.data_1 = mission_status_data.data_1;
00025 mission_status.data_2 = mission_status_data.data_2;
00026 mission_status.data_3 = mission_status_data.data_3;
00027 mission_status.data_4 = mission_status_data.data_4;
00028 mission_status.data_5 = mission_status_data.data_5;
00029 mission_status_publisher.publish(mission_status);
00030 }
00031
00032 void DJISDKMission::mission_event_callback(uint8_t *buf, uint8_t len)
00033 {
00034 DJI::onboardSDK::GSPushData mission_event_data;
00035
00036 memcpy(&mission_event_data, buf, len);
00037 mission_event.data_1 = mission_event_data.data_1;
00038 mission_event.data_2 = mission_event_data.data_2;
00039 mission_event.data_3 = mission_event_data.data_3;
00040 mission_event.data_4 = mission_event_data.data_4;
00041 mission_event.data_5 = mission_event_data.data_5;
00042 mission_event_publisher.publish(mission_event);
00043 }
00044
00045
00046 bool DJISDKMission::mission_start_callback(dji_sdk::MissionStart::Request& request, dji_sdk::MissionStart::Response& response)
00047 {
00048 switch(current_type)
00049 {
00050 case MissionType::WAYPOINT:
00051
00052 rosAdapter->waypoint->start();
00053
00054 break;
00055
00056 case MissionType::HOTPOINT:
00057
00058 new_hotpoint.latitude = hotpoint_task.latitude;
00059 new_hotpoint.longitude = hotpoint_task.longitude;
00060 new_hotpoint.height = hotpoint_task.altitude;
00061 new_hotpoint.radius = hotpoint_task.radius;
00062 new_hotpoint.yawRate = hotpoint_task.angular_speed;
00063 new_hotpoint.clockwise = hotpoint_task.is_clockwise;
00064 new_hotpoint.startPoint = hotpoint_task.start_point;
00065 new_hotpoint.yawMode = hotpoint_task.yaw_mode;
00066 rosAdapter->hotpoint->setData(new_hotpoint);
00067 rosAdapter->hotpoint->start();
00068
00069 break;
00070
00071 case MissionType::FOLLOWME:
00072
00073 new_follow.mode = followme_task.mode;
00074 new_follow.yaw = followme_task.yaw_mode;
00075 new_follow.target.latitude = followme_task.initial_latitude;
00076 new_follow.target.longitude = followme_task.initial_longitude;
00077 new_follow.target.height = followme_task.initial_altitude;
00078 new_follow.target.angle = 0;
00079 new_follow.sensitivity = followme_task.sensitivity;
00080 rosAdapter->followme->setData(new_follow);
00081 rosAdapter->followme->start(0,0,0);
00082
00083 break;
00084
00085 default:
00086
00087 return false;
00088
00089 }
00090 return true;
00091
00092 }
00093
00094
00095 bool DJISDKMission::mission_pause_callback(dji_sdk::MissionPause::Request& request, dji_sdk::MissionPause::Response& response)
00096 {
00097
00098 switch(current_type)
00099 {
00100
00101 case MissionType::WAYPOINT:
00102 rosAdapter->waypoint->pause(request.pause == 0 ? true : false);
00103 break;
00104
00105 case MissionType::HOTPOINT:
00106 rosAdapter->hotpoint->pause(request.pause == 0 ? true : false);
00107 break;
00108
00109 case MissionType::FOLLOWME:
00110 rosAdapter->followme->pause(request.pause == 0 ? true : false);
00111
00112 break;
00113 default:
00114 return false;
00115
00116 }
00117
00118 return true;
00119
00120 }
00121
00122
00123 bool DJISDKMission::mission_cancel_callback(dji_sdk::MissionCancel::Request& request, dji_sdk::MissionCancel::Response& response)
00124 {
00125
00126 switch(current_type)
00127 {
00128
00129 case MissionType::WAYPOINT:
00130 rosAdapter->waypoint->stop();
00131 break;
00132
00133 case MissionType::HOTPOINT:
00134 rosAdapter->hotpoint->stop();
00135 break;
00136
00137 case MissionType::FOLLOWME:
00138 rosAdapter->followme->stop();
00139 break;
00140
00141 default:
00142 return false;
00143
00144 }
00145 return true;
00146 }
00147
00148
00149 bool DJISDKMission::mission_wp_download_callback(dji_sdk::MissionWpDownload::Request& request, dji_sdk::MissionWpDownload::Response& response)
00150 {
00151 if (current_type != MissionType::WAYPOINT)
00152 {
00153 ROS_INFO("Drone not in waypoint task!");
00154 return false;
00155 }
00156
00157 dji_sdk::MissionWaypointTask waypoint_task;
00158 dji_sdk::MissionWaypoint waypont_data;
00159
00160
00161
00162 response.waypoint_task = waypoint_task;
00163 return true;
00164 }
00165
00166 bool DJISDKMission::mission_hp_download_callback(dji_sdk::MissionHpDownload::Request& request, dji_sdk::MissionHpDownload::Response& response)
00167 {
00168 if (current_type != MissionType::HOTPOINT)
00169 {
00170 ROS_INFO("Drone not in hotpoint task!");
00171 return false;
00172 }
00173
00174 dji_sdk::MissionHotpointTask hotpoint_task;
00175
00176
00177
00178 response.hotpoint_task = hotpoint_task;
00179 return true;
00180 }
00181
00182
00183 bool DJISDKMission::mission_wp_upload_callback(dji_sdk::MissionWpUpload::Request& request, dji_sdk::MissionWpUpload::Response& response)
00184 {
00185
00186 waypoint_task = request.waypoint_task;
00187 DJI::onboardSDK::WayPointInitData new_task = {0};
00188 DJI::onboardSDK::WayPointData new_waypoint = {0};
00189
00190 new_task.indexNumber = waypoint_task.mission_waypoint.size();
00191 new_task.maxVelocity = waypoint_task.velocity_range;
00192 new_task.idleVelocity = waypoint_task.idle_velocity;
00193 new_task.finishAction = waypoint_task.action_on_finish;
00194 new_task.executiveTimes = waypoint_task.mission_exec_times;
00195 new_task.yawMode = waypoint_task.yaw_mode;
00196 new_task.traceMode = waypoint_task.trace_mode;
00197 new_task.RCLostAction = waypoint_task.action_on_rc_lost;
00198 new_task.gimbalPitch = waypoint_task.gimbal_pitch_mode;
00199
00200 rosAdapter->waypoint->init(&new_task);
00201 printf("uploaded the task with %d waypoints\n", new_task.indexNumber);
00202
00203 sleep(2);
00204
00205 int i = 0;
00206 for (auto waypoint:waypoint_task.mission_waypoint) {
00207 new_waypoint.latitude = waypoint.latitude*C_PI/180;
00208 new_waypoint.longitude = waypoint.longitude*C_PI/180;
00209 new_waypoint.altitude = waypoint.altitude;
00210 new_waypoint.damping = waypoint.damping_distance;
00211 new_waypoint.yaw = waypoint.target_yaw;
00212 new_waypoint.gimbalPitch = waypoint.target_gimbal_pitch;
00213 new_waypoint.turnMode = waypoint.turn_mode;
00214 new_waypoint.hasAction = waypoint.has_action;
00215 new_waypoint.actionTimeLimit = waypoint.action_time_limit;
00216
00217 new_waypoint.actionNumber = 15;
00218 new_waypoint.actionRepeat = waypoint.waypoint_action.action_repeat;
00219 std::copy(waypoint.waypoint_action.command_list.begin(), waypoint.waypoint_action.command_list.end(), new_waypoint.commandList);
00220 std::copy(waypoint.waypoint_action.command_parameter.begin(),waypoint.waypoint_action.command_parameter.end(), new_waypoint.commandParameter);
00221
00222 new_waypoint.index = i;
00223
00224 rosAdapter->waypoint->uploadIndexData(&new_waypoint);
00225 printf("uploaded the %dth waypoint\n", new_waypoint.index);
00226 i+=1;
00227 sleep(2);
00228 }
00229
00230 current_type = MissionType::WAYPOINT;
00231 printf("current_type -> WP\n");
00232
00233 return true;
00234
00235 }
00236
00237
00238 bool DJISDKMission::mission_wp_get_speed_callback(dji_sdk::MissionWpGetSpeed::Request& request, dji_sdk::MissionWpGetSpeed::Response& response)
00239 {
00240 if (current_type != MissionType::WAYPOINT)
00241 {
00242 printf("Not in Waypoint Mode!\n");
00243 return false;
00244 }
00245 rosAdapter->waypoint->readIdleVelocity();
00246 return true;
00247
00248 }
00249
00250
00251 bool DJISDKMission::mission_wp_set_speed_callback(dji_sdk::MissionWpSetSpeed::Request& request, dji_sdk::MissionWpSetSpeed::Response& response)
00252 {
00253 if (current_type != MissionType::WAYPOINT)
00254 {
00255 printf("Not in Waypoint Mode!\n");
00256 return false;
00257 }
00258 rosAdapter->waypoint->updateIdleVelocity(request.speed);
00259 return true;
00260
00261 }
00262
00263
00264 bool DJISDKMission::mission_hp_upload_callback(dji_sdk::MissionHpUpload::Request& request, dji_sdk::MissionHpUpload::Response& response)
00265 {
00266 hotpoint_task = request.hotpoint_task;
00267 hotpoint_task.latitude = hotpoint_task.latitude*C_PI/180;
00268 hotpoint_task.longitude = hotpoint_task.longitude*C_PI/180;
00269
00270 current_type = MissionType::HOTPOINT;
00271 printf("current_type -> HP\n");
00272 return true;
00273
00274 }
00275
00276
00277 bool DJISDKMission::mission_hp_set_speed_callback(dji_sdk::MissionHpSetSpeed::Request& request, dji_sdk::MissionHpSetSpeed::Response& response)
00278 {
00279 if (current_type != MissionType::HOTPOINT)
00280 {
00281 printf("Not in Hotpoint Mode!\n");
00282 return false;
00283 }
00284 rosAdapter->hotpoint->updateYawRate(request.speed, request.direction);
00285
00286 return true;
00287
00288 }
00289
00290
00291 bool DJISDKMission::mission_hp_set_radius_callback(dji_sdk::MissionHpSetRadius::Request& request, dji_sdk::MissionHpSetRadius::Response& response)
00292 {
00293 if (current_type != MissionType::HOTPOINT)
00294 {
00295 printf("Not in Hotpoint Mode!\n");
00296 return false;
00297 }
00298 rosAdapter->hotpoint->updateRadius(request.radius);
00299
00300 return true;
00301
00302 }
00303
00304
00305 bool DJISDKMission::mission_hp_reset_yaw_callback(dji_sdk::MissionHpResetYaw::Request& request, dji_sdk::MissionHpResetYaw::Response& response)
00306 {
00307 if (current_type != MissionType::HOTPOINT)
00308 {
00309 printf("Not in Hotpoint Mode!\n");
00310 return false;
00311 }
00312 rosAdapter->hotpoint->resetYaw();
00313
00314 return true;
00315
00316 }
00317
00318
00319 bool DJISDKMission::mission_fm_upload_callback(dji_sdk::MissionFmUpload::Request& request, dji_sdk::MissionFmUpload::Response& response)
00320 {
00321 followme_task = request.followme_task;
00322 followme_task.initial_latitude = followme_task.initial_latitude*C_PI/180;
00323 followme_task.initial_longitude = followme_task.initial_longitude*C_PI/180;
00324
00325 current_type = MissionType::FOLLOWME;
00326 printf("current_type -> FM\n");
00327 return true;
00328
00329 }
00330
00331
00332 bool DJISDKMission::mission_fm_set_target_callback(dji_sdk::MissionFmSetTarget::Request& request, dji_sdk::MissionFmSetTarget::Response& response)
00333 {
00334 if (current_type != MissionType::FOLLOWME)
00335 {
00336 printf("Not in Followme Mode!\n");
00337 return false;
00338 }
00339 DJI::onboardSDK::FollowTarget target_info;
00340 target_info.latitude = request.followme_target.latitude;
00341 target_info.longitude = request.followme_target.longitude;
00342 target_info.height = request.followme_target.altitude;
00343 rosAdapter->followme->setTarget(target_info);
00344
00345 return true;
00346
00347 }
00348
00349
00350 DJISDKMission::DJISDKMission(ros::NodeHandle& nh)
00351 {
00352 init_missions(nh);
00353
00354 rosAdapter->setMissionStatusCallback(&DJISDKMission::mission_status_callback, this);
00355 rosAdapter->setMissionEventCallback(&DJISDKMission::mission_event_callback, this);
00356
00357 }
00358
00359