ardrone_sdk.cpp
Go to the documentation of this file.
1 
26 #include <ardrone_autonomy/video.h>
28 #include <stdint.h>
29 
30 const navdata_unpacked_t* shared_raw_navdata_ptr;
32 
33 vp_os_mutex_t navdata_lock;
34 vp_os_mutex_t video_lock;
35 vp_os_mutex_t twist_lock;
36 
37 int32_t current_navdata_id = 0;
38 
40 
41 int32_t looprate;
44 
45 int32_t should_exit;
46 
47 extern "C"
48 {
49  vp_stages_latency_estimation_config_t vlat;
50 
51  DEFINE_THREAD_ROUTINE(update_ros, data)
52  {
53  PRINT("Thread `update_ros` started \n ");
54  ARDroneDriver* driver = reinterpret_cast<ARDroneDriver*>(data);
55  driver->run();
56  return (THREAD_RET) 0;
57  }
58 
59  C_RESULT ardrone_tool_init_custom(void)
60  {
61  should_exit = 0;
62  vp_os_mutex_init(&navdata_lock);
63  vp_os_mutex_init(&video_lock);
64  vp_os_mutex_init(&twist_lock);
65 
66  ros_driver = new ARDroneDriver();
67  int _w, _h;
68 
69  if (IS_ARDRONE2)
70  {
71  ardrone_application_default_config.video_codec = H264_360P_CODEC;
72  _w = D2_STREAM_WIDTH;
73  _h = D2_STREAM_HEIGHT;
74  }
75  else if (IS_ARDRONE1)
76  {
77  ardrone_application_default_config.video_codec = UVLC_CODEC;
78  _w = D1_STREAM_WIDTH;
79  _h = D1_STREAM_HEIGHT;
80  }
81  else
82  {
83  printf("Something must be really wrong with the SDK!");
84  }
85 
86  ros::param::param("~looprate", looprate, 50);
87  ros::param::param("~realtime_navdata", realtime_navdata, false);
88  ros::param::param("~realtime_video", realtime_video, false);
89  if (!realtime_navdata) ROS_WARN("realtime navdata is off, odometry may be imprecise");
90 
91  // SET SOME NON-STANDARD DEFAULT VALUES FOR THE DRIVER
92  // THESE CAN BE OVERWRITTEN BY ROS PARAMETERS (below)
93  ardrone_application_default_config.bitrate_ctrl_mode = VBC_MODE_DISABLED;
94  if (IS_ARDRONE2)
95  {
96  ardrone_application_default_config.max_bitrate = 4000;
97  }
98 
99  ardrone_application_default_config.navdata_options = NAVDATA_OPTION_FULL_MASK;
100  ardrone_application_default_config.video_channel = ZAP_CHANNEL_HORI;
101  ardrone_application_default_config.control_level = (0 << CONTROL_LEVEL_COMBINED_YAW);
102  ardrone_application_default_config.flying_mode = FLYING_MODE_FREE_FLIGHT;
103 
104  // Load ROS param to config snippet
106  // Now continue with the rest of the initialization
107 
108  ardrone_tool_input_add(&teleop);
109  uint8_t post_stages_index = 0;
110 
111  // Alloc structs
112  specific_parameters_t* params = reinterpret_cast<specific_parameters_t*>(
113  vp_os_calloc(1, sizeof(specific_parameters_t)));
114  specific_stages_t* driver_pre_stages = reinterpret_cast<specific_stages_t*>(
115  vp_os_calloc(1, sizeof(specific_stages_t)));
116  specific_stages_t* driver_post_stages = reinterpret_cast<specific_stages_t*>(
117  vp_os_calloc(1, sizeof(specific_stages_t)));
118  vp_api_picture_t* in_picture = reinterpret_cast<vp_api_picture_t*>(
119  vp_os_calloc(1, sizeof(vp_api_picture_t)));
120  vp_api_picture_t* out_picture = reinterpret_cast<vp_api_picture_t*>(
121  vp_os_calloc(1, sizeof(vp_api_picture_t)));
122 
123  in_picture->width = _w;
124  in_picture->height = _h;
125 
126  out_picture->framerate = 20;
127  out_picture->format = PIX_FMT_RGB24;
128  out_picture->width = _w;
129  out_picture->height = _h;
130 
131  out_picture->y_buf = reinterpret_cast<uint8_t*>(vp_os_malloc(_w * _h * 3));
132  out_picture->cr_buf = NULL;
133  out_picture->cb_buf = NULL;
134 
135  out_picture->y_line_size = _w * 3;
136  out_picture->cb_line_size = 0;
137  out_picture->cr_line_size = 0;
138 
139  // Alloc the lists
140  driver_pre_stages->stages_list = NULL;
141  driver_post_stages->stages_list = reinterpret_cast<vp_api_io_stage_t*>(
142  vp_os_calloc(NB_DRIVER_POST_STAGES, sizeof(vp_api_io_stage_t)));
143 
144  // Fill the POST-stages------------------------------------------------------
145  // vp_os_memset (&vlat, 0x0, sizeof (vlat));
146  // vlat.state = (vp_stages_latency_estimation_state) 0;
147  // //vlat.last_decoded_frame_info= (void *)&vec;
148  // driver_post_stages->stages_list[post_stages_index].name = "LatencyEst";
149  // driver_post_stages->stages_list[post_stages_index].type = VP_API_FILTER_DECODER;
150  // driver_post_stages->stages_list[post_stages_index].cfg = (void *)&vlat;
151  // driver_post_stages->stages_list[post_stages_index++].funcs = vp_stages_latency_estimation_funcs;
152 
153  driver_post_stages->stages_list[post_stages_index].name = "ExtractData";
154  driver_post_stages->stages_list[post_stages_index].type = VP_API_OUTPUT_SDL;
155  driver_post_stages->stages_list[post_stages_index].cfg = NULL;
156  driver_post_stages->stages_list[post_stages_index++].funcs = vp_stages_export_funcs;
157 
158  driver_pre_stages->length = 0;
159  driver_post_stages->length = post_stages_index;
160 
161  params->in_pic = in_picture;
162  params->out_pic = out_picture;
163  params->pre_processing_stages_list = driver_pre_stages;
164  params->post_processing_stages_list = driver_post_stages;
165  params->needSetPriority = 1;
166  params->priority = 31;
167  // Using the provided threaded pipeline implementation from SDK
168  START_THREAD(video_stage, params);
169  video_stage_init();
170  if (ARDRONE_VERSION() >= 2)
171  {
172  START_THREAD(video_recorder, NULL);
173  video_recorder_init();
174  video_recorder_resume_thread();
175  }
176  // Threads do not start automatically
177  video_stage_resume_thread();
178  ardrone_tool_set_refresh_time(25);
179  // rosDriver->configure_drone();
180  START_THREAD(update_ros, ros_driver);
181  return C_OK;
182  }
183 
185  {
186  PRINT("Shutting down ... \n ");
187  JOIN_THREAD(update_ros);
188  delete ros_driver;
189  video_stage_resume_thread();
190  ardrone_tool_input_remove(&teleop);
191  return C_OK;
192  }
193 
194  C_RESULT navdata_custom_init(void* data)
195  {
196  (void) data;
197  return C_OK;
198  }
199 
200  C_RESULT navdata_custom_process(const navdata_unpacked_t * const pnd)
201  {
202  vp_os_mutex_lock(&navdata_lock);
203  shared_navdata_receive_time = ros::Time::now();
204  shared_raw_navdata_ptr = reinterpret_cast<const navdata_unpacked_t*>(pnd);
205 
206  if (realtime_navdata)
207  {
208  // if we're publishing navdata at full speed, publish!
209  const navdata_unpacked_t shared_raw_navdata = *shared_raw_navdata_ptr;
210  ros_driver->PublishNavdataTypes(shared_raw_navdata, shared_navdata_receive_time);
211  ros_driver->PublishNavdata(shared_raw_navdata, shared_navdata_receive_time);
212  ros_driver->PublishOdometry(shared_raw_navdata, shared_navdata_receive_time);
213  }
214 
216  vp_os_mutex_unlock(&navdata_lock);
217  return C_OK;
218  }
219 
221  {
222  return C_OK;
223  }
224 
226  {
227  return (should_exit == 1);
228  }
229 
230  BEGIN_THREAD_TABLE
231  THREAD_TABLE_ENTRY(video_stage, 31)
232  THREAD_TABLE_ENTRY(update_ros, 43)
233  THREAD_TABLE_ENTRY(video_recorder, 20)
234  THREAD_TABLE_ENTRY(navdata_update, 31)
235 // THREAD_TABLE_ENTRY(ATcodec_Commands_Client, 43)
236  THREAD_TABLE_ENTRY(ardrone_control, 31)
237  END_THREAD_TABLE
238 
239  BEGIN_NAVDATA_HANDLER_TABLE
240  NAVDATA_HANDLER_TABLE_ENTRY(
244  NULL)
245  END_NAVDATA_HANDLER_TABLE
246 }
#define NB_DRIVER_POST_STAGES
Definition: ardrone_sdk.h:72
bool param(const std::string &param_name, T &param_val, const T &default_val)
bool_t ardrone_tool_exit()
C_RESULT navdata_custom_release()
bool realtime_navdata
Definition: ardrone_sdk.cpp:42
const vp_api_stage_funcs_t vp_stages_export_funcs
Definition: video.cpp:61
vp_os_mutex_t twist_lock
Definition: ardrone_sdk.cpp:35
void PublishOdometry(const navdata_unpacked_t &navdata_raw, const ros::Time &navdata_receive_time)
const navdata_unpacked_t * shared_raw_navdata_ptr
Definition: ardrone_sdk.cpp:30
#define ROS_WARN(...)
int32_t current_navdata_id
Definition: ardrone_sdk.cpp:37
#define D1_STREAM_HEIGHT
Definition: video.h:41
int32_t should_exit
Definition: ardrone_sdk.cpp:45
#define D2_STREAM_WIDTH
Definition: video.h:58
#define D1_STREAM_WIDTH
Definition: video.h:40
C_RESULT ardrone_tool_shutdown_custom()
#define D2_STREAM_HEIGHT
Definition: video.h:59
C_RESULT navdata_custom_process(const navdata_unpacked_t *const pnd)
bool realtime_video
Definition: ardrone_sdk.cpp:43
DEFINE_THREAD_ROUTINE(update_ros, data)
Definition: ardrone_sdk.cpp:51
printf("Deleting Profile %s\n", buffer)
ARDroneDriver * ros_driver
Definition: ardrone_sdk.cpp:39
ros::Time shared_navdata_receive_time
Definition: ardrone_sdk.cpp:31
vp_os_mutex_t navdata_lock
Definition: ardrone_sdk.cpp:33
C_RESULT navdata_custom_init(void *data)
static Time now()
input_device_t teleop
vp_os_mutex_t video_lock
Definition: ardrone_sdk.cpp:34
vp_stages_latency_estimation_config_t vlat
Definition: ardrone_sdk.cpp:49
void PublishNavdata(const navdata_unpacked_t &navdata_raw, const ros::Time &navdata_receive_time)
C_RESULT ardrone_tool_init_custom(void)
Definition: ardrone_sdk.cpp:59
int32_t looprate
Definition: ardrone_sdk.cpp:41


ardrone_autonomy
Author(s): Mani Monajjemi, Mani Monajjemi
autogenerated on Mon Jun 10 2019 12:39:49