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
34namespace 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
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");
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");
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
std::string timestamp()
constexpr T c
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
Checks if the numbers published in the relevant data fields equal a reference value.
Checks if the numbers published in the relevant data fields are larger than a reference value.
Checks if the numbers published in the relevant data fields are smaller than a reference value.
Checks if the relevant data fields have been updated since the installation of this condition.
void onConnectObserver() override
Framework hook.
void onExitObserver() override
Framework hook.
PropertyDefinitionsPtr createPropertyDefinitions() override
void onInitObserver() override
Framework hook.
void reportGamepadState(const std::string &device, const std::string &name, const GamepadData &data, const TimestampBasePtr &timestamp, const Ice::Current &c) override
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
bool existsChannel(const std::string &channelName) const
void offerChannel(std::string channelName, std::string description)
Offer a channel.
Definition Observer.cpp:131
void offerConditionCheck(std::string checkName, ConditionCheck *conditionCheck)
Offer a condition check.
Definition Observer.cpp:301
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
bool offerOrUpdateDataField(std::string channelName, std::string datafieldName, const Variant &value, const std::string &description)
Definition Observer.cpp:242
The Variant class is described here: Variants.
Definition Variant.h:224
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< TimestampVariant > TimestampVariantPtr