##

JoyPlugin Class Reference

The JoyPlugin connects to a joystick or gamepad, and transmits data from the joystick over an Ignition Transport topic. More...

`#include <JoyPlugin.hh>`

Inherits WorldPlugin.

## Public Types

typedef boost::shared_ptr< WorldPlugin > | TPtr
| plugin pointer type definition More...

## Public Member Functions

| JoyPlugin ()
| Constructor. More...
virtual | ~JoyPlugin ()
| Destructor. More...
std::string | GetFilename () const
| Get the name of the handler. More...
std::string | GetHandle () const
| Get the short name of the handler. More...
PluginType | GetType () const
| Returns the type of the plugin. More...
virtual void | Init ()
void | Load (physics::WorldPtr _world, sdf::ElementPtr _sdf) override
| Load function. More...
virtual void | Reset ()

## Static Public Member Functions

static TPtr | Create (const std::string &_filename, const std::string &_name)
| a class method that creates a plugin from a file name. More...

## Protected Member Functions

void | LoadParam (const sdf::ElementPtr &_sdf, const std::string &_name, V &_target, V _defaultValue=V()) const
| Load parameter value from _sdf and store it to the given reference, using the supplied default value if the element in _sdf is not found. More...
void | LoadParam (sdf::ElementPtr &_sdf, const std::string &_name, std::string &_target, const char *_defaultValue) const
| Load parameter value from _sdf and store it to the given reference, using the supplied default value if the element in _sdf is not found. More...

## Protected Attributes

std::string | filename
| Path to the shared library file. More...
std::string | handleName
| Short name. More...
PluginType | type
| Type of plugin. More...

## Detailed Description

The JoyPlugin connects to a joystick or gamepad, and transmits data from the joystick over an Ignition Transport topic.

The default topic name is /joy, and the message type is ignition.msgs.Joy.

Another plugin or application can listen to the joystick messages, and then take actions based on the data.

# Example

1. Connect a joystick to the computer.
2. Run the Gazebo demo: gazebo worlds/joy_demo.world

3. Echo the joy data to a terminal: ign topic -e -t /joy

   Note: You will need ign-tools

# Usage

The plugin is loaded via a world plugin. In SDF this looks like:

<plugin name="joy" filename="libJoyPlugin.so">
<sticky_buttons>false</sticky_buttons>
<dead_zone>0.05</dead_zone>
<rate>60</rate>
<accumulation_rate>1000</accumulation_rate>
</plugin>

See worlds/joy_demo.world for an example.

# Configuration

Options that can be specified in the plugin include:

1. <dev>(string): Name of the joystick device. The default value is /dev/input/js0.
2. <topic>(string): Name of the topic on which to publish joy messages. The default is /joy.
3. <sticky_buttons>(true/false): When true the buttons values change state only on a transition from 0 to 1. This makes the button act like toggle buttons. False is the default
4. <dead_zone>(float between 0 and 0.9): A larger number increases the distance the joystick has to move before registering a value. The default is 0.05;
5. <rate>(float): The rate at which joystick messages are published, in Hz. The default value is 1Hz.
6. <accumulation_rate>(float): The rate at which data is collected from the joystick device. The default value is 1000Hz.

# Troubleshooting

1. Playstation joysticks may require a press of the center "Ps" button before they work.

## Member Typedef Documentation

## TPtr

typedef boost::shared_ptr<WorldPlugin > TPtr

inherited

plugin pointer type definition

## Constructor & Destructor Documentation

## JoyPlugin()

JoyPlugin | ( |  | ) |

Constructor.

## ~JoyPlugin()

virtual ~JoyPlugin | ( |  | ) |

virtual

Destructor.

## Member Function Documentation

## Create()

static TPtr Create | ( | const std::string & | _filename,
|  | const std::string & | _name
| ) |  |

inline static inherited

a class method that creates a plugin from a file name.

It locates the shared library and loads it dynamically.

Parameters

  [in] | _filename | the path to the shared library.
  [in] | _name | short name of the plugin

Returns
  Shared Pointer to this class type

## GetFilename()

std::string GetFilename | ( |  | ) | const

inline inherited

Get the name of the handler.

## GetHandle()

std::string GetHandle | ( |  | ) | const

inline inherited

Get the short name of the handler.

## GetType()

PluginType GetType | ( |  | ) | const

inline inherited

Returns the type of the plugin.

Returns
  type of the plugin

## Init()

virtual void Init | ( |  | ) |

inline virtual inherited

Reimplemented in StaticMapPlugin, ArrangePlugin, SimEventsPlugin, and RubblePlugin.

## Load()

void Load | ( | physics::WorldPtr | _world,
|  | sdf::ElementPtr | _sdf
| ) |  |

override virtual

Load function.

Called when a Plugin is first created, and after the World has been loaded. This function should not be blocking.

Parameters

  [in] | _world | Pointer the World
  [in] | _sdf | Pointer the the SDF element of the plugin.

Implements WorldPlugin.

## LoadParam() [1/2]

void LoadParam | ( | const sdf::ElementPtr & | _sdf,
|  | const std::string & | _name,
|  | V & | _target,
|  | V | _defaultValue = `V()`
| ) |  | const

inline protected inherited

Load parameter value from _sdf and store it to the given reference, using the supplied default value if the element in _sdf is not found.

A message is written using gzmsg reporting whether the default value was used or not.

Parameters

  [in] | _sdf | The SDF element of the plugin.
  [in] | _name | Name of a tag inside the SDF.
  [out] | _target | The reference to store the param value to.
  [in] | _defaultValue | The default value.

## LoadParam() [2/2]

void LoadParam | ( | sdf::ElementPtr & | _sdf,
|  | const std::string & | _name,
|  | std::string & | _target,
|  | const char * | _defaultValue
| ) |  | const

inline protected inherited

Load parameter value from _sdf and store it to the given reference, using the supplied default value if the element in _sdf is not found.

A message is written using gzmsg reporting whether the default value was used or not. String specialization to allow accepting const char* values for std::string parameters.

Parameters

  [in] | _sdf | The SDF element of the plugin.
  [in] | _name | Name of a tag inside the SDF.
  [out] | _target | The reference to store the param value to.
  [in] | _defaultValue | The default value.

## Reset()

virtual void Reset | ( |  | ) |

inline virtual inherited

Reimplemented in ArrangePlugin.

## Member Data Documentation

## filename

std::string filename

protected inherited

Path to the shared library file.

## handleName

std::string handleName

protected inherited

Short name.

## type

PluginType type

protected inherited

Type of plugin.

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

- JoyPlugin.hh

gazebo::PluginT< WorldPlugin >::filename
std::string filename
Path to the shared library file.
Definition: Plugin.hh:258