Visual Servoing Platform  version 3.4.0
vpRobotBebop2 Class Reference

#include <vpRobotBebop2.h>

Public Member Functions

 vpRobotBebop2 (bool verbose=false, bool setDefaultSettings=true, std::string ipAddress="192.168.42.1", int discoveryPort=44444)
 
virtual ~vpRobotBebop2 ()
 
Drone networking information
std::string getIpAddress ()
 
int getDiscoveryPort ()
 
General drone information
void doFlatTrim ()
 
unsigned int getBatteryLevel ()
 
void setVerbose (bool verbose)
 
void resetAllSettings ()
 
Drone state checking
bool isFlying ()
 
bool isHovering ()
 
bool isLanded ()
 
bool isRunning ()
 
bool isStreaming ()
 
Motion commands and parameters
void cutMotors ()
 
double getMaxTilt ()
 
void setMaxTilt (double maxTilt)
 
void setPitch (int value)
 
void setPosition (float dX, float dY, float dZ, float dPsi, bool blocking)
 
void setPosition (const vpHomogeneousMatrix &M, bool blocking)
 
void setRoll (int value)
 
void setVelocity (const vpColVector &vel, double delta_t)
 
void setVerticalSpeed (int value)
 
void setYawSpeed (int value)
 
void stopMoving ()
 
void takeOff (bool blocking=true)
 
Streaming commands and parameters (only available if ViSP was built with FFMpeg support)
void getGrayscaleImage (vpImage< unsigned char > &I)
 
void getRGBaImage (vpImage< vpRGBa > &I)
 
int getVideoHeight ()
 
int getVideoWidth ()
 
void setExposure (float expo)
 
void setStreamingMode (int mode)
 
void setVideoResolution (int mode)
 
void setVideoStabilisationMode (int mode)
 
void startStreaming ()
 
void stopStreaming ()
 
Camera control commands and parameters
double getCameraHorizontalFOV () const
 
double getCurrentCameraPan () const
 
double getMaxCameraPan () const
 
double getMinCameraPan () const
 
double getCurrentCameraTilt () const
 
double getMaxCameraTilt () const
 
double getMinCameraTilt () const
 
void setCameraOrientation (double tilt, double pan, bool blocking=false)
 
void setCameraPan (double pan, bool blocking=false)
 
void setCameraTilt (double tilt, bool blocking=false)
 

Static Public Member Functions

static void land ()
 

Detailed Description

Interface for Parrot ARSDK3, allowing to control the Bebop 2 drone and get images from the camera (if ViSP was built with FFMpeg support).

Examples:
keyboardControlBebop2.cpp, servoBebop2.cpp, testRobotBebop2.cpp, and tutorial-grabber-bebop2.cpp.

Definition at line 71 of file vpRobotBebop2.h.

Constructor & Destructor Documentation

vpRobotBebop2::vpRobotBebop2 ( bool  verbose = false,
bool  setDefaultSettings = true,
std::string  ipAddress = "192.168.42.1",
int  discoveryPort = 44444 
)

Constructor (only one available).

Initialises drone control, by discovering drones with IP ipAddress and port discoveryPort on the wifi network the computer is currently connected to. Sets up signal handling to safely land the drone when something bad happens.

Warning
This constructor should be called after the drone is turned on, and after the computer is connected to the drone wifi network.
If the connection to the drone failed, the programm will throw an exception.

After having called this constructor, it is recommanded to check if the drone is running with isRunning() before sending commands to the drone.

Parameters
[in]verbose: turn verbose on or off If verbose is true : info, warning, error and fatal error messages are displayed. If verbose is false : only warning, error and fatal error messages are displayed.
[in]setDefaultSettings: set default settings or not If setDefaultSettings is true : the drone is reset to factory settings and the following parameters are set :
  • Resolution of streamed video to 480p (856x480).
  • Max roll and pitch to 10 degrees.
  • Video stabilisation to 0 (no stabilisation).
  • Video exposure compensation to 0.
  • Video streaming mode to 0 (lowest latency, average reliability).
  • Camera orientation to 0 degrees for tilt and 0 degrees for pan If setDefaultSettings is false : the current settings are unchanged.
