Go to the documentation of this file.
28 #include <linux/joystick.h>
35 offeringTopic(getProperty<std::string>(
"GamepadTopicName").getValue());
36 deviceName = getProperty<std::string>(
"GamepadDeviceName").getValue();
37 deviceEventName = getProperty<std::string>(
"GamepadForceFeedbackName").getValue();
44 topicPrx = getTopic<GamepadUnitListenerPrx>(getProperty<std::string>(
"GamepadTopicName").getValue());
49 std::unique_lock lock(mutex);
61 const IceUtil::Time age = IceUtil::Time::now() - dataTimestamp->toTime();
62 if (age.toMilliSeconds() < getProperty<int>(
"PublishTimeout").getValue())
66 topicPrx->reportGamepadState(deviceName, js.
name, data, dataTimestamp);
71 ARMARX_INFO <<
deactivateSpam(100000,
std::to_string(dataTimestamp->getTimestamp())) <<
"No new signal from gamepad for " << age.toMilliSecondsDouble() <<
" milliseconds. Not sending data. Timeout: " << getProperty<int>(
"PublishTimeout").getValue() <<
" ms";
88 if (js.
open(deviceName, deviceEventName))
116 void GamepadUnit::run()
119 while (readTask->isRunning())
125 ARMARX_WARNING <<
"failed to read gamepad data - trying to reconnect";
134 std::unique_lock lock(mutex);
140 float axisFactor = 1.0f / 32768.f;
142 data.leftStickY = js.
axis[0] * axisFactor;
143 data.leftStickX = js.
axis[1] * axisFactor;
144 data.rightStickX = js.
axis[3] * axisFactor;
145 data.rightStickY = js.
axis[4] * axisFactor;
146 data.dPadX = js.
axis[7] * axisFactor;
147 data.dPadY = js.
axis[6] * axisFactor;
148 data.leftTrigger = js.
axis[2] * axisFactor;
149 data.rightTrigger = js.
axis[5] * axisFactor;
165 ARMARX_VERBOSE <<
"left x (integer): " << js.
axis[0] <<
" left x (float): " << data.leftStickX <<
" right trigger: " << data.rightTrigger;
bool open(std::string const &deviceName, std::string const &deviceEventName)
void onDisconnectComponent() override
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
void onExitComponent() override
void vibrate(const ::Ice::Current &=::Ice::emptyCurrent) override
void executeEffect(int gain=100, const int nTimes=1)
std::vector< bool > buttonsPressed
std::vector< int16_t > axis
void onConnectComponent() override
armarx::core::time::DateTime Time
const std::string & to_string(const std::string &s)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
void onInitComponent() override
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
bool openGamepadConnection()
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
This file offers overloads of toIce() and fromIce() functions for STL container types.