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 
31 
33 
34 namespace armarx
35 {
36  void
38  {
39  usingTopic(getProperty<std::string>("GamepadTopicName").getValue());
40 
45 
46  offeringTopic(getProperty<std::string>("DebugDrawerTopic").getValue());
47  }
48 
49  void
51  {
52  debugDrawerPrx = getTopic<DebugDrawerInterfacePrx>(
53  getProperty<std::string>("DebugDrawerTopic").getValue());
54  }
55 
56  void
58  {
59  debugDrawerPrx->removePoseVisu("IMU", "orientation");
60  debugDrawerPrx->removeLineVisu("IMU", "acceleration");
61  }
62 
65  {
68  }
69 
70  void
71  GamepadUnitObserver::reportGamepadState(const std::string& device,
72  const std::string& name,
73  const GamepadData& data,
74  const TimestampBasePtr& timestamp,
75  const Ice::Current& c)
76  {
77  std::unique_lock lock(dataMutex);
78 
79  TimestampVariantPtr timestampPtr = TimestampVariantPtr::dynamicCast(timestamp);
80 
81  if (!existsChannel(device))
82  {
83  offerChannel(device, "Gamepad data");
84  }
85 
86  //ARMARX_IMPORTANT << deactivateSpam(1) << "observed " << device << " with name " << name;
87 
88  //axis
90  device, "leftStickX", Variant(data.leftStickX), "X value of the left analog stick");
92  device, "leftStickY", Variant(data.leftStickY), "Y value of the left analog stick");
94  device, "rightStickX", Variant(data.rightStickX), "X value of the right analog stick");
96  device, "rightStickY", Variant(data.rightStickY), "Y value of the right analog stick");
97  offerOrUpdateDataField(device, "dPadX", Variant(data.dPadX), "X value of the digital pad");
98  offerOrUpdateDataField(device, "dPadY", Variant(data.dPadY), "y value of the digital pad");
100  device, "leftTrigger", Variant(data.leftTrigger), "value of the left analog trigger");
101  offerOrUpdateDataField(device,
102  "rightTrigger",
103  Variant(data.rightTrigger),
104  "value of the right analog trigger");
105  //buttons
106  offerOrUpdateDataField(device, "aButton", Variant(data.aButton), "A button pressed");
108  device, "backButton", Variant(data.backButton), "Back button pressed");
109  offerOrUpdateDataField(device, "bButton", Variant(data.bButton), "B button pressed");
111  device, "leftButton", Variant(data.leftButton), "Left shoulder button pressed");
113  device, "leftStickButton", Variant(data.leftStickButton), "Left stick button pressed");
115  device, "rightButton", Variant(data.rightButton), "Right shoulder button pressed");
116  offerOrUpdateDataField(device,
117  "rightStickButton",
118  Variant(data.rightStickButton),
119  "Right stick button pressed");
121  device, "startButton", Variant(data.startButton), "Start button pressed");
123  device, "theMiddleButton", Variant(data.theMiddleButton), "The middle button pressed");
124  offerOrUpdateDataField(device, "xButton", Variant(data.xButton), "X button pressed");
125  offerOrUpdateDataField(device, "yButton", Variant(data.yButton), "Y button pressed");
126 
127  updateChannel(device);
128  }
129 } // namespace armarx
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:788
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:223
armarx::GamepadUnitObserverPropertyDefinitions
Definition: GamepadUnitObserver.h:41
armarx::GamepadUnitObserver::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: GamepadUnitObserver.cpp:64
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:71
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:242
GamepadUnitObserver.h
armarx::ConditionCheckSmaller
Definition: ConditionCheckSmaller.h:40
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::Observer::existsChannel
bool existsChannel(const std::string &channelName) const
Definition: Observer.cpp:1552
armarx::GamepadUnitObserver::onConnectObserver
void onConnectObserver() override
Framework hook.
Definition: GamepadUnitObserver.cpp:50
IceInternal::Handle< TimestampVariant >
armarx::GamepadUnitObserver::onInitObserver
void onInitObserver() override
Framework hook.
Definition: GamepadUnitObserver.cpp:37
armarx::GamepadUnitObserver::onExitObserver
void onExitObserver() override
Framework hook.
Definition: GamepadUnitObserver.cpp:57
armarx::ConditionCheckUpdated
Definition: ConditionCheckUpdated.h:41
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
TimestampVariant.h
timestamp
std::string timestamp()
Definition: CartographerAdapter.cpp:85
armarx::ManagedIceObject::usingTopic
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
Definition: ManagedIceObject.cpp:254
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
ConditionCheckSmaller.h
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:300
IceUtil::Handle
Definition: forward_declarations.h:30
armarx::ConditionCheckEquals
Definition: ConditionCheckEquals.h:46
armarx::Observer::offerConditionCheck
void offerConditionCheck(std::string checkName, ConditionCheck *conditionCheck)
Offer a condition check.
Definition: Observer.cpp:301
ConditionCheckLarger.h
armarx::ConditionCheckLarger
Definition: ConditionCheckLarger.h:40
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
ConditionCheckUpdated.h
armarx::Observer::offerChannel
void offerChannel(std::string channelName, std::string description)
Offer a channel.
Definition: Observer.cpp:131