YARP
Yet Another Robot Platform
JoypadControlServer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #include "JoypadControlServer.h"
10 #include <map>
11 #include <vector>
12 #include <yarp/os/LogComponent.h>
13 #include <yarp/os/LogStream.h>
14 
15 #define DEFAULT_THREAD_PERIOD 0.010 //s
16 
17 using namespace std;
18 using namespace yarp::dev;
19 using namespace yarp::os;
20 using namespace yarp::sig;
21 
22 namespace {
23 YARP_LOG_COMPONENT(JOYPADCONTROLSERVER, "yarp.device.JoypadControlServer")
24 }
25 
26 
28 
29 inline void cat(Vector& a, const Vector& b)
30 {
31  for (size_t i = 0; i < b.size(); i++)
32  {
33  a.push_back(b[i]);
34  }
35 }
36 
38 {
39  bool ret;
40  if(interface)
41  {
42  device = interface;
43  ret = true;
44  }
45  else
46  {
47  device = nullptr;
48  ret = false;
49  }
50 
51  countGetters.insert(make_pair(VOCAB_BUTTON, &IJoypadController::getButtonCount));
52  countGetters.insert(make_pair(VOCAB_HAT, &IJoypadController::getHatCount));
53  countGetters.insert(make_pair(VOCAB_TRACKBALL, &IJoypadController::getTrackballCount));
54  countGetters.insert(make_pair(VOCAB_AXIS, &IJoypadController::getAxisCount));
55  countGetters.insert(make_pair(VOCAB_STICK, &IJoypadController::getStickCount));
56  countGetters.insert(make_pair(VOCAB_TOUCH, &IJoypadController::getTouchSurfaceCount));
57 
58  return ret;
59 }
60 
62 {
63  bool ret;
64 
65  ret = false;
66  if(cmd.get(0).asVocab() != VOCAB_IJOYPADCTRL || !cmd.get(1).isVocab() || !cmd.get(2).isVocab() || !cmd.get(3).isVocab())
67  {
68  response.addVocab(VOCAB_FAILED);
69  return ret;
70  }
71 
72  if(cmd.get(1).asVocab() == VOCAB_GET)
73  {
74  int toGet;
75 
76  toGet = cmd.get(2).asVocab();
77 
78  if(cmd.get(3).asVocab() == VOCAB_COUNT)
79  {
80  if(countGetters.find(toGet) != countGetters.end())
81  {
82  unsigned int count;
83  getcountmethod getter;
84  getter = countGetters[toGet];
85  if((device->*getter)(count))
86  {
87  response.addVocab(VOCAB_OK);
88  response.addInt32(count);
89  ret = true;
90  }
91  }
92  else if (toGet == VOCAB_STICKDOF && cmd.get(4).isInt32())
93  {
94  unsigned int count;
95  if (device->getStickDoF(cmd.get(4).asInt32(), count))
96  {
97  response.addVocab(VOCAB_OK);
98  response.addInt32(count);
99  ret = true;
100  }
101  else
102  {
103  response.addVocab(VOCAB_FAILED);
104  ret = false;
105  }
106  }
107  else
108  {
109  response.addVocab(VOCAB_FAILED);
110  ret = false;
111  }
112  }
113  else if(cmd.get(3).asVocab() == VOCAB_VALUE)
114  {
115  switch (cmd.get(2).asVocab()) {
116  case VOCAB_BUTTON:
117  {
118  float value;
119  if(cmd.get(4).isInt32() && device->getButton(cmd.get(4).asInt32(), value))
120  {
121  response.addVocab(VOCAB_OK);
122  response.addFloat64(value);
123  ret = true;
124  }
125  break;
126  }
127  case VOCAB_AXIS:
128  {
129  double value;
130  if(cmd.get(4).isInt32() && device->getAxis(cmd.get(4).asInt32(), value))
131  {
132  response.addVocab(VOCAB_OK);
133  response.addFloat64(value);
134  ret = true;
135  }
136  break;
137  }
138  case VOCAB_STICK:
139  {
140  if(cmd.get(4).isVocab())
141  {
142  yarp::sig::Vector frame;
143 
145  if(cmd.get(5).isInt32() && device->getStick(cmd.get(5).asInt32(), frame, mode))
146  {
147  response.addVocab(VOCAB_OK);
148  for(size_t i = 0; i < frame.size(); ++i)
149  {
150  response.addFloat64(frame[i]);
151  }
152 
153  ret = true;
154  }
155  }
156  break;
157  }
158  case VOCAB_STICKDOF:
159  {
160 
161  unsigned int dofCount;
162 
163  if(cmd.get(5).isInt32() && device->getStickDoF(cmd.get(5).asInt32(), dofCount))
164  {
165  response.addVocab(VOCAB_OK);
166  response.addInt32(dofCount);
167  ret = true;
168  }
169 
170  break;
171  }
172  case VOCAB_TOUCH:
173  {
174  yarp::sig::Vector pos;
175  unsigned int id;
176 
177  id = cmd.get(4).asInt32();
178  if(cmd.get(4).isInt32() && device->getTouch(id, pos))
179  {
180  response.addVocab(VOCAB_OK);
181  for(size_t i = 0; i < pos.size(); ++i)
182  {
183  response.addFloat64(pos[i]);
184  }
185  ret = true;
186  }
187  break;
188  }
189  case VOCAB_TRACKBALL:
190  {
191  yarp::sig::Vector axes;
192  unsigned int id;
193 
194  id = cmd.get(4).asInt32();
195  if(cmd.get(4).isInt32() && device->getTrackball(id, axes))
196  {
197  response.addVocab(VOCAB_OK);
198  for(size_t i = 0; i < axes.size(); ++i)
199  {
200  response.addFloat64(axes[i]);
201  }
202  ret = true;
203  }
204  break;
205  }
206  case VOCAB_HAT:
207  {
208  unsigned char value;
209  if(cmd.get(4).isInt32() && device->getHat(cmd.get(4).asInt32(), value))
210  {
211  response.addVocab(VOCAB_OK);
212  response.addInt32(value);
213  ret = true;
214  }
215  break;
216  }
217  default:
218  break;
219  }
220  }
221  }
222  return ret;
223 
224 }
225 
226 
228  m_period(DEFAULT_THREAD_PERIOD),
229  m_device(nullptr),
230  m_subDeviceOwned(nullptr),
231  m_isSubdeviceOwned(false),
232  m_separatePorts(false),
233  m_profile(false),
234  m_coordsMode(yarp::dev::IJoypadController::JoypadCtrl_coordinateMode::JypCtrlcoord_POLAR)
235 {
236 
237 }
238 
240 {
241  if(m_subDeviceOwned)
242  {
243  delete m_subDeviceOwned;
244  }
245  m_subDeviceOwned = nullptr;
246  m_device = nullptr;
247 }
248 
250 {
251  if(params.check("help"))
252  {
253  yCInfo(JOYPADCONTROLSERVER)
254  << "parameters:\n\n"
255  << "period - refresh period of the broadcasted values in ms.. default" << DEFAULT_THREAD_PERIOD * 1000 << "\n"
256  << "use_separate_ports - set it to 1 to use separate ports (buttons, axes, trackballs, hats) and 0 to stream all in one single port\n"
257  << "name - Prefix name of the ports opened by the JoypadControlServer, e.g. /robotName/joypad\n"
258  << "subdevice - name of the subdevice to open\n"
259  << "profile - print the joypad data for debugging purpose";
260  return false;
261  }
262  std::string rootName;
263  if (!params.check("period", "refresh period of the broadcasted values in ms"))
264  {
265  yCInfo(JOYPADCONTROLSERVER) << "Using default 'period' parameter of" << DEFAULT_THREAD_PERIOD << "s";
266  }
267  else
268  {
269  m_period = params.find("period").asInt32() / 1000.0;
270  }
271 
272  m_profile = params.check("profile");
273 
274  if(params.check("use_separate_ports"))
275  {
276  m_separatePorts = params.find("use_separate_ports").asBool();
277  if(!m_separatePorts)
278  {
279  yCError(JOYPADCONTROLSERVER) << "Single port mode not supported at the moment";
280  return false;
281  }
282  }
283  else
284  {
285  yCError(JOYPADCONTROLSERVER) << "Missing use_separate_ports in configuration";
286  return false;
287  }
289  rootName = params.check("name",Value("/"), "starting '/' if needed.").asString();
290 
291  if (!params.check("name", "Prefix name of the ports opened by the JoypadControlServer."))
292  {
293  yCError(JOYPADCONTROLSERVER) << "Missing 'name' parameter. Check you configuration file; it must be like:";
294  yCError(JOYPADCONTROLSERVER) << " name: Prefix name of the ports opened by the JoypadControlServer, e.g. /robotName/joypad";
295  return false;
296  }
297 
298  rootName = params.find("name").asString();
299  m_rpcPortName = rootName + "/rpc:i";
300  m_portButtons.name = rootName + "/buttons:o";
301  m_portAxis.name = rootName + "/axis:o";
302  m_portStick.name = rootName + "/stick:o";
303  m_portTouch.name = rootName + "/touch:o";
304  m_portTrackball.name = rootName + "/trackball:o";
305  m_portHats.name = rootName + "/hat:o";
306 
307 
308  // check if we need to create subdevice or if they are
309  // passed later on thorugh attachAll()
310  if(params.check("subdevice"))
311  {
312  m_isSubdeviceOwned=true;
313  if(!openAndAttachSubDevice(params))
314  {
315  yCError(JOYPADCONTROLSERVER) << "Error while opening subdevice";
316  return false;
317  }
318  }
319  else
320  {
321  m_isSubdeviceOwned=false;
322  }
323  return true;
324 }
325 
326 bool JoypadControlServer::openAndAttachSubDevice(Searchable& prop)
327 {
328  Property p;
329 
330  m_subDeviceOwned = new PolyDriver;
331 
332  p.fromString(prop.toString());
333  p.setMonitor(prop.getMonitor(), "subdevice"); // pass on any monitoring
334  p.unput("device");
335  p.put("device",prop.find("subdevice").asString()); // subdevice was already checked before
336 
337  // if errors occurred during open, quit here.
338  m_subDeviceOwned->open(p);
339 
340  if (!m_subDeviceOwned->isValid())
341  {
342  yCError(JOYPADCONTROLSERVER) << "Opening subdevice... FAILED";
343  return false;
344  }
345  m_isSubdeviceOwned = true;
346  if(!attach(m_subDeviceOwned))
347  return false;
348 
349  if(!m_parser.configure(m_device) )
350  {
351  yCError(JOYPADCONTROLSERVER) << "Error configuring interfaces for parsers";
352  return false;
353  }
354 
355  openPorts();
356  PeriodicThread::setPeriod(m_period);
357  return PeriodicThread::start();
358 }
359 
361 {
362  if(poly)
363  poly->view(m_device);
364 
365  if(m_device == nullptr)
366  {
367  yCError(JOYPADCONTROLSERVER) << "Attached device has no valid IJoypadController interface.";
368  return false;
369  }
370  return true;
371 }
372 
374 {
375  if(s == nullptr)
376  {
377  yCError(JOYPADCONTROLSERVER) << "Attached device has no valid IJoystickController interface.";
378  return false;
379  }
380  m_device = s;
381  return true;
382 }
383 
385 {
386  m_device = nullptr;
387  return true;
388 }
389 
391 {
392  // Get interface from attached device if any.
393  return true;
394 }
395 
397 {
398  // Detach() calls stop() which in turns calls this functions, therefore no calls to detach here!
399 }
400 
401 bool JoypadControlServer::openPorts()
402 {
403  if(!m_device)
404  {
405  return false;
406  }
407 
408  if(!m_rpcPort.open(m_rpcPortName))
409  {
410  yCError(JOYPADCONTROLSERVER) << "Unable to open rpc Port" << m_rpcPortName.c_str();
411  return false;
412  }
413  m_rpcPort.setReader(m_parser);
414 // dumb(or K.I.S.S.) version of the method:
415 // unsigned int count;
416 // if(m_device->getAxisCount(count))
417 // {
418 // if(count == 0)
419 // {
420 // m_portAxis.valid = false;
421 // }
422 // else
423 // {
424 // m_portAxis.open();
425 // m_portAxis.valid = true;
426 // }
427 // }
428 // else
429 // {
430 // return false;
431 // }
432 //
433 // if(m_device->getButtonCount(count))
434 // {
435 // if(count == 0)
436 // {
437 // m_portButton.valid = false;
438 // }
439 // else
440 // {
441 // m_portButton.open();
442 // m_portButton.valid = true;
443 // }
444 // }
445 // else
446 // {
447 // return false;
448 // }
449 //
450 // if(m_device->getStickCount(count))
451 // {
452 // if(count == 0)
453 // {
454 // m_portStick.valid = false;
455 // }
456 // else
457 // {
458 // m_portStick.open();
459 // m_portStick.valid = true;
460 // }
461 // }
462 // else
463 // {
464 // return false;
465 // }
466 //
467 // if(m_device->getTouchSurfaceCount(count))
468 // {
469 // if(count == 0)
470 // {
471 // m_portTouch.valid = false;
472 // }
473 // else
474 // {
475 // m_portTouch.open();
476 // m_portTouch.valid = true;
477 // }
478 // }
479 // else
480 // {
481 // return false;
482 // }
483 // if(m_device->getTrackballCount(count))
484 // {
485 // if(count == 0)
486 // {
487 // m_portTrackball.valid = false;
488 // }
489 // else
490 // {
491 // m_portTrackball.open();
492 // m_portTrackball.valid = true;
493 // }
494 // }
495 // else
496 // {
497 // return false;
498 // }
499 //
500 // if(m_device->getHatCount(count))
501 // {
502 // if(count == 0)
503 // {
504 // m_portHats.valid = false;
505 // }
506 // else
507 // {
508 // m_portHats.open();
509 // m_portHats.valid = true;
510 // }
511 // }
512 // else
513 // {
514 // return false;
515 // }
516 // return true;
517  if(m_separatePorts)
518  {
519  using countGet = bool (IJoypadController::*)(unsigned int&);
520 
521  struct solver
522  {
523  countGet getter;
525 
526  solver(countGet a, JoypadControl::LoopablePort* b) : getter(a), port(b)
527  {}
528  };
529 
530  vector<solver> getters;
531 
532  getters.emplace_back(&IJoypadController::getAxisCount, &m_portAxis );
533  getters.emplace_back(&IJoypadController::getButtonCount, &m_portButtons );
534  getters.emplace_back(&IJoypadController::getStickCount, &m_portStick );
535  getters.emplace_back(&IJoypadController::getTouchSurfaceCount, &m_portTouch );
536  getters.emplace_back(&IJoypadController::getTrackballCount, &m_portTrackball);
537  getters.emplace_back(&IJoypadController::getHatCount, &m_portHats );
538 
539  for(auto& getter : getters)
540  {
541  if((m_device->*(getter.getter))(getter.port->count))
542  {
543  if(getter.port->count == 0)
544  {
545  getter.port->valid = false;
546  }
547  else
548  {
549  getter.port->contactable->open(getter.port->name);
550  getter.port->valid = true;
551  }
552  }
553  else
554  {
555  return false;
556  }
557  }
558 
559  return true;
560  }
561  else
562  {
563  return false;
564  //m_godPort.open(m_name + "/joydata:o");
565  }
566 }
567 
568 void JoypadControlServer::profile()
569 {
570  string message;
571  unsigned int count;
572 
573  message = "Axes: ";
574  m_device->getAxisCount(count);
575  for(unsigned int i = 0; i < count; ++i)
576  {
577  double data;
578  m_device->getAxis(i, data);
579  message += to_string(data) + " ";
580  }
581  yCInfo(JOYPADCONTROLSERVER) << message;
582 
583  message = "Hats: ";
584  m_device->getHatCount(count);
585  for(unsigned int i = 0; i < count; ++i)
586  {
587  unsigned char data;
588  m_device->getHat(i, data);
589  message += to_string(data) + " ";
590  }
591  yCInfo(JOYPADCONTROLSERVER) << message;
592 
593  message = "Buttons: ";
594  m_device->getButtonCount(count);
595  for(unsigned int i = 0; i < count; ++i)
596  {
597  float data;
598  m_device->getButton(i, data);
599  message += to_string(data) + " ";
600  }
601  yCInfo(JOYPADCONTROLSERVER) << message;
602 
603  message = "Stick: ";
604  m_device->getStickCount(count);
605  for(unsigned int i = 0; i < count; ++i)
606  {
607  Vector data;
609  message += "n_" + to_string(i) + ": ";
610  for (size_t j = 0; j < data.size(); ++j)
611  {
612  message += to_string(data[j]) + " ";
613  }
614  message += "\n";
615 
616  }
617  yCInfo(JOYPADCONTROLSERVER) << message;
618 
619  message = "trackball: ";
620  m_device->getTrackballCount(count);
621  for(unsigned int i = 0; i < count; ++i)
622  {
623  Vector data;
624  m_device->getTrackball(i, data);
625  message += "n_" + to_string(i) + ": ";
626  for (size_t j = 0; j < data.size(); ++j)
627  {
628  message += to_string(data[j]) + " ";
629  }
630  message += "\n";
631  }
632 
633  message = "touch Surface: ";
634  m_device->getTouchSurfaceCount(count);
635  for(unsigned int i = 0; i < count; ++i)
636  {
637  Vector data;
638  m_device->getTouch(i, data);
639  message += "n_" + to_string(i) + ": ";
640  for (size_t j = 0; j < data.size(); ++j)
641  {
642  message += to_string(data[j]) + " ";
643  }
644  message += "\n";
645  }
646  yCInfo(JOYPADCONTROLSERVER) << message;
647 }
648 
650 {
651  if(m_separatePorts)
652  {
653  if (m_portButtons.valid)
654  {
655  bool write;
656  write = true;
657  Vector& b = m_portButtons.prepare();
658  b.clear();
659  for(size_t i = 0; i < m_portButtons.count; ++i)
660  {
661  float v;
662  if(!m_device->getButton(i, v))
663  {
664  write = false;
665  break;
666  }
667  b.push_back(v);
668  }
669  if(write)m_portButtons.write();
670  }
671 
672  if (m_portHats.valid)
673  {
674  bool write;
675 
676  write = true;
677  VecOfChar& b = m_portHats.prepare();
678  b.clear();
679  for(size_t i = 0; i < m_portHats.count; ++i)
680  {
681  unsigned char v;
682  if(!m_device->getHat(i, v))
683  {
684  write = false;
685  break;
686  }
687  b.push_back(v);
688  }
689  if(write)m_portHats.write();
690  }
691 
692  if (m_portAxis.valid)
693  {
694  bool write;
695 
696  write = true;
697  Vector& b = m_portAxis.prepare();
698  b.clear();
699  for(size_t i = 0; i < m_portAxis.count; ++i)
700  {
701  double v;
702  if(!m_device->getAxis(i, v))
703  {
704  yCError(JOYPADCONTROLSERVER) << "Cannot get axis with id" << i;
705  write = false;
706  break;
707  }
708  b.push_back(v);
709  }
710  if(write)m_portAxis.write();
711  }
712 
713  if (m_portTrackball.valid)
714  {
715  bool write;
716 
717  write = true;
718  Vector& b = m_portTrackball.prepare();
719  b.clear();
720  for(size_t i = 0; i < m_portTrackball.count; ++i)
721  {
722  Vector v;
723  if(!m_device->getTrackball(i, v))
724  {
725  yCError(JOYPADCONTROLSERVER) << "Cannot get axis with id" << i;
726  write = false;
727  break;
728  }
729  cat(b, v);
730  }
731  if(write)m_portTrackball.write();
732  }
733 
734  if (m_portStick.valid)
735  {
736  bool write;
737  write = true;
738  Vector& b = m_portStick.prepare();
739  b.clear();
740  for(size_t i = 0; i < m_portStick.count; ++i)
741  {
742  Vector v;
743  unsigned int dofCount;
744  if(!m_device->getStick(i, v, m_coordsMode) || !m_device->getStickDoF(i, dofCount) || v.size() != dofCount)
745  {
746  write = false;
747  break;
748  }
749  cat(b, v);
750  }
751  if(write)m_portStick.write();
752  }
753 
754  if (m_portTouch.valid)
755  {
756  bool write;
757  write = true;
758  Vector& b = m_portTouch.prepare();
759  b.clear();
760  for(unsigned int i = 0; i < m_portTouch.count; ++i)
761  {
762  Vector v;
763  if(!m_device->getTouch(i, v))
764  {
765  write = false;
766  break;
767  }
768  cat(b, v);
769  }
770 
771  if(write)m_portTouch.write();
772  }
773  }
774  else
775  {
776  return;
777  //JoyData& message = m_godPort.prepare();
778  //for(size_t i = 0; i < m_device->getAxisCount();)
779  //message.Axes
780  }
781 
782  if(m_profile)
783  {
784  profile();
785  }
786 }
787 
789 {
790  if (p.size() != 1)
791  {
792  yCError(JOYPADCONTROLSERVER) << "Cannot attach more than one device";
793  return false;
794  }
795 
796  yarp::dev::PolyDriver* Idevice2attach = p[0]->poly;
797  if(p[0]->key == "IJoypadController")
798  {
799  yCInfo(JOYPADCONTROLSERVER) << "Good name!";
800  }
801  else
802  {
803  yCInfo(JOYPADCONTROLSERVER) << "Bad name!";
804  }
805 
806  if (!Idevice2attach->isValid())
807  {
808  yCError(JOYPADCONTROLSERVER) << "Device " << p[0]->key << " to attach to is not valid ... cannot proceed";
809  return false;
810  }
811 
812  Idevice2attach->view(m_device);
813  if(!attach(m_device))
814  return false;
815 
816  PeriodicThread::setPeriod(m_period);
817  if (!PeriodicThread::start())
818  return false;
819 
820  openPorts();
821  return true;
822 }
823 
825 {
828 
829  //check if we already instantiated a subdevice previously
830  if (m_isSubdeviceOwned)
831  return false;
832 
833  m_device = nullptr;
834  return true;
835 }
836 
838 {
839  detachAll();
840 
841  // close subdevice if it was created inside the open (--subdevice option)
842  if(m_isSubdeviceOwned)
843  {
844  if(m_subDeviceOwned)m_subDeviceOwned->close();
845 
846  m_subDeviceOwned = nullptr;
847  m_device = nullptr;
848  m_isSubdeviceOwned = false;
849  }
850 
851  // Closing port
852  vector<JoypadControl::LoopablePort*> portv;
853  portv.push_back(&m_portButtons);
854  portv.push_back(&m_portAxis);
855  portv.push_back(&m_portStick);
856  portv.push_back(&m_portTouch);
857  portv.push_back(&m_portTrackball);
858  portv.push_back(&m_portHats);
859 
860  for(auto p : portv)
861  {
862  //p->contactable->interrupt();
863  p->contactable->close();
864  }
865 
866  m_rpcPort.close();
867  return true;
868 }
yarp::os::Port::close
void close() override
Stop port activity.
Definition: Port.cpp:357
LogStream.h
JoypadControl::LoopablePort
Definition: JoypadControlNetUtils.h:32
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
yarp::os::Value::asVocab
virtual std::int32_t asVocab() const
Get vocabulary identifier as an integer.
Definition: Value.cpp:231
yarp::os::Property::put
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition: Property.cpp:998
yarp::dev::IJoypadController::getTrackballCount
virtual bool getTrackballCount(unsigned int &Trackball_count)=0
Get number of trackballs.
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
VOCAB_STICKDOF
constexpr yarp::conf::vocab32_t VOCAB_STICKDOF
Definition: IJoypadController.h:294
yarp::sig
Signal processing.
Definition: Image.h:25
JoypadControlServer::detachAll
bool detachAll() override
Detach the object (you must have first called attach).
Definition: JoypadControlServer.cpp:824
yarp::dev::IJoypadController::getAxis
virtual bool getAxis(unsigned int axis_id, double &value)=0
Get the value of an axis if present, return false otherwise.
yarp::os::Searchable::toString
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
yarp::os::Property::fromString
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
Definition: Property.cpp:1046
yarp::dev::IJoypadController::getAxisCount
virtual bool getAxisCount(unsigned int &axis_count)=0
Get number of Axes.
yarp::dev::PolyDriverList::size
int size() const
Definition: PolyDriverList.cpp:39
yarp::dev::PolyDriver::isValid
bool isValid() const
Check if device is valid.
Definition: PolyDriver.cpp:199
YARP_LOG_COMPONENT
#define YARP_LOG_COMPONENT(name,...)
Definition: LogComponent.h:80
yarp::dev::IJoypadController::getButtonCount
virtual bool getButtonCount(unsigned int &button_count)=0
Get number of Buttons.
VOCAB_GET
constexpr yarp::conf::vocab32_t VOCAB_GET
Definition: GenericVocabs.h:16
yarp::dev::IJoypadController::JypCtrlcoord_POLAR
@ JypCtrlcoord_POLAR
Definition: IJoypadController.h:37
VOCAB_TRACKBALL
constexpr yarp::conf::vocab32_t VOCAB_TRACKBALL
Definition: IJoypadController.h:290
JoypadControlServer::detach
bool detach() override
Detach the object (you must have first called attach).
Definition: JoypadControlServer.cpp:384
yarp::dev::DeviceDriver::view
bool view(T *&x)
Get an interface to the device driver.
Definition: DeviceDriver.h:77
yarp::dev::IJoypadController::getTouchSurfaceCount
virtual bool getTouchSurfaceCount(unsigned int &touch_count)=0
get the number of touch surface.
yarp::os::Port::open
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition: Port.cpp:82
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
yarp::sig::VectorOf::clear
void clear()
Definition: Vector.h:521
yarp::dev::IJoypadController::getStickDoF
virtual bool getStickDoF(unsigned int stick_id, unsigned int &DoF)=0
Get the Degree Of Freedom count for desired stick.
JoypadControlServer::~JoypadControlServer
~JoypadControlServer() override
Definition: JoypadControlServer.cpp:239
yarp::dev::PolyDriverList
Definition: PolyDriverList.h:22
yarp::os::Bottle::addFloat64
void addFloat64(yarp::conf::float64_t x)
Places a 64-bit floating point number in the bottle, at the end of the list.
Definition: Bottle.cpp:161
yarp::dev::PolyDriver::open
bool open(const std::string &txt)
Construct and configure a device by its common name.
Definition: PolyDriver.cpp:143
JoypadControlServer::attachAll
bool attachAll(const yarp::dev::PolyDriverList &p) override
Attach to a list of objects.
Definition: JoypadControlServer.cpp:788
yarp::os::PeriodicThread::isRunning
bool isRunning() const
Returns true when the thread is started, false otherwise.
Definition: PeriodicThread.cpp:316
yarp::dev
An interface for the device drivers.
Definition: audioBufferSizeData.cpp:17
JoypadControlServer.h
yarp::sig::VectorOf
Provides:
Definition: Vector.h:122
yarp::dev::IJoypadController::getStickCount
virtual bool getStickCount(unsigned int &stick_count)=0
get the number of the sticks
VOCAB_VALUE
constexpr yarp::conf::vocab32_t VOCAB_VALUE
Definition: GenericVocabs.h:41
yarp::os::Bottle::get
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition: Bottle.cpp:249
VOCAB_BUTTON
constexpr yarp::conf::vocab32_t VOCAB_BUTTON
Definition: IJoypadController.h:289
yarp::os::Value::asBool
virtual bool asBool() const
Get boolean value.
Definition: Value.cpp:189
yarp::dev::IJoypadController::getButton
virtual bool getButton(unsigned int button_id, float &value)=0
Get the value of a button.
yarp::os::Value::asString
virtual std::string asString() const
Get string value.
Definition: Value.cpp:237
yarp::dev::PolyDriver
A container for a device driver.
Definition: PolyDriver.h:27
VOCAB_FAILED
constexpr yarp::conf::vocab32_t VOCAB_FAILED
Definition: GenericVocabs.h:19
JoypadCtrlParser::respond
bool respond(const yarp::os::Bottle &cmd, yarp::os::Bottle &response) override
Respond to a message.
Definition: JoypadControlServer.cpp:61
JoypadControlServer::open
bool open(yarp::os::Searchable &params) override
Open the DeviceDriver.
Definition: JoypadControlServer.cpp:249
yarp::dev::IJoypadController::getTouch
virtual bool getTouch(unsigned int touch_id, yarp::sig::Vector &value)=0
Get the value of a touch if present, return false otherwise.
yarp::dev::PolyDriver::close
bool close() override
Close the DeviceDriver.
Definition: PolyDriver.cpp:176
VOCAB_AXIS
constexpr yarp::conf::vocab32_t VOCAB_AXIS
Definition: IJoypadController.h:292
yarp::os::Searchable::check
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
VOCAB_TOUCH
constexpr yarp::conf::vocab32_t VOCAB_TOUCH
Definition: IJoypadController.h:295
yarp::os::Searchable::find
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
yarp::os::Bottle::addInt32
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
Definition: Bottle.cpp:143
JoypadCtrlParser::JoypadCtrlParser
JoypadCtrlParser()
Definition: JoypadControlServer.cpp:27
yarp::os::Port::setReader
void setReader(PortReader &reader) override
Set an external reader for port data.
Definition: Port.cpp:505
yarp::os::PeriodicThread
An abstraction for a periodic thread.
Definition: PeriodicThread.h:25
yarp::os::Bottle::addVocab
void addVocab(int x)
Places a vocabulary item in the bottle, at the end of the list.
Definition: Bottle.cpp:167
LogComponent.h
JoypadControlServer::attach
bool attach(yarp::dev::PolyDriver *poly) override
Attach to another object.
Definition: JoypadControlServer.cpp:360
JoypadControlServer::close
bool close() override
Close the DeviceDriver.
Definition: JoypadControlServer.cpp:837
VOCAB_CARTESIAN
constexpr yarp::conf::vocab32_t VOCAB_CARTESIAN
Definition: IJoypadController.h:297
VOCAB_HAT
constexpr yarp::conf::vocab32_t VOCAB_HAT
Definition: IJoypadController.h:291
JoypadControlServer::threadRelease
void threadRelease() override
Release method.
Definition: JoypadControlServer.cpp:396
JoypadControlServer::JoypadControlServer
JoypadControlServer()
Definition: JoypadControlServer.cpp:227
yarp::dev::IJoypadController::JypCtrlcoord_CARTESIAN
@ JypCtrlcoord_CARTESIAN
Definition: IJoypadController.h:37
yCError
#define yCError(component,...)
Definition: LogComponent.h:157
yarp::os::Value::asInt32
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition: Value.cpp:207
yCInfo
#define yCInfo(component,...)
Definition: LogComponent.h:135
JoypadControlServer::run
void run() override
Loop function.
Definition: JoypadControlServer.cpp:649
yarp::os
An interface to the operating system, including Port based communication.
Definition: AbstractCarrier.h:17
VOCAB_COUNT
constexpr yarp::conf::vocab32_t VOCAB_COUNT
Definition: GenericVocabs.h:40
yarp::dev::IJoypadController::getHat
virtual bool getHat(unsigned int hat_id, unsigned char &value)=0
Get the value of an Hat.
yarp::dev::IJoypadController::getStick
virtual bool getStick(unsigned int stick_id, yarp::sig::Vector &value, JoypadCtrl_coordinateMode coordinate_mode)=0
Get the value of a stick if present, return false otherwise.
JoypadCtrlParser::configure
bool configure(yarp::dev::IJoypadController *interface)
Definition: JoypadControlServer.cpp:37
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
cat
void cat(Vector &a, const Vector &b)
Definition: JoypadControlServer.cpp:29
yarp::os::PeriodicThread::stop
void stop()
Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() ca...
Definition: PeriodicThread.cpp:296
yarp::sig::VectorOf::size
size_t size() const
Definition: Vector.h:355
JoypadControlServer::threadInit
bool threadInit() override
Initialization method.
Definition: JoypadControlServer.cpp:390
VOCAB_IJOYPADCTRL
constexpr yarp::conf::vocab32_t VOCAB_IJOYPADCTRL
Definition: IJoypadController.h:287
yarp::dev::IJoypadController::getHatCount
virtual bool getHatCount(unsigned int &Hat_count)=0
Get number of Hats.
yarp::dev::IJoypadController::getTrackball
virtual bool getTrackball(unsigned int trackball_id, yarp::sig::Vector &value)=0
Get the axes change of a Trackball.
yarp::sig::file::write
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:971
yarp::os::Value
A single value (typically within a Bottle).
Definition: Value.h:47
VOCAB_STICK
constexpr yarp::conf::vocab32_t VOCAB_STICK
Definition: IJoypadController.h:293
yarp::os::Property::unput
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
Definition: Property.cpp:1029
DEFAULT_THREAD_PERIOD
#define DEFAULT_THREAD_PERIOD
Definition: JoypadControlServer.cpp:15
yarp::sig::VectorOf::push_back
void push_back(const T &elem)
Push a new element in the vector: size is changed.
Definition: Vector.h:282
yarp::dev::IJoypadController
Definition: IJoypadController.h:35
VOCAB_OK
constexpr yarp::conf::vocab32_t VOCAB_OK
Definition: GenericVocabs.h:18
yarp::os::Value::isVocab
virtual bool isVocab() const
Checks if value is a vocabulary identifier.
Definition: Value.cpp:177
yarp::os::Property
A class for storing options and configuration information.
Definition: Property.h:37
yarp::os::Value::isInt32
virtual bool isInt32() const
Checks if value is a 32-bit integer.
Definition: Value.cpp:135