GamepadUnit.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotAPI::ArmarXObjects::GamepadUnit
17  * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu )
18  * @date 2017
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include<linux/joystick.h>
26 #include<sys/stat.h>
27 #include<fcntl.h>
29 
31 
34 
35 #include <RobotAPI/interface/units/GamepadUnit.h>
36 
37 #include "Joystick.h"
38 
39 namespace armarx
40 {
41  /**
42  * @class GamepadUnitPropertyDefinitions
43  * @brief
44  */
47  {
48  public:
51  {
52  //defineRequiredProperty<std::string>("PropertyName", "Description");
53  //defineOptionalProperty<std::string>("PropertyName", "DefaultValue", "Description");
54  defineOptionalProperty<std::string>("GamepadTopicName", "GamepadValues", "Name of the Gamepad Topic");
55  defineOptionalProperty<std::string>("GamepadDeviceName", "/dev/input/js2", "device that will be opened as a gamepad");
56  defineOptionalProperty<std::string>("GamepadForceFeedbackName", "", "device that will be used for force feedback, leave empty to disable. See RobotAPI/source/RobotAPI/drivers/GamepadUnit/README.md for more details.");
57  defineOptionalProperty<int>("PublishTimeout", 2000, "In Milliseconds. Timeout after which the gamepad data is not published after, if no new data was read from the gamepad");
58  }
59  };
60 
61  /**
62  * @defgroup Component-GamepadUnit GamepadUnit
63  * @ingroup RobotAPI-Components
64  * A description of the component GamepadUnit.
65  *
66  * @class GamepadUnit
67  * @ingroup Component-GamepadUnit
68  * @brief Brief description of class GamepadUnit.
69  *
70  * Detailed description of class GamepadUnit.
71  */
72  class GamepadUnit :
73  virtual public armarx::Component,
74  virtual public GamepadUnitInterface
75  {
76  public:
77  /**
78  * @see armarx::ManagedIceObject::getDefaultName()
79  */
80  std::string getDefaultName() const override
81  {
82  return "GamepadUnit";
83  }
84 
85  protected:
86  /**
87  * @see armarx::ManagedIceObject::onInitComponent()
88  */
89  void onInitComponent() override;
90 
91  /**
92  * @see armarx::ManagedIceObject::onConnectComponent()
93  */
94  void onConnectComponent() override;
95 
96  /**
97  * @see armarx::ManagedIceObject::onDisconnectComponent()
98  */
99  void onDisconnectComponent() override;
100 
101  /**
102  * @see armarx::ManagedIceObject::onExitComponent()
103  */
104  void onExitComponent() override;
105 
106  /**
107  * @see PropertyUser::createPropertyDefinitions()
108  */
110 
111  bool openGamepadConnection();
112 
113  void vibrate(const ::Ice::Current& = ::Ice::emptyCurrent) override;
114 
115  private:
116  GamepadUnitListenerPrx topicPrx;
119 
120  void run();
121  std::mutex mutex;
122  std::string deviceName;
123  std::string deviceEventName;
124  Joystick js;
125  GamepadData data;
126  TimestampVariantPtr dataTimestamp;
127  };
128 }
armarx::GamepadUnit::getDefaultName
std::string getDefaultName() const override
Definition: GamepadUnit.h:80
armarx::GamepadUnit::onDisconnectComponent
void onDisconnectComponent() override
Definition: GamepadUnit.cpp:172
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
RunningTask.h
armarx::GamepadUnit::onExitComponent
void onExitComponent() override
Definition: GamepadUnit.cpp:188
IceInternal::Handle< TimestampVariant >
armarx::GamepadUnit::vibrate
void vibrate(const ::Ice::Current &=::Ice::emptyCurrent) override
Definition: GamepadUnit.cpp:80
TimestampVariant.h
armarx::GamepadUnitPropertyDefinitions::GamepadUnitPropertyDefinitions
GamepadUnitPropertyDefinitions(std::string prefix)
Definition: GamepadUnit.h:49
armarx::GamepadUnit::onConnectComponent
void onConnectComponent() override
Definition: GamepadUnit.cpp:41
TaskUtil.h
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::GamepadUnit::onInitComponent
void onInitComponent() override
Definition: GamepadUnit.cpp:32
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::GamepadUnit::openGamepadConnection
bool openGamepadConnection()
Definition: GamepadUnit.cpp:86
Joystick.h
armarx::Joystick
Definition: Joystick.h:39
armarx::GamepadUnit::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: GamepadUnit.cpp:193
armarx::GamepadUnitPropertyDefinitions
Definition: GamepadUnit.h:45
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::GamepadUnit
Brief description of class GamepadUnit.
Definition: GamepadUnit.h:72
armarx::SimplePeriodicTask
Usage:
Definition: ApplicationNetworkStats.h:32