|  | YARP Yet Another Robot Platform |  | 
 
 
 
Go to the documentation of this file.
   26     m_ports.push_back(&m_buttonsPort  );
 
   27     m_ports.push_back(&m_axisPort     );
 
   28     m_ports.push_back(&m_stickPort    );
 
   29     m_ports.push_back(&m_trackballPort);
 
   30     m_ports.push_back(&m_touchPort    );
 
   31     m_ports.push_back(&m_hatsPort     );
 
   35 bool JoypadControlClient::getJoypadInfo()
 
   42     vector<tuple<int, JoypadControl::LoopablePort*, string> > vocabs_ports;
 
   43     vocabs_ports.emplace_back(
VOCAB_BUTTON,    &m_buttonsPort,   
"/buttons");
 
   44     vocabs_ports.emplace_back(
VOCAB_AXIS,      &m_axisPort,      
"/axis");
 
   45     vocabs_ports.emplace_back(
VOCAB_STICK,     &m_stickPort,     
"/stick");
 
   46     vocabs_ports.emplace_back(
VOCAB_TRACKBALL, &m_trackballPort, 
"/trackballs");
 
   47     vocabs_ports.emplace_back(
VOCAB_TOUCH,     &m_touchPort,     
"/touch");
 
   48     vocabs_ports.emplace_back(
VOCAB_HAT,       &m_hatsPort,      
"/hat");
 
   50     for(
auto vocab_port : vocabs_ports)
 
   52         if(!getCount(get<0>(vocab_port), count)) 
return false;
 
   57             std::string portname = m_local + get<2>(vocab_port) + 
":i";
 
   58             get<1>(vocab_port)->valid = 
true;
 
   59             get<1>(vocab_port)->count = count;
 
   63                 for(
unsigned int i = 0; i < count; i++)
 
   65                     unsigned int dofCount;
 
   68                         yCError(JOYPADCONTROLCLIENT) << 
"Unable to get sticks DoF";
 
   71                     m_stickDof.push_back(dofCount);
 
   75             yCInfo(JOYPADCONTROLCLIENT) << 
"Opening" << portname;
 
   77             if(!get<1>(vocab_port)->contactable->open(portname))
 
   79                 yCError(JOYPADCONTROLCLIENT) << 
"Unable to open" << portname << 
"port";
 
   83             source      = m_remote + get<2>(vocab_port) + 
":o";
 
   84             destination = m_local  + get<2>(vocab_port) + 
":i";
 
   87                 yCError(JOYPADCONTROLCLIENT) << 
"Unable to connect" << portname << 
"port";
 
   91             get<1>(vocab_port)->useCallback();
 
  100     if(config.
check(
"help"))
 
  102         yCInfo(JOYPADCONTROLCLIENT) << 
"Parameter:\n\n" <<
 
  103                    "local  - prefix of the local port\n" <<
 
  104                    "remote - prefix of the port provided to and opened by JoypadControlServer\n";
 
  106     if(!config.
check(
"local"))
 
  108         yCError(JOYPADCONTROLCLIENT) << 
"Unable to 'local' parameter. check configuration file";
 
  114     if(!m_rpcPort.
open(m_local + 
"/rpc:o"))
 
  116         yCError(JOYPADCONTROLCLIENT) << 
"Unable to open rpc port.";
 
  120     yCInfo(JOYPADCONTROLCLIENT) << 
"rpc port opened. starting the handshake";
 
  122     if(!config.
check(
"remote"))
 
  124         yCError(JOYPADCONTROLCLIENT) << 
"Unable to find the 'remote' parameter. check configuration file";
 
  132         yCError(JOYPADCONTROLCLIENT) << 
"Handshake failed. unable to connect to remote port" << m_remote + 
"/rpc:i";
 
  136     yCInfo(JOYPADCONTROLCLIENT) << 
"Handshake succeeded! retrieving info";
 
  140         yCError(JOYPADCONTROLCLIENT) << 
"Unable to get joypad info.";
 
  155             port->onTimeout(0.5);
 
  160 bool JoypadControlClient::getCount(
const int& vocab_toget, 
unsigned int& value)
 
  167             value = m_buttonsPort.count;
 
  172             value = m_axisPort.count;
 
  176             value = m_trackballPort.count;
 
  181             value = m_touchPort.count;
 
  186             value = m_stickPort.count;
 
  191             value = m_hatsPort.count;
 
  204     m_rpcPort.
write(cmd, response);
 
  254     m_rpcPort.
write(cmd, response);
 
  277         m_rpcPort.
write(cmd, response);
 
  285             yCError(JOYPADCONTROLCLIENT) << 
"GetButton() error. VOCAB_FAILED";
 
  291         std::lock_guard<std::mutex> l(m_buttonsPort.mutex);
 
  292         if(button_id < m_buttonsPort.storage.size())
 
  294             value = m_buttonsPort.storage[button_id];
 
  299             yCError(JOYPADCONTROLCLIENT) << 
"GetButton() error. button_id out of bound";
 
  317         m_rpcPort.
write(cmd, response);
 
  331         std::lock_guard<std::mutex> l(m_trackballPort.mutex);
 
  332         if(trackball_id < m_trackballPort.storage.size() / 2)
 
  334             value.
push_back(m_trackballPort.storage[trackball_id * 2]);
 
  335             value.
push_back(m_trackballPort.storage[trackball_id * 2 + 1]);
 
  356         m_rpcPort.
write(cmd, response);
 
  369         std::lock_guard<std::mutex> l(m_hatsPort.mutex);
 
  370         if(hat_id < m_hatsPort.storage.size())
 
  372             value = m_hatsPort.storage[hat_id];
 
  393         m_rpcPort.
write(cmd, response);
 
  401             yCError(JOYPADCONTROLCLIENT) << 
"GetAxis() error. VOCAB_FAILED";
 
  407         std::lock_guard<std::mutex> l(m_axisPort.mutex);
 
  408         if(axis_id < m_axisPort.storage.size())
 
  410             value = m_axisPort.storage[axis_id];
 
  415             yCError(JOYPADCONTROLCLIENT) << 
"GetAxis() error. Axis_id out of bound";
 
  424     if(m_rpc_only || coordinate_mode == IJoypadController::JypCtrlcoord_POLAR)
 
  435         m_rpcPort.
write(cmd, response);
 
  451         m_rpcPort.
write(cmd, response);
 
  454             for(
int i = 0; i < dof; i++)
 
  474         std::lock_guard<std::mutex> l(m_stickPort.mutex);
 
  480             yCError(JOYPADCONTROLCLIENT) << 
"GetStick() error. Stick_id out of bound";
 
  483         for(
size_t j = 0; j < stick_id; j++)
 
  485             offset += m_stickDof[j];
 
  488         for(
size_t i = 0; i < m_stickDof[stick_id]; ++i)
 
  490             value.
push_back(m_stickPort.storage[offset + i]);
 
  509         m_rpcPort.
write(cmd, response);
 
  523         std::lock_guard<std::mutex> l(m_touchPort.mutex);
 
  524         if(touch_id < m_touchPort.storage.size()/2)
 
  526             value.
push_back(m_touchPort.storage[touch_id * 2]);
 
  527             value.
push_back(m_touchPort.storage[touch_id * 2 + 1]);
 
  540     vector<JoypadControl::LoopablePort*> portv;
 
  541     portv.push_back(&m_buttonsPort);
 
  542     portv.push_back(&m_axisPort);
 
  543     portv.push_back(&m_hatsPort);
 
  544     portv.push_back(&m_touchPort);
 
  545     portv.push_back(&m_trackballPort);
 
  546     portv.push_back(&m_stickPort);
 
  550         p->contactable->interrupt();
 
  551         p->contactable->close();
 
  
 
void close() override
Stop port activity.
JoypadCtrl_coordinateMode
bool getRawStickCount(unsigned int &stick_count) override
A simple collection of objects that can be described and transmitted in a portable way.
bool getStickCount(unsigned int &stick_count) override final
get the number of the sticks
virtual std::int32_t asVocab() const
Get vocabulary identifier as an integer.
A base class for nested structures that can be searched.
constexpr yarp::conf::vocab32_t VOCAB_STICKDOF
bool getRawStick(unsigned int stick_id, yarp::sig::Vector &value, JoypadCtrl_coordinateMode coordinate_mode) override
bool getRawTrackballCount(unsigned int &Trackball_count) override
#define YARP_LOG_COMPONENT(name,...)
constexpr yarp::conf::vocab32_t VOCAB_GET
bool getRawButton(unsigned int button_id, float &value) override
constexpr yarp::conf::vocab32_t VOCAB_TRACKBALL
bool getRawTouchSurfaceCount(unsigned int &touch_count) override
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
std::vector< JoypadControl::LoopablePort * > m_ports
void run() override
Loop function.
An interface for the device drivers.
bool getRawHatCount(unsigned int &Hat_count) override
constexpr yarp::conf::vocab32_t VOCAB_POLAR
bool close() override
Close the DeviceDriver.
constexpr yarp::conf::vocab32_t VOCAB_VALUE
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
constexpr yarp::conf::vocab32_t VOCAB_BUTTON
virtual bool isFloat64() const
Checks if value is a 64-bit floating point number.
bool getStickDoF(unsigned int stick_id, unsigned int &DoF) override final
Get the Degree Of Freedom count for desired stick.
bool getRawButtonCount(unsigned int &button_count) override
bool getRawAxisCount(unsigned int &axis_count) override
virtual std::string asString() const
Get string value.
bool getRawAxis(unsigned int axis_id, double &value) override
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
bool start()
Call this to start the thread.
bool getRawTouch(unsigned int touch_id, yarp::sig::Vector &value) override
constexpr yarp::conf::vocab32_t VOCAB_AXIS
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
constexpr yarp::conf::vocab32_t VOCAB_TOUCH
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
void addVocab(int x)
Places a vocabulary item in the bottle, at the end of the list.
constexpr yarp::conf::vocab32_t VOCAB_CARTESIAN
constexpr yarp::conf::vocab32_t VOCAB_HAT
#define yCError(component,...)
virtual std::int32_t asInt32() const
Get 32-bit integer value.
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
#define yCInfo(component,...)
An interface to the operating system, including Port based communication.
constexpr yarp::conf::vocab32_t VOCAB_COUNT
bool getRawHat(unsigned int hat_id, unsigned char &value) override
bool getRawStickDoF(unsigned int stick_id, unsigned int &DoF) override
constexpr yarp::conf::vocab32_t VOCAB_IJOYPADCTRL
constexpr yarp::conf::vocab32_t VOCAB_STICK
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
void push_back(const T &elem)
Push a new element in the vector: size is changed.
bool getRawTrackball(unsigned int trackball_id, yarp::sig::Vector &value) override
constexpr yarp::conf::vocab32_t VOCAB_OK
virtual bool isInt32() const
Checks if value is a 32-bit integer.