Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpRobotBebop2.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Interface for the Irisa's Afma6 robot.
32 *
33 * Authors:
34 * Gatien Gaumerais
35 */
36
37#ifndef _vpRobotBebop2_h_
38#define _vpRobotBebop2_h_
39
40#include <visp3/core/vpConfig.h>
41
42#if defined(VISP_HAVE_ARSDK) && defined(VISP_HAVE_THREADS)
43
44#include <visp3/core/vpImage.h>
45
46extern "C" {
47#include <libARController/ARController.h> // For drone control
48#include <libARSAL/ARSAL.h> // For semaphore
49
50#ifdef VISP_HAVE_FFMPEG
51#include <libavcodec/avcodec.h> // For H264 video decoding
52#include <libswscale/swscale.h> // For rescaling decoded frames
53#endif
54}
55
56#include <mutex>
57#include <signal.h>
58#include <string>
59
75class VISP_EXPORT vpRobotBebop2
76{
77public:
78 vpRobotBebop2(bool verbose = false, bool setDefaultSettings = true, std::string ipAddress = "192.168.42.1",
79 int discoveryPort = 44444);
80 virtual ~vpRobotBebop2();
81
83
84 std::string getIpAddress();
85 int getDiscoveryPort();
87
89
90 void doFlatTrim();
91 unsigned int getBatteryLevel();
92 void setVerbose(bool verbose);
93 void resetAllSettings();
95
97
98 bool isFlying();
99 bool isHovering();
100 bool isLanded();
101 bool isRunning();
102 bool isStreaming();
104
105 //*** Motion commands ***//
107
108 void cutMotors();
109 double getMaxTilt();
110 void setMaxTilt(double maxTilt);
111 void setPitch(int value);
112 void setPosition(float dX, float dY, float dZ, float dPsi, bool blocking);
113 void setPosition(const vpHomogeneousMatrix &M, bool blocking);
114 void setRoll(int value);
115 void setVelocity(const vpColVector &vel, double delta_t);
116 void setVerticalSpeed(int value);
117 void setYawSpeed(int value);
118 void stopMoving();
119 void takeOff(bool blocking = true);
121 static void land();
122 //*** ***//
123
124 //*** Streaming commands ***//
125#ifdef VISP_HAVE_FFMPEG
128 void getGrayscaleImage(vpImage<unsigned char> &I);
130 int getVideoHeight();
131 int getVideoWidth();
132 void setExposure(float expo);
133 void setStreamingMode(int mode);
134 void setVideoResolution(int mode);
135 void setVideoStabilisationMode(int mode);
136 void startStreaming();
137 void stopStreaming();
139#endif
140 //*** ***//
141
142 //*** Camera control commands ***//
145 double getCameraHorizontalFOV() const;
146 double getCurrentCameraPan() const;
147 double getMaxCameraPan() const;
148 double getMinCameraPan() const;
149 double getCurrentCameraTilt() const;
150 double getMaxCameraTilt() const;
151 double getMinCameraTilt() const;
152 void setCameraOrientation(double tilt, double pan, bool blocking = false);
153 void setCameraPan(double pan, bool blocking = false);
154 void setCameraTilt(double tilt, bool blocking = false);
156 //*** ***//
157
158private:
159 //*** Attributes ***//
160 std::string m_ipAddress;
161 int m_discoveryPort;
162
163 ARSAL_Sem_t m_stateSem;
164 struct sigaction m_sigAct;
165
166#ifdef VISP_HAVE_FFMPEG
167 AVCodecContext *m_codecContext;
168 AVPacket *m_packet;
169 AVFrame *m_picture;
170 std::mutex m_bgr_picture_mutex;
171 AVFrame *m_bgr_picture;
172 SwsContext *m_img_convert_ctx;
173 uint8_t *m_buffer;
174
175 bool m_videoDecodingStarted;
176
177 int m_videoWidth;
178 int m_videoHeight;
179#endif
180
181 static bool m_running;
183
184 bool m_exposureSet;
185 bool m_flatTrimFinished;
186 bool m_relativeMoveEnded;
187 bool m_videoResolutionSet;
188 bool m_streamingStarted;
189 bool m_streamingModeSet;
190 bool m_settingsReset;
191
192 bool m_update_codec_params;
193 std::vector<uint8_t> m_codec_params_data;
194
195 unsigned int m_batteryLevel;
196 double m_maxTilt;
197
198 double m_cameraHorizontalFOV;
199
200 double m_currentCameraTilt;
201 double m_minCameraTilt;
202 double m_maxCameraTilt;
203
204 double m_currentCameraPan;
205 double m_minCameraPan;
206 double m_maxCameraPan;
207
208 static ARCONTROLLER_Device_t *m_deviceController;
209
210 eARCONTROLLER_ERROR m_errorController;
211 eARCONTROLLER_DEVICE_STATE m_deviceState;
212 //*** ***//
213
214 [[noreturn]] static void sighandler(int signo);
215
216 eARCOMMANDS_ARDRONE3_PILOTINGSTATE_FLYINGSTATECHANGED_STATE getFlyingState();
217 eARCOMMANDS_ARDRONE3_MEDIASTREAMINGSTATE_VIDEOENABLECHANGED_ENABLED getStreamingState();
218
219 //*** Setup functions ***//
220 void cleanUp();
221 ARDISCOVERY_Device_t *discoverDrone();
222 void createDroneController(ARDISCOVERY_Device_t *discoveredDrone);
223 void setupCallbacks();
224 void startController();
225
226#ifdef VISP_HAVE_FFMPEG
227 //*** Video streaming functions ***//
228 void initCodec();
229 void cleanUpCodec();
230
231 void startVideoDecoding();
232 void stopVideoDecoding();
233 void computeFrame(ARCONTROLLER_Frame_t *frame);
234 //*** ***//
235#endif
236
237 //*** Callbacks ***//
238 static void stateChangedCallback(eARCONTROLLER_DEVICE_STATE newState, eARCONTROLLER_ERROR error, void *customData);
239#ifdef VISP_HAVE_FFMPEG
240 static eARCONTROLLER_ERROR decoderConfigCallback(ARCONTROLLER_Stream_Codec_t codec, void *customData);
241 static eARCONTROLLER_ERROR didReceiveFrameCallback(ARCONTROLLER_Frame_t *frame, void *customData);
242#endif
243
244 static void cmdBatteryStateChangedRcv(ARCONTROLLER_DICTIONARY_ELEMENT_t *elementDictionary, vpRobotBebop2 *drone);
245 static void cmdCameraOrientationChangedRcv(ARCONTROLLER_DICTIONARY_ELEMENT_t *elementDictionary,
246 vpRobotBebop2 *drone);
247 static void cmdCameraSettingsRcv(ARCONTROLLER_DICTIONARY_ELEMENT_t *elementDictionary, vpRobotBebop2 *drone);
248 static void cmdExposureSetRcv(ARCONTROLLER_DICTIONARY_ELEMENT_t *elementDictionary, vpRobotBebop2 *drone);
249 static void cmdMaxPitchRollChangedRcv(ARCONTROLLER_DICTIONARY_ELEMENT_t *elementDictionary, vpRobotBebop2 *drone);
250 static void cmdRelativeMoveEndedRcv(ARCONTROLLER_DICTIONARY_ELEMENT_t *elementDictionary, vpRobotBebop2 *drone);
251 static void commandReceivedCallback(eARCONTROLLER_DICTIONARY_KEY commandKey,
252 ARCONTROLLER_DICTIONARY_ELEMENT_t *elementDictionary, void *customData);
253 //*** ***//
254};
255END_VISP_NAMESPACE
256#endif //#ifdef VISP_HAVE_ARSDK
257#endif //#ifndef _vpRobotBebop2_h_
Implementation of column vector and the associated operations.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Definition vpImage.h:131
void setPitch(int value)
std::string getIpAddress()
double getMinCameraPan() const
void setMaxTilt(double maxTilt)
void setPosition(float dX, float dY, float dZ, float dPsi, bool blocking)
void setVelocity(const vpColVector &vel, double delta_t)
void setExposure(float expo)
double getCurrentCameraPan() const
void setVideoStabilisationMode(int mode)
void setRoll(int value)
double getMinCameraTilt() const
double getMaxCameraTilt() const
void setVerbose(bool verbose)
void setVerticalSpeed(int value)
void setStreamingMode(int mode)
static void land()
unsigned int getBatteryLevel()
void getRGBaImage(vpImage< vpRGBa > &I)
void setYawSpeed(int value)
void setCameraPan(double pan, bool blocking=false)
void takeOff(bool blocking=true)
double getCurrentCameraTilt() const
double getCameraHorizontalFOV() const
void setVideoResolution(int mode)
void setCameraTilt(double tilt, bool blocking=false)
vpRobotBebop2(bool verbose=false, bool setDefaultSettings=true, std::string ipAddress="192.168.42.1", int discoveryPort=44444)
void setCameraOrientation(double tilt, double pan, bool blocking=false)
double getMaxCameraPan() const