[in]ipAddress: ip address used to discover the drone on the wifi network.
[in]discoveryPort: port used to discover the drone on the wifi network.
Exceptions
vpException::fatalError: If the program failed to connect to the drone.

Definition at line 114 of file vpRobotBebop2.cpp.

References vpException::fatalError, resetAllSettings(), setCameraOrientation(), setExposure(), setMaxTilt(), setStreamingMode(), setVerbose(), setVideoResolution(), and setVideoStabilisationMode().

vpRobotBebop2::~vpRobotBebop2 ( )
virtual

Destructor. Lands the drone if not landed, safely disconnects everything, and deactivates video streaming and decoding if needed.

Definition at line 214 of file vpRobotBebop2.cpp.

Member Function Documentation

void vpRobotBebop2::cutMotors ( )

Cuts the motors. Should only be used in emergency cases.

Warning
The drone will fall.
Examples:
keyboardControlBebop2.cpp.

Definition at line 600 of file vpRobotBebop2.cpp.

void vpRobotBebop2::doFlatTrim ( )

Sends a flat trim command to the robot, to calibrate accelerometer and gyro.

Warning
Should be executed only if the drone is landed and on a flat surface.
Examples:
keyboardControlBebop2.cpp, servoBebop2.cpp, and testRobotBebop2.cpp.

Definition at line 222 of file vpRobotBebop2.cpp.

References isLanded(), isRunning(), and vpTime::sleepMs().

unsigned int vpRobotBebop2::getBatteryLevel ( )

Gets current battery level.

Warning
When the drone battery gets to 0, it will automatically land and won't process any command.

Definition at line 263 of file vpRobotBebop2.cpp.

double vpRobotBebop2::getCameraHorizontalFOV ( ) const

Gets camera horizontal FOV (degrees).

Definition at line 269 of file vpRobotBebop2.cpp.

double vpRobotBebop2::getCurrentCameraPan ( ) const

Gets current camera pan (degrees).

Examples:
servoBebop2.cpp.

Definition at line 293 of file vpRobotBebop2.cpp.

Referenced by setCameraTilt().

double vpRobotBebop2::getCurrentCameraTilt ( ) const

Gets current camera tilt (degrees).

Examples:
servoBebop2.cpp.

Definition at line 275 of file vpRobotBebop2.cpp.

Referenced by setCameraPan().

int vpRobotBebop2::getDiscoveryPort ( )

Gets the drone port used during wifi discovery.

Definition at line 249 of file vpRobotBebop2.cpp.

void vpRobotBebop2::getGrayscaleImage ( vpImage< unsigned char > &  I)
Warning
This function is only available if ViSP is build with ffmpeg support.

Gets the last streamed and decoded image from the drone camera feed in grayscale. The image obtained has a width of 856 and a height of 480.

Parameters
[in,out]I: grayscale image that will contain last streamed and decoded image after the function ends.
Examples:
servoBebop2.cpp, and tutorial-grabber-bebop2.cpp.

Definition at line 788 of file vpRobotBebop2.cpp.

References vpImageConvert::BGRToGrey(), vpImage< Type >::bitmap, vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), and vpImage< Type >::resize().

std::string vpRobotBebop2::getIpAddress ( )

Gets the drone IP address used during wifi discovery.

Definition at line 243 of file vpRobotBebop2.cpp.

double vpRobotBebop2::getMaxCameraPan ( ) const

Gets maximum camera pan (degrees).

Definition at line 305 of file vpRobotBebop2.cpp.

double vpRobotBebop2::getMaxCameraTilt ( ) const

Gets maximum camera tilt (degrees).

Definition at line 287 of file vpRobotBebop2.cpp.

double vpRobotBebop2::getMaxTilt ( )

Gets the current max pitch and roll values allowed for the drone.

Definition at line 255 of file vpRobotBebop2.cpp.

double vpRobotBebop2::getMinCameraPan ( ) const

Gets minimum camera pan (degrees).

Definition at line 299 of file vpRobotBebop2.cpp.

double vpRobotBebop2::getMinCameraTilt ( ) const

Gets minimum camera tilt (degrees).

Definition at line 281 of file vpRobotBebop2.cpp.

void vpRobotBebop2::getRGBaImage ( vpImage< vpRGBa > &  I)
Warning
This function is only available if ViSP is build with ffmpeg support.

Gets the last streamed and decoded image from the drone camera feed in RGBa. The image obtained has a width of 856 and a height of 480.

Parameters
[in,out]I: RGBa image that will contain last streamed and decoded image after the function ends.
Examples:
keyboardControlBebop2.cpp, and testRobotBebop2.cpp.

Definition at line 816 of file vpRobotBebop2.cpp.

References vpImageConvert::BGRToRGBa(), vpImage< Type >::bitmap, vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), and vpImage< Type >::resize().

int vpRobotBebop2::getVideoHeight ( )
Warning
This function is only available if ViSP is build with ffmpeg support.

Gets the height of the video streamed by the drone (pixels).

Examples:
servoBebop2.cpp.

Definition at line 841 of file vpRobotBebop2.cpp.

int vpRobotBebop2::getVideoWidth ( )
Warning
This function is only available if ViSP is build with ffmpeg support.

Gets the width of the video streamed by the drone (pixels).

Definition at line 848 of file vpRobotBebop2.cpp.

bool vpRobotBebop2::isFlying ( )

Checks if the drone is currently flying, ie if the drone is up in the air and moving.

Definition at line 434 of file vpRobotBebop2.cpp.

Referenced by setPitch(), setPosition(), setRoll(), setVerticalSpeed(), and setYawSpeed().

bool vpRobotBebop2::isHovering ( )

Checks if the drone is currently hovering, ie if the drone is up in the air but not moving.

Definition at line 425 of file vpRobotBebop2.cpp.

Referenced by setPitch(), setPosition(), setRoll(), setVerticalSpeed(), setYawSpeed(), and takeOff().

bool vpRobotBebop2::isLanded ( )

Checks if the drone is currently landed.

Definition at line 443 of file vpRobotBebop2.cpp.

Referenced by doFlatTrim(), setStreamingMode(), setVideoResolution(), stopMoving(), and takeOff().

bool vpRobotBebop2::isStreaming ( )

Checks if the drone is currently streaming and decoding the video from its camera.

Examples:
keyboardControlBebop2.cpp, and servoBebop2.cpp.

Definition at line 412 of file vpRobotBebop2.cpp.

Referenced by setStreamingMode(), and setVideoResolution().

void vpRobotBebop2::land ( )
static

Sends landing command.

Warning
This function is static because it needs to be called by the signal handler in case of a detected signal.
Examples:
keyboardControlBebop2.cpp, servoBebop2.cpp, and testRobotBebop2.cpp.

Definition at line 478 of file vpRobotBebop2.cpp.

Referenced by stopStreaming().

void vpRobotBebop2::resetAllSettings ( )

Resets drone settings (like max tilt or streaming mode) to factory defaults.

Definition at line 723 of file vpRobotBebop2.cpp.

References isRunning(), and vpTime::sleepMs().

Referenced by vpRobotBebop2().

void vpRobotBebop2::setCameraOrientation ( double  tilt,
double  pan,
bool  blocking = false 
)

Sets camera orientation : tilt and pan (degrees).

Warning
The camera movement is gradual. It takes some time for the camera to reach the desired orientation.
Parameters
[in]tilt: The desired tilt.
[in]pan: The desired pan.
[in]blocking: If true, the function returns when the camera reached the desired position. If false, returns immediately. You can check if the camera reached the desired position using getCurrentCameraTilt() and getCurrentCameraPan().
Examples:
servoBebop2.cpp.

Definition at line 319 of file vpRobotBebop2.cpp.

References isRunning(), and vpTime::sleepMs().

Referenced by vpRobotBebop2().

void vpRobotBebop2::setCameraPan ( double  pan,
bool  blocking = false 
)

Sets camera pan (degrees).

Warning
The camera movement is gradual. It takes some time for the camera to reach the desired pan.
Parameters
[in]pan: The desired pan.
[in]blocking: If true, the function returns when the camera reached the desired position. If false, returns immediately. You can check if the camera reached the desired position using getCurrentCameraPan().

Definition at line 377 of file vpRobotBebop2.cpp.

References getCurrentCameraTilt(), isRunning(), and vpTime::sleepMs().

void vpRobotBebop2::setCameraTilt ( double  tilt,
bool  blocking = false 
)

Sets camera tilt (degrees).

Warning
The camera movement is gradual. It takes some time for the camera to reach the desired tilt.
Parameters
[in]tilt: The desired tilt.
[in]blocking: If true, the function returns when the camera reached the desired position. If false, returns immediately. You can check if the camera reached the desired position using getCurrentCameraTilt().

Definition at line 348 of file vpRobotBebop2.cpp.

References getCurrentCameraPan(), isRunning(), and vpTime::sleepMs().

void vpRobotBebop2::setExposure ( float  expo)
Warning
This function is only available if ViSP is build with ffmpeg support.

Sets the exposure compensation of the video (min : -1.5, max : 1.5).

Parameters
[in]expo: desired video exposure compensation.
Examples:
servoBebop2.cpp, and tutorial-grabber-bebop2.cpp.

Definition at line 857 of file vpRobotBebop2.cpp.

References isRunning(), and vpTime::sleepMs().

Referenced by vpRobotBebop2().

void vpRobotBebop2::setMaxTilt ( double  maxTilt)

Sets the max pitch and roll values for the drone. The smallest possible angle is 5, the maximum is 35.

Parameters
[in]maxTilt: new maximum pitch and roll value for the drone (degrees).
Warning
This value is only taken into account by the drone when issuing percentage-of-max-tilt-value-based commands.
This value is not taken into account by the drone when using setPosition or setVelocity functions.
Examples:
keyboardControlBebop2.cpp.

Definition at line 750 of file vpRobotBebop2.cpp.

References isRunning().

Referenced by vpRobotBebop2().

void vpRobotBebop2::setPitch ( int  value)

Sets the pitch angle, expressed as signed percentage of the maximum pitch angle.

Warning
The drone will not stop moving in that direction until you send another motion command.
Parameters
[in]value: desired pitch in signed percentage, between 100 and -100. Positive values will make the drone tilt and go forward Negative values will make the drone tilt and go backward
Examples:
keyboardControlBebop2.cpp.

Definition at line 548 of file vpRobotBebop2.cpp.

References isFlying(), isHovering(), and isRunning().

void vpRobotBebop2::setPosition ( float  dX,
float  dY,
float  dZ,
float  dPsi,
bool  blocking 
)

Moves the drone by the given amounts dX, dY, dZ (meters) and rotate the heading by dPsi (radian). Doesn't do anything if the drone isn't flying or hovering.

Parameters
[in]dX: displacement along X axis (meters).
[in]dY: displacement along Y axis (meters).
[in]dZ: displacement along Z axis (meters).
[in]dPsi: rotation of the heading (radians).
[in]blocking: specifies whether the function should be blocking or not. If blocking is true, the function will wait until the drone has finished moving. If blocking is false, the function will return even if the drone is still moving.
See also
setPosition(const vpHomogeneousMatrix &M, bool blocking)

Definition at line 622 of file vpRobotBebop2.cpp.

References isFlying(), isHovering(), isRunning(), and vpTime::sleepMs().

Referenced by setPosition(), and setVelocity().

void vpRobotBebop2::setPosition ( const vpHomogeneousMatrix M,
bool  blocking 
)

Changes the position of the drone based on a homogeneous transformation matrix.

Parameters
[in]M: homogeneous matrix. Translation should be expressed in meters and rotation in radians.
[in]blocking: specifies whether the function should be blocking or not. If blocking is true, the function will wait until the drone has finished moving. If blocking is false, the function will return even if the drone is still moving.
Warning
The rotation around the X and Y axes should be equal to 0, as the drone cannot rotate around these axes.
See also
setPosition(float dX, float dY, float dZ, float dPsi, bool blocking)

Definition at line 654 of file vpRobotBebop2.cpp.

References vpHomogeneousMatrix::getRotationMatrix(), vpRotationMatrix::getThetaUVector(), vpHomogeneousMatrix::getTranslationVector(), and setPosition().

void vpRobotBebop2::setRoll ( int  value)

Sets the roll angle, expressed as signed percentage of the maximum roll angle.

Warning
The drone will not stop moving in that direction until you send another motion command.
Parameters
[in]value: desired roll in signed percentage, between 100 and -100. Positive values will make the drone tilt and go to its right Negative values will make the drone tilt and go to its left
Examples:
keyboardControlBebop2.cpp.

Definition at line 576 of file vpRobotBebop2.cpp.

References isFlying(), isHovering(), and isRunning().

void vpRobotBebop2::setStreamingMode ( int  mode)
Warning
This function is only available if ViSP is build with ffmpeg support.

Sets the streaming mode.

Warning
This function should be called only if the drone isn't flying and the streaming isn't started.
Parameters
[in]mode: desired streaming mode. If mode = 0 (default mode), the streaming minimizes latency with average reliability (best for piloting). If mode = 1, the streaming maximizes the reliability with an average latency (best when streaming quality is important but not the latency). If mode = 2, the streaming maximizes the reliability using a framerate decimation with an average latency (best when streaming quality is important but not the latency).
Examples:
keyboardControlBebop2.cpp, and servoBebop2.cpp.

Definition at line 888 of file vpRobotBebop2.cpp.

References isLanded(), isRunning(), isStreaming(), and vpTime::sleepMs().

Referenced by vpRobotBebop2().

void vpRobotBebop2::setVelocity ( const vpColVector vel_cmd,
double  delta_t 
)

Sets the drone velocity.

Parameters
[in]vel_cmd: Drone velocity commands, vx, vy, vz, wz. Translation velocities (vx, vy, vz) should be expressed in meters and rotation velocity (wz) in radians.
[in]delta_t: Sampling time (in seconds), time during which the velocity vel_cmd is applied.
Warning
The dimension of the velocity vector should be equal to 4, as the drone cannot rotate around X and Y axes.
Examples:
servoBebop2.cpp, and testRobotBebop2.cpp.

Definition at line 681 of file vpRobotBebop2.cpp.

References vpExponentialMap::direct(), setPosition(), vpArray2D< Type >::size(), and stopMoving().

void vpRobotBebop2::setVerbose ( bool  verbose)

Sets the verbose level for console prints.

Parameters
[in]verbose: specifies the desired verbose level. If verbose is true : info, warning, error and fatal error messages are displayed. If verbose is false : only warning, error and fatal error messages are displayed.

Definition at line 710 of file vpRobotBebop2.cpp.

Referenced by vpRobotBebop2().

void vpRobotBebop2::setVerticalSpeed ( int  value)

Sets the vertical speed, expressed as signed percentage of the maximum vertical speed.

Warning
The drone will not stop moving in that direction until you send another motion command.
Parameters
[in]value: desired vertical speed in signed percentage, between 100 and -100. Positive values will make the drone go up Negative values will make the drone go down
Examples:
keyboardControlBebop2.cpp.

Definition at line 495 of file vpRobotBebop2.cpp.

References isFlying(), isHovering(), and isRunning().

void vpRobotBebop2::setVideoResolution ( int  mode)
Warning
This function is only available if ViSP is build with ffmpeg support.

Sets the streaming mode.

Warning
This function should be called only if the drone isn't flying and the streaming isn't started.
Parameters
[in]mode: desired streaming mode. If mode = 0 (default mode), the resolution is 480p (856x480). If mode = 1, the resolution is 720p (1280x720).
Examples:
keyboardControlBebop2.cpp, servoBebop2.cpp, testRobotBebop2.cpp, and tutorial-grabber-bebop2.cpp.

Definition at line 937 of file vpRobotBebop2.cpp.

References isLanded(), isRunning(), isStreaming(), and vpTime::sleepMs().

Referenced by vpRobotBebop2().

void vpRobotBebop2::setVideoStabilisationMode ( int  mode)
Warning
This function is only available if ViSP is build with ffmpeg support.

Sets the video stabilisation mode.

Parameters
[in]mode: desired stabilisation mode. If mode = 0, the video follows drone angles (no stabilisation, default). If mode = 1, the video is stabilised on roll only. If mode = 2, the video is stabilised on pitch only. If mode = 3, the video is stabilised on both pitch and roll.
Examples:
servoBebop2.cpp.

Definition at line 990 of file vpRobotBebop2.cpp.

References isRunning().

Referenced by vpRobotBebop2().

void vpRobotBebop2::setYawSpeed ( int  value)

Sets the yaw speed, expressed as signed percentage of the maximum yaw speed.

Warning
The drone will not stop moving in that direction until you send another motion command.
Parameters
[in]value: desired yaw speed in signed percentage, between 100 and -100. Positive values will make the drone turn to its right / clockwise Negative values will make the drone turn to its left / counterclockwise
Examples:
keyboardControlBebop2.cpp.

Definition at line 521 of file vpRobotBebop2.cpp.

References isFlying(), isHovering(), and isRunning().

void vpRobotBebop2::startStreaming ( )
Warning
This function is only available if ViSP is build with ffmpeg support.

Starts the video streaming from the drone camera. Every time a frame is received, it is decoded and stored into m_currentImage, which can be obtained with getImage().

See also
getImage(vpImage<unsigned char> &I)
Examples:
keyboardControlBebop2.cpp, servoBebop2.cpp, testRobotBebop2.cpp, and tutorial-grabber-bebop2.cpp.

Definition at line 1029 of file vpRobotBebop2.cpp.

References isRunning(), and vpTime::sleepMs().

void vpRobotBebop2::stopMoving ( )

Stops any drone movement.

Warning
Depending on the speed of the drone when the function is called, the drone may still move a bit until it stabilizes.
Examples:
keyboardControlBebop2.cpp, and servoBebop2.cpp.

Definition at line 767 of file vpRobotBebop2.cpp.

References isLanded(), and isRunning().

Referenced by setVelocity().

void vpRobotBebop2::stopStreaming ( )
Warning
This function is only available if ViSP is build with ffmpeg support.

Stops the streaming and decoding of the drone camera video

Definition at line 1064 of file vpRobotBebop2.cpp.

References land(), and vpTime::sleepMs().

void vpRobotBebop2::takeOff ( bool  blocking = true)

Sends take off command.

Parameters
[in]blocking: If true, the function returns when take off is achieved. If false, returns immediately. You can check if take off is finished using isHovering().
Examples:
keyboardControlBebop2.cpp, servoBebop2.cpp, and testRobotBebop2.cpp.

Definition at line 455 of file vpRobotBebop2.cpp.

References isHovering(), isLanded(), isRunning(), and vpTime::sleepMs().