GamepadUnitObserver.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #include "GamepadUnitObserver.h"
25 
26 
31 
33 
35 
36 namespace armarx
37 {
39  {
40  usingTopic(getProperty<std::string>("GamepadTopicName").getValue());
41 
46 
47  offeringTopic(getProperty<std::string>("DebugDrawerTopic").getValue());
48  }
49 
50 
51 
53  {
54  debugDrawerPrx = getTopic<DebugDrawerInterfacePrx>(getProperty<std::string>("DebugDrawerTopic").getValue());
55  }
56 
57 
59  {
60  debugDrawerPrx->removePoseVisu("IMU", "orientation");
61  debugDrawerPrx->removeLineVisu("IMU", "acceleration");
62  }
63 
64 
66  {
68  }
69 
70  void GamepadUnitObserver::reportGamepadState(const std::string& device, const std::string& name, const GamepadData& data, const TimestampBasePtr& timestamp, const Ice::Current& c)
71  {
72  std::unique_lock lock(dataMutex);
73 
74  TimestampVariantPtr timestampPtr = TimestampVariantPtr::dynamicCast(timestamp);
75 
76  if (!existsChannel(device))
77  {
78  offerChannel(device, "Gamepad data");
79  }
80 
81  //ARMARX_IMPORTANT << deactivateSpam(1) << "observed " << device << " with name " << name;
82 
83  //axis
84  offerOrUpdateDataField(device, "leftStickX", Variant(data.leftStickX), "X value of the left analog stick");
85  offerOrUpdateDataField(device, "leftStickY", Variant(data.leftStickY), "Y value of the left analog stick");
86  offerOrUpdateDataField(device, "rightStickX", Variant(data.rightStickX), "X value of the right analog stick");
87  offerOrUpdateDataField(device, "rightStickY", Variant(data.rightStickY), "Y value of the right analog stick");
88  offerOrUpdateDataField(device, "dPadX", Variant(data.dPadX), "X value of the digital pad");
89  offerOrUpdateDataField(device, "dPadY", Variant(data.dPadY), "y value of the digital pad");
90  offerOrUpdateDataField(device, "leftTrigger", Variant(data.leftTrigger), "value of the left analog trigger");
91  offerOrUpdateDataField(device, "rightTrigger", Variant(data.rightTrigger), "value of the right analog trigger");
92  //buttons
93  offerOrUpdateDataField(device, "aButton", Variant(data.aButton), "A button pressed");
94  offerOrUpdateDataField(device, "backButton", Variant(data.backButton), "Back button pressed");
95  offerOrUpdateDataField(device, "bButton", Variant(data.bButton), "B button pressed");
96  offerOrUpdateDataField(device, "leftButton", Variant(data.leftButton), "Left shoulder button pressed");
97  offerOrUpdateDataField(device, "leftStickButton", Variant(data.leftStickButton), "Left stick button pressed");
98  offerOrUpdateDataField(device, "rightButton", Variant(data.rightButton), "Right shoulder button pressed");
99  offerOrUpdateDataField(device, "rightStickButton", Variant(data.rightStickButton), "Right stick button pressed");
100  offerOrUpdateDataField(device, "startButton", Variant(data.startButton), "Start button pressed");
101  offerOrUpdateDataField(device, "theMiddleButton", Variant(data.theMiddleButton), "The middle button pressed");
102  offerOrUpdateDataField(device, "xButton", Variant(data.xButton), "X button pressed");
103  offerOrUpdateDataField(device, "yButton", Variant(data.yButton), "Y button pressed");
104 
105  updateChannel(device);
106  }
107 }
108 
armarx::Observer::updateChannel
void updateChannel(const std::string &channelName, const std::set< std::string > &updatedDatafields=std::set< std::string >())
Update all conditions for a channel.
Definition: Observer.cpp:715
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::GamepadUnitObserverPropertyDefinitions
Definition: GamepadUnitObserver.h:40
armarx::GamepadUnitObserver::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: GamepadUnitObserver.cpp:65
armarx::GamepadUnitObserver::reportGamepadState
void reportGamepadState(const std::string &device, const std::string &name, const GamepadData &data, const TimestampBasePtr &timestamp, const Ice::Current &c) override
Definition: GamepadUnitObserver.cpp:70
ConditionCheckEquals.h
Pose.h
armarx::Observer::offerOrUpdateDataField
bool offerOrUpdateDataField(std::string channelName, std::string datafieldName, const Variant &value, const std::string &description)
Definition: Observer.cpp:222
GamepadUnitObserver.h
armarx::ConditionCheckSmaller
Definition: ConditionCheckSmaller.h:40
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::Observer::existsChannel
bool existsChannel(const std::string &channelName) const
Definition: Observer.cpp:1433
armarx::GamepadUnitObserver::onConnectObserver
void onConnectObserver() override
Framework hook.
Definition: GamepadUnitObserver.cpp:52
IceInternal::Handle< TimestampVariant >
armarx::GamepadUnitObserver::onInitObserver
void onInitObserver() override
Framework hook.
Definition: GamepadUnitObserver.cpp:38
armarx::GamepadUnitObserver::onExitObserver
void onExitObserver() override
Framework hook.
Definition: GamepadUnitObserver.cpp:58
armarx::ConditionCheckUpdated
Definition: ConditionCheckUpdated.h:41
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
TimestampVariant.h
armarx::ManagedIceObject::usingTopic
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
Definition: ManagedIceObject.cpp:248
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
ConditionCheckSmaller.h
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:290
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::ConditionCheckEquals
Definition: ConditionCheckEquals.h:46
armarx::Observer::offerConditionCheck
void offerConditionCheck(std::string checkName, ConditionCheck *conditionCheck)
Offer a condition check.
Definition: Observer.cpp:273
ConditionCheckLarger.h
armarx::ConditionCheckLarger
Definition: ConditionCheckLarger.h:40
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
ConditionCheckUpdated.h
armarx::Observer::offerChannel
void offerChannel(std::string channelName, std::string description)
Offer a channel.
Definition: Observer.cpp:126