Visual Servoing Platform  version 3.5.1 under development (2023-03-14)
vpRobotMavsdk Class Reference

#include <visp3/robot/vpRobotMavsdk.h>

Public Member Functions

 vpRobotMavsdk ()
 
 vpRobotMavsdk (const std::string &connection_info)
 
virtual ~vpRobotMavsdk ()
 
Robot connection
void connect (const std::string &connection_info)
 
General robot information
float getBatteryLevel () const
 
void getPose (vpHomogeneousMatrix &pose) const
 
std::string getAddress () const
 
Robot state checking
bool isRunning () const
 
Sending state info
bool sendMocapData (const vpHomogeneousMatrix &M)
 

Commands and parameters

bool arm ()
 
void doFlatTrim ()
 
void holdPosition ()
 
bool kill ()
 
bool land ()
 
void setForwardSpeed (double vx)
 
void setLateralSpeed (double vy)
 
void setPosition (float dX, float dY, float dZ, float dPsi)
 
void setPosition (const vpHomogeneousMatrix &M)
 
void setVelocity (const vpColVector &vel, double delta_t)
 
void setVelocity (const vpColVector &vel)
 
void setVerticalSpeed (double vz)
 
void setYawSpeed (double wz)
 
void stopMoving ()
 
void setTakeOffAlt (double altitude)
 
bool takeOff (bool interactive=true)
 

Detailed Description

Interface for Mavlink allowing to control drones or rovers using a MavLink compatible controller.

This class needs cxx17 or more recent standard enabled during ViSP cmake configuration.

This class is enabled when MavSDK C++ is installed and detected by ViSP during cmake configuration step.

Note
The body frame associated to the robot controlled through MavLink is supposed to be Front-Right-Down (FRD) respectively for X-Y-Z.
See also
Tutorial: Image-based visual-servoing on a drone equipped with a Pixhawk
Examples
sendMocapToPixhawk.cpp, servoPixhawkDroneIBVS.cpp, testPixhawkDroneKeyboard.cpp, testPixhawkDronePositionControl.cpp, testPixhawkDroneTakeoff.cpp, and testPixhawkDroneVelocityControl.cpp.

Definition at line 68 of file vpRobotMavsdk.h.

Constructor & Destructor Documentation

◆ vpRobotMavsdk() [1/2]

vpRobotMavsdk::vpRobotMavsdk ( )

Default constructor without parameters. You need to use the connect() function afterwards.

See also
connect()

Definition at line 747 of file vpRobotMavsdk.cpp.

◆ vpRobotMavsdk() [2/2]

vpRobotMavsdk::vpRobotMavsdk ( const std::string &  connection_info)

Constructor.

Initializes robot controller, by discovering robots connected either with an Ethernet TCP or UDP link, or with a serial link the computer is currently connected to. Sets up signal handling to safely land/stop the robot when something wrong happens or when the user stops the binary using CRTL-C.

Warning
This constructor should be called after the robot is turned on, and after the computer is connected to the robot Ethernet network or with a serial link.
If the connection to the robot failed, the program will throw an exception.

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

Parameters
[in]connection_info: Specify connection information. This parameter must be written following these conventions:
  • for TCP link: tcp://[server_host][:server_port]
  • for UDP link: udp://[bind_host][:bind_port]
  • for Serial link: serial:///path/to/serial/dev[:baudrate] For more information see here.
Exceptions
vpException::fatalError: If the program failed to connect to the robot.

Definition at line 740 of file vpRobotMavsdk.cpp.

◆ ~vpRobotMavsdk()

vpRobotMavsdk::~vpRobotMavsdk ( )
virtual

Destructor. Lands the drone if not landed or stops the robot if it is a rover and safely disconnects everything.

Definition at line 753 of file vpRobotMavsdk.cpp.

Member Function Documentation

◆ arm()

bool vpRobotMavsdk::arm ( )

Arms the robot.

Returns
True if arming is successful, False otherwise.

Definition at line 822 of file vpRobotMavsdk.cpp.

◆ connect()

void vpRobotMavsdk::connect ( const std::string &  connection_info)

Connects to the robot and setups the different controllers.

Parameters
[in]connection_info: The connection information given to connect to the robot. You may use:
  • for TCP link: tcp://[server_host][:server_port]
  • for UDP link: udp://[bind_host][:bind_port]
  • for Serial link: serial:///path/to/serial/dev[:baudrate]

Example: udp://192.168.30.111:14550.

For more information see here.

See also
getAddress()

Definition at line 768 of file vpRobotMavsdk.cpp.

◆ doFlatTrim()

void vpRobotMavsdk::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.

Definition at line 807 of file vpRobotMavsdk.cpp.

◆ getAddress()

std::string vpRobotMavsdk::getAddress ( ) const

Gives the address given to connect to the robot.

Returns
: A string corresponding to the Ethernet or serial address used for the connection to the robot.
See also
connect()

Definition at line 788 of file vpRobotMavsdk.cpp.

◆ getBatteryLevel()

float vpRobotMavsdk::getBatteryLevel ( ) const

Gets current battery level in Volts.

Warning
When the robot battery gets below a certain threshold (around 14.8), you should recharge it.

Definition at line 794 of file vpRobotMavsdk.cpp.

◆ getPose()

void vpRobotMavsdk::getPose ( vpHomogeneousMatrix Pose) const

Gets the current robot pose in its local NED frame.

Parameters
[in]Pose: Homogeneous matrix describing the position and attitude of the robot.

Definition at line 800 of file vpRobotMavsdk.cpp.

◆ holdPosition()

void vpRobotMavsdk::holdPosition ( )

Makes the robot hold its position.

Warning
The function simply switches to Hold mode when the robot is equipped with a GPS. it can function without a GPS, but it still preferable to use it outdoors.

Definition at line 838 of file vpRobotMavsdk.cpp.

◆ isRunning()

bool vpRobotMavsdk::isRunning ( ) const

Checks if the robot is running, ie if the robot is connected and ready to receive commands.

Examples
testPixhawkDroneKeyboard.cpp.

Definition at line 773 of file vpRobotMavsdk.cpp.

◆ kill()

bool vpRobotMavsdk::kill ( )

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

Returns
True if the cut motors command was successful, false otherwise.
Warning
If your robot is a drone, it will fall.
Examples
testPixhawkDroneKeyboard.cpp.

Definition at line 909 of file vpRobotMavsdk.cpp.

◆ land()

bool vpRobotMavsdk::land ( )

Sends landing command. To use if your robot is a drone.

Returns
True if the landing is successful, false otherwise.
See also
takeOff()
Examples
testPixhawkDroneKeyboard.cpp.

Definition at line 852 of file vpRobotMavsdk.cpp.

◆ sendMocapData()

bool vpRobotMavsdk::sendMocapData ( const vpHomogeneousMatrix M)

Sends MoCap position data to the robot.

Returns
True if the MoCap data was successfully sent to the robot, false otherwise.
Parameters
[in]M: Homogeneous matrix containing the pose of the robot for the MoCap system.

Definition at line 780 of file vpRobotMavsdk.cpp.

◆ setForwardSpeed()

void vpRobotMavsdk::setForwardSpeed ( double  vx)

Sets the forward speed, expressed in m/s , in the Front-Right-Down body frame.

Warning
The robot will not stop moving in that direction until you send another motion command.
Parameters
[in]vx: Desired forward speed in m/s.
  • Positive values will make the robot go forward
  • Negative values will make the robot go backwards
Examples
testPixhawkDroneKeyboard.cpp.

Definition at line 931 of file vpRobotMavsdk.cpp.

◆ setLateralSpeed()

void vpRobotMavsdk::setLateralSpeed ( double  vy)

Sets the lateral speed, expressed in m/s, in the Front-Right-Down body frame.

Warning
The robot will not stop moving in that direction until you send another motion command.
Parameters
[in]vy: desired lateral speed in m/s.
  • Positive values will make the robot go right
  • Negative values will make the robot go left
Examples
testPixhawkDroneKeyboard.cpp.

Definition at line 942 of file vpRobotMavsdk.cpp.

◆ setPosition() [1/2]

void vpRobotMavsdk::setPosition ( const vpHomogeneousMatrix M)

Changes the relative position of the robot based on a homogeneous transformation matrix.

Parameters
[in]M: Homogeneous matrix with translation be expressed in meters and rotation in radians.
Warning
The rotation around the X and Y axes should be equal to 0, as the robot (drone or rover) cannot rotate around these axes.
This function is blocking.
See also
setPosition(float dX, float dY, float dZ, float dPsi, bool blocking)

Definition at line 879 of file vpRobotMavsdk.cpp.

◆ setPosition() [2/2]

void vpRobotMavsdk::setPosition ( float  dX,
float  dY,
float  dZ,
float  dPsi 
)

Moves the robot by the given amounts dX, dY, dZ (meters) and rotate the heading by dPsi (radian) in the Front-Right-Down (FRD) body frame. Doesn't do anything if the drone isn't flying or hovering. This function is blocking.

Parameters
[in]dX: Relative displacement along X axis (meters).
[in]dY: Relative displacement along Y axis (meters).
[in]dZ: Relative displacement along Z axis (meters).
[in]dPsi: Relative rotation of the heading (radians).
See also
setPosition(const vpHomogeneousMatrix &M, bool blocking)

Definition at line 866 of file vpRobotMavsdk.cpp.

◆ setTakeOffAlt()

void vpRobotMavsdk::setTakeOffAlt ( double  altitude)

Sets the take off altitude.

Parameters
[in]altitude: Desired altitude for take off in meters, equal to 1.0 m by default.
Warning
The altitude must be positive.
See also
takeOff()

Definition at line 816 of file vpRobotMavsdk.cpp.

◆ setVelocity() [1/2]

void vpRobotMavsdk::setVelocity ( const vpColVector vel_cmd)

Sets the robot velocity in its own Front-Right-Down (FRD) frame.

Parameters
[in]vel_cmd: 4-dim robot velocity commands, vx, vy, vz, wz. Translation velocities (vx, vy, vz) should be expressed in meters and rotation velocity (wz) in radians.
Warning
The dimension of the velocity vector should be equal to 4, as the robot cannot rotate around X and Y axes.
The robot applies this command until given another one.

Definition at line 902 of file vpRobotMavsdk.cpp.

◆ setVelocity() [2/2]

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

Sets the robot velocity in its own Front-Right-Down (FRD) frame for a duration delta_t. The robot stops afterwards.

Parameters
[in]vel_cmd: 4-dim robot 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 robot cannot rotate around X and Y axes.

Definition at line 891 of file vpRobotMavsdk.cpp.

◆ setVerticalSpeed()

void vpRobotMavsdk::setVerticalSpeed ( double  vz)

Sets the vertical speed, expressed in m/s, in the Front-Right-Down body frame.

Warning
The robot will not stop moving in that direction until you send another motion command.
Parameters
[in]vz: desired vertical speed in m/s.
  • Positive values will make the robot go down.
  • Negative values will make the robot go up.
Examples
testPixhawkDroneKeyboard.cpp.

Definition at line 953 of file vpRobotMavsdk.cpp.

◆ setYawSpeed()

void vpRobotMavsdk::setYawSpeed ( double  wz)

Sets the yaw speed, expressed as signed rotation speed.

Warning
The robot will not stop moving in that direction until you send another motion command.
Parameters
[in]wz: Desired yaw speed in rad/s. Positive values will make the robot turn to its right / clockwise Negative values will make the robot turn to its left / counterclockwise
Examples
testPixhawkDroneKeyboard.cpp.

Definition at line 920 of file vpRobotMavsdk.cpp.

◆ stopMoving()

void vpRobotMavsdk::stopMoving ( )

Stops any robot movement.

Warning
Depending on the speed of the robot when the function is called, the robot may still move a bit until it stabilizes.
Examples
testPixhawkDroneKeyboard.cpp.

Definition at line 845 of file vpRobotMavsdk.cpp.

◆ takeOff()

bool vpRobotMavsdk::takeOff ( bool  interactive = true)

Sends take off command. To use if your robot is a drone.

Parameters
[in]interactive: If True asks the user if the offboard mode is to be forced through the terminal. If false Offboard mode is automatically set.
Returns
True if the takeoff is successful, False otherwise
See also
setTakeOffAlt(), land()
Warning
This function is blocking.
Examples
testPixhawkDroneKeyboard.cpp.

Definition at line 831 of file vpRobotMavsdk.cpp.