Swarm API

Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
swarm::RobotPlugin Class Reference

A Model plugin that is the base class for all agent plugins in a swarm. More...

#include <RobotPlugin.hh>

Inheritance diagram for swarm::RobotPlugin:
Inheritance graph
[legend]

Public Types

enum  VehicleType { GROUND = 0, ROTOR = 1, FIXED_WING = 2 }
 The type of vehicle. More...
 

Public Member Functions

 RobotPlugin ()
 Class constructor. More...
 
virtual ~RobotPlugin ()
 Class destructor. More...
 

Protected Member Functions

double BatteryCapacity () const
 Get the current battery capacity (mAh). More...
 
double BatteryConsumption () const
 Get the vehicle's battery consumption (mA). More...
 
double BatteryConsumptionFactor () const
 Get the vehicle's battery consumption factor (unitless). More...
 
double BatteryStartCapacity () const
 Get starting battery capacity (mAh). More...
 
bool Bearing (ignition::math::Angle &_bearing) const
 Angle between the true North and the robot. More...
 
template<typename C >
bool Bind (void(C::*_cb)(const std::string &_srcAddress, const std::string &_dstAddress, const uint32_t _dstPort, const std::string &_data), C *_obj, const std::string &_address, const int _port=kDefaultPort)
 This method can bind a local address and a port to a virtual socket. More...
 
ignition::math::Pose3d CameraToWorld (const ignition::math::Pose3d &_poseinCamera) const
 Convert a pose in a robot's camera frame into the world frame. More...
 
double ExpectedBatteryLife () const
 Get the expected battery life in seconds. More...
 
std::string Host () const
 Get your local address. More...
 
bool Image (ImageData &_img) const
 Get the set of objects detected by the camera. More...
 
bool Imu (ignition::math::Vector3d &_linVel, ignition::math::Vector3d &_angVel, ignition::math::Quaterniond &_orient) const
 Get the robot's IMU information. More...
 
virtual void Load (sdf::ElementPtr _sdf)
 This method is called after the world has been loaded and gives child plugins access to the SDF model file. More...
 
std::string Name () const
 Get the name of this robot. More...
 
std::vector< std::string > Neighbors () const
 Get the list of local neighbors. More...
 
bool Pose (double &_latitude, double &_longitude, double &_altitude) const
 Get the robot's current pose from its GPS sensor. More...
 
void SearchArea (double &_minLatitude, double &_maxLatitude, double &_minLongitude, double &_maxLongitude)
 Get the search area, in GPS coordinates. More...
 
bool SendTo (const std::string &_data, const std::string &_dstAddress, const uint32_t _port=kDefaultPort)
 Send some data to other/s member/s of the swarm. More...
 
bool SetAngularVelocity (const ignition::math::Vector3d &_velocity)
 Set the robot's angular velocity, using Euler angles. More...
 
bool SetAngularVelocity (const double _x, const double _y, const double _z)
 Set the robot's angular velocity, using Euler angles. More...
 
bool SetLinearVelocity (const ignition::math::Vector3d &_velocity)
 Set the robot's linear velocity. More...
 
bool SetLinearVelocity (const double _x, const double _y, const double _z)
 Set the robot's linear velocity. More...
 
VehicleType Type () const
 Get the type of vehicle. More...
 
virtual void Update (const gazebo::common::UpdateInfo &_info)
 Update the plugin. More...
 

Protected Attributes

const std::string kBoo = "boo"
 Address used by the base of operations. More...
 
const std::string kBroadcast = "broadcast"
 Address used to send a message to all the members of the swarm listening on a specific port. More...
 
const std::string kMulticast = "multicast"
 Address used to bind to a multicast group. More...
 

Static Protected Attributes

static const uint32_t kBooPort = 4200
 Base of communications port. More...
 
static const uint32_t kDefaultPort = 4100
 Default port. More...
 
static const uint32_t kMtu = 1500
 Maximum transmission payload size (octets) for each message. More...
 

Detailed Description

A Model plugin that is the base class for all agent plugins in a swarm.

This plugin exposes the following functionality to the derived plugins:

Motion.

Sensors.

Introspection.

Member Enumeration Documentation

The type of vehicle.

Enumerator
GROUND 

A ground vehicle.

ROTOR 

A rotorcraft aerial vehicle.

FIXED_WING 

A fixed wing aerial vehicle.

Constructor & Destructor Documentation

swarm::RobotPlugin::RobotPlugin ( )

Class constructor.

virtual swarm::RobotPlugin::~RobotPlugin ( )
virtual

Class destructor.

Member Function Documentation

double swarm::RobotPlugin::BatteryCapacity ( ) const
protected

Get the current battery capacity (mAh).

Returns
The battery capacity in mAh.
double swarm::RobotPlugin::BatteryConsumption ( ) const
protected

Get the vehicle's battery consumption (mA).

Returns
The battery consumption in mA.
double swarm::RobotPlugin::BatteryConsumptionFactor ( ) const
protected

Get the vehicle's battery consumption factor (unitless).

Returns
Get the factor applied to battery consumption. This value will be between 0 and 1, where a value < 1 accounts for additional current draw.
double swarm::RobotPlugin::BatteryStartCapacity ( ) const
protected

Get starting battery capacity (mAh).

Returns
The battery's start capacity in mAh.
bool swarm::RobotPlugin::Bearing ( ignition::math::Angle &  _bearing) const
protected

Angle between the true North and the robot.

If the vehicle is facing North the bearing is 0. The bearing increments clockwise up to 2*PI radians. For example, a vehicle facing East would have a bearing of PI/2 radians. Note that in Gazebo the North is aligned with the +Y axis.

Parameters
[out]_bearingBearing between the true North and the robot.
Returns
True if the call was successful.
template<typename C >
bool swarm::RobotPlugin::Bind ( void(C::*)(const std::string &_srcAddress, const std::string &_dstAddress, const uint32_t _dstPort, const std::string &_data)  _cb,
C *  _obj,
const std::string &  _address,
const int  _port = kDefaultPort 
)
inlineprotected

This method can bind a local address and a port to a virtual socket.

This is a required step if your agent needs to receive messages.

Parameters
[in]_addressLocal address or "kMulticast". If you specify your local address, you will receive all the messages sent where the destination is <YOUR_LOCAL_ADDRESS, port> or <"kBroadcast", port>. On the other hand, if you specify "kMulticast" as the _address parameter, you will be subscribed to the multicast group <"kMulticast, port>". You will receive all the messages sent from any node to this multicast group.
[in]_cbCallback function to be executed when a new message is received associated to the specified <_address, port>. In the callback, "_srcAddress" contains the address of the sender of the message. "_dstAddress" contains the destination address. "_dstPort" contains the destination port. "_data" contains the payload.
[in]_objInstance containing the member function callback.
[in]_portPort used to receive messages.
Returns
True when success or false otherwise.
  • Example usage (bind on the local address and default port): this->Bind(&MyClass::OnDataReceived, this, this->Host());
  • Example usage (Bind on the multicast group and custom port.): this->Bind(&MyClass::OnDataReceived, this, this->kMulticast, 5123);
ignition::math::Pose3d swarm::RobotPlugin::CameraToWorld ( const ignition::math::Pose3d &  _poseinCamera) const
protected

Convert a pose in a robot's camera frame into the world frame.

Parameters
[in]_poseinCameraThe pose in the camera frame
Returns
The pose in the world frame.
double swarm::RobotPlugin::ExpectedBatteryLife ( ) const
protected

Get the expected battery life in seconds.

Returns
Battery life in seconds, based on the current capacity and consumption.
std::string swarm::RobotPlugin::Host ( ) const
protected

Get your local address.

This address should be specified as a SDF model parameter.

Returns
The local address.
bool swarm::RobotPlugin::Image ( ImageData _img) const
protected

Get the set of objects detected by the camera.

Parameters
[out]_imgImage object that will hold the output from the camera. Note that each object's pose is in the robot's camera frame. Use CameraToWorld() for making a conversion to world coordinates.
Returns
True if the call was successful.
See also
CameraToWorld
bool swarm::RobotPlugin::Imu ( ignition::math::Vector3d &  _linVel,
ignition::math::Vector3d &  _angVel,
ignition::math::Quaterniond &  _orient 
) const
protected

Get the robot's IMU information.

The linear velocity is set in the robot's local coordinate frame, where

  • x = forward/back velocity,
  • y = left/right velociy,
  • z = up/down velocity.

The angular velocity is set in the robot's local coordinate frame, where

  • x = Velocity about x-axis (roll),
  • y = Velocity about y-axis (pitch),
  • z = Velocity about z-axis (yaw).

The orientation is set relative to the reference pose with a range from PI to -PI. The reference pose was initialized when the robot was spawned

  • x = Offset with respect the reference pos about x-axis (roll),
  • y = Offset with respect the reference pos about y-axis (pitch),
  • z = Offset with respect the reference pos about z-axis (yaw).
Parameters
[out]_linVelLinear velocity in the robot's local coordinate frame (m/s).
[out]_angVelAngular velocity in the robot's local coordinate frame (m/s).
[out]_orientOffset with respect the reference pos.
virtual void swarm::RobotPlugin::Load ( sdf::ElementPtr  _sdf)
protectedvirtual

This method is called after the world has been loaded and gives child plugins access to the SDF model file.

Parameters
[in]_sdfPointer to the SDF element of the model.
std::string swarm::RobotPlugin::Name ( ) const
protected

Get the name of this robot.

Returns
The name given to this robot in the SDF file.
std::vector<std::string> swarm::RobotPlugin::Neighbors ( ) const
protected

Get the list of local neighbors.

Returns
A vector of addresses from your local neighbors.
bool swarm::RobotPlugin::Pose ( double &  _latitude,
double &  _longitude,
double &  _altitude 
) const
protected

Get the robot's current pose from its GPS sensor.

Parameters
[out]_latitudeRobot latitude will be written here.
[out]_longitudeRobot longitude will be written here.
[out]_altitudeRobot altitude will be written here.
Returns
True if the call was successful.
void swarm::RobotPlugin::SearchArea ( double &  _minLatitude,
double &  _maxLatitude,
double &  _minLongitude,
double &  _maxLongitude 
)
protected

Get the search area, in GPS coordinates.

Parameters
[out]_minLatitudeMinimum latitude will be written here.
[out]_maxLatitudeMaximum latitude will be written here.
[out]_minLongitudeMinimum longitude will be written here.
[out]_maxLongitudeMaximum longitude will be written here.
bool swarm::RobotPlugin::SendTo ( const std::string &  _data,
const std::string &  _dstAddress,
const uint32_t  _port = kDefaultPort 
)
protected

Send some data to other/s member/s of the swarm.

Parameters
[in]_dstAddressDestination address. Note that the destination address might be a unicast address, "kBroadcast" or "kMulticast". In the case of broadcast and multicast communications your node will receive your own message if you're bind to your local or the multicast address.
[in]_portDestination port.
[in]_dataPayload.
Returns
True when success or false if the underlying library used for sending messages notifies an error (meaning that the message was not sent).
bool swarm::RobotPlugin::SetAngularVelocity ( const ignition::math::Vector3d &  _velocity)
protected

Set the robot's angular velocity, using Euler angles.

The velocity is applied in the robot's local coordinate frame, where

  • x = rotate about x-axis (roll),
  • y = rotate about y-axis (pitch),
  • z = rotate about z-axis (yaw).

This velocity will be constrained by the type of robot. For example, a ground vehicle will ignore the x and y components of the _velocity vector, but a quadcopter will use all three.

Parameters
[in]_velocityVelocity about the robot's local XYZ axes (radian/s).
Returns
True if the command was successful. False if the angular velocity could not be set, such as due to low battery.
bool swarm::RobotPlugin::SetAngularVelocity ( const double  _x,
const double  _y,
const double  _z 
)
protected

Set the robot's angular velocity, using Euler angles.

The velocity is applied in the robot's local coordinate frame, where

  • x = rotate about x-axis (roll),
  • y = rotate about y-axis (pitch),
  • z = rotate about z-axis (yaw).

This velocity will be constrained by the type of robot. For example, a ground vehicle will ignore the x and y components of the _velocity vector, but a quadcopter will use all three.

Parameters
[in]_xVelocity about the robot's local X axis (radian/s).
[in]_yVelocity about the robot's local Y axis (radian/s).
[in]_zVelocity about the robot's local Z axis (radian/s).
Returns
True if the command was successful. False if the angular velocity could not be set, such as due to low battery.
bool swarm::RobotPlugin::SetLinearVelocity ( const ignition::math::Vector3d &  _velocity)
protected

Set the robot's linear velocity.

The velocity is applied in the robot's local coordinate frame, where

  • x = forward/back,
  • y = left/right,
  • z = up/down.

This velocity will be constrained by the type of robot. For example, a ground vehicle will ignore the y & z components of the _velocity vector, but a rotorcraft will use all three.

Parameters
[in]_velocityThe velocity vector in the robot's local coordinate frame (m/s).
Returns
True if the command was successful. False if the linear velocity could not be set, such as due to low battery.
bool swarm::RobotPlugin::SetLinearVelocity ( const double  _x,
const double  _y,
const double  _z 
)
protected

Set the robot's linear velocity.

The velocity is applied in the robot's local coordinate frame, where

  • x = forward/back,
  • y = left/right,
  • z = up/down.

This velocity will be constrained by the type of robot. For example, a ground vehicle will ignore the y & z components of the _velocity vector, but a rotorcraft will use all three.

Parameters
[in]_xX velocity in the robot's local coordinate frame (m/s).
[in]_yY velocity in the robot's local coordinate frame (m/s).
[in]_zZ velocity in the robot's local coordinate frame (m/s).
Returns
True if the command was successful. False if the linear velocity could not be set, such as due to low battery.
VehicleType swarm::RobotPlugin::Type ( ) const
protected

Get the type of vehicle.

The type of vehicle is set in the SDF world file using the <type> XML element.

Returns
The enum value that specifies what type of vehicles this plugin controls.
virtual void swarm::RobotPlugin::Update ( const gazebo::common::UpdateInfo &  _info)
protectedvirtual

Update the plugin.

This function is called once every iteration.

Parameters
[in]_infoUpdate information provided by the server.

Field Documentation

const std::string swarm::RobotPlugin::kBoo = "boo"
protected

Address used by the base of operations.

const uint32_t swarm::RobotPlugin::kBooPort = 4200
staticprotected

Base of communications port.

const std::string swarm::RobotPlugin::kBroadcast = "broadcast"
protected

Address used to send a message to all the members of the swarm listening on a specific port.

const uint32_t swarm::RobotPlugin::kDefaultPort = 4100
staticprotected

Default port.

const uint32_t swarm::RobotPlugin::kMtu = 1500
staticprotected

Maximum transmission payload size (octets) for each message.

const std::string swarm::RobotPlugin::kMulticast = "multicast"
protected

Address used to bind to a multicast group.

Note that we do not support multiple multicast groups, only one.


The documentation for this class was generated from the following file: