Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
vpRobotBebop2 Class Reference

#include <visp3/robot/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 ()
 
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)
 

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)
 
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).

See also
Tutorial: Visual-servoing with Parrot Bebop 2 drone
Examples
keyboardControlBebop2.cpp, servoBebop2.cpp, testRobotBebop2.cpp, and tutorial-grabber-bebop2.cpp.

Definition at line 73 of file vpRobotBebop2.h.

Constructor & Destructor Documentation

◆ vpRobotBebop2()

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 program will throw an exception.

After having called this constructor, it is recommended 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 stabilization to 0 (no stabilization).
  • 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::~vpRobotBebop2 ( )
virtual

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

Definition at line 215 of file vpRobotBebop2.cpp.

Member Function Documentation

◆ cutMotors()

void vpRobotBebop2::cutMotors ( )

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

Warning
The drone will fall.
Examples
keyboardControlBebop2.cpp.

Definition at line 611 of file vpRobotBebop2.cpp.

◆ doFlatTrim()

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
testRobotBebop2.cpp.

Definition at line 223 of file vpRobotBebop2.cpp.

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

◆ getBatteryLevel()

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 265 of file vpRobotBebop2.cpp.

◆ getCameraHorizontalFOV()

double vpRobotBebop2::getCameraHorizontalFOV ( ) const

Gets camera horizontal FOV (degrees).

Definition at line 271 of file vpRobotBebop2.cpp.

◆ getCurrentCameraPan()

double vpRobotBebop2::getCurrentCameraPan ( ) const

Gets current camera pan (degrees).

Definition at line 295 of file vpRobotBebop2.cpp.

Referenced by setCameraTilt().

◆ getCurrentCameraTilt()

double vpRobotBebop2::getCurrentCameraTilt ( ) const

Gets current camera tilt (degrees).

Definition at line 277 of file vpRobotBebop2.cpp.

Referenced by setCameraPan().

◆ getDiscoveryPort()

int vpRobotBebop2::getDiscoveryPort ( )

Gets the drone port used during wifi discovery.

Definition at line 251 of file vpRobotBebop2.cpp.

◆ getGrayscaleImage()

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.

Definition at line 803 of file vpRobotBebop2.cpp.

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

◆ getIpAddress()

std::string vpRobotBebop2::getIpAddress ( )

Gets the drone IP address used during wifi discovery.

Definition at line 245 of file vpRobotBebop2.cpp.

◆ getMaxCameraPan()

double vpRobotBebop2::getMaxCameraPan ( ) const

Gets maximum camera pan (degrees).

Definition at line 307 of file vpRobotBebop2.cpp.

◆ getMaxCameraTilt()

double vpRobotBebop2::getMaxCameraTilt ( ) const

Gets maximum camera tilt (degrees).

Definition at line 289 of file vpRobotBebop2.cpp.

◆ getMaxTilt()

double vpRobotBebop2::getMaxTilt ( )

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

Definition at line 257 of file vpRobotBebop2.cpp.

◆ getMinCameraPan()

double vpRobotBebop2::getMinCameraPan ( ) const

Gets minimum camera pan (degrees).

Definition at line 301 of file vpRobotBebop2.cpp.

◆ getMinCameraTilt()

double vpRobotBebop2::getMinCameraTilt ( ) const

Gets minimum camera tilt (degrees).

Definition at line 283 of file vpRobotBebop2.cpp.

◆ getRGBaImage()

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
testRobotBebop2.cpp.

Definition at line 833 of file vpRobotBebop2.cpp.

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

◆ getVideoHeight()

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).

Definition at line 860 of file vpRobotBebop2.cpp.

◆ getVideoWidth()

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 867 of file vpRobotBebop2.cpp.

◆ isFlying()

bool vpRobotBebop2::isFlying ( )

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

Definition at line 440 of file vpRobotBebop2.cpp.

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

◆ isHovering()

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 431 of file vpRobotBebop2.cpp.

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

◆ isLanded()

bool vpRobotBebop2::isLanded ( )

Checks if the drone is currently landed.

Definition at line 449 of file vpRobotBebop2.cpp.

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

◆ isRunning()

bool vpRobotBebop2::isRunning ( )

◆ isStreaming()

bool vpRobotBebop2::isStreaming ( )

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

Definition at line 418 of file vpRobotBebop2.cpp.

Referenced by setStreamingMode(), and setVideoResolution().

◆ land()

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, and testRobotBebop2.cpp.

Definition at line 485 of file vpRobotBebop2.cpp.

◆ resetAllSettings()

void vpRobotBebop2::resetAllSettings ( )

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

Definition at line 736 of file vpRobotBebop2.cpp.

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

Referenced by vpRobotBebop2().

◆ setCameraOrientation()

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().

Definition at line 321 of file vpRobotBebop2.cpp.

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

Referenced by vpRobotBebop2().

◆ setCameraPan()

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 381 of file vpRobotBebop2.cpp.

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

◆ setCameraTilt()

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 351 of file vpRobotBebop2.cpp.

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

◆ setExposure()

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.

Definition at line 876 of file vpRobotBebop2.cpp.

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

Referenced by vpRobotBebop2().

◆ setMaxTilt()

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.

Definition at line 764 of file vpRobotBebop2.cpp.

References isRunning().

Referenced by vpRobotBebop2().

◆ setPitch()

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 557 of file vpRobotBebop2.cpp.

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

◆ setPosition() [1/2]

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 666 of file vpRobotBebop2.cpp.

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

◆ setPosition() [2/2]

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 633 of file vpRobotBebop2.cpp.

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

Referenced by setPosition(), and setVelocity().

◆ setRoll()

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 586 of file vpRobotBebop2.cpp.

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

◆ setStreamingMode()

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).

Definition at line 908 of file vpRobotBebop2.cpp.

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

Referenced by vpRobotBebop2().

◆ setVelocity()

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
testRobotBebop2.cpp.

Definition at line 693 of file vpRobotBebop2.cpp.

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

◆ setVerbose()

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 722 of file vpRobotBebop2.cpp.

Referenced by vpRobotBebop2().

◆ setVerticalSpeed()

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 502 of file vpRobotBebop2.cpp.

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

◆ setVideoResolution()

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
testRobotBebop2.cpp.

Definition at line 959 of file vpRobotBebop2.cpp.

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

Referenced by vpRobotBebop2().

◆ setVideoStabilisationMode()

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.

Definition at line 1014 of file vpRobotBebop2.cpp.

References isRunning().

Referenced by vpRobotBebop2().

◆ setYawSpeed()

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 529 of file vpRobotBebop2.cpp.

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

◆ startStreaming()

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
testRobotBebop2.cpp.

Definition at line 1054 of file vpRobotBebop2.cpp.

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

◆ stopMoving()

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.

Definition at line 782 of file vpRobotBebop2.cpp.

References isLanded(), and isRunning().

Referenced by setVelocity().

◆ stopStreaming()

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 1091 of file vpRobotBebop2.cpp.

References vpTime::sleepMs().

◆ takeOff()

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, and testRobotBebop2.cpp.

Definition at line 461 of file vpRobotBebop2.cpp.

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