Skip to content

Commit

Permalink
Merge pull request #143 from robotology/haptic_trahapticGlove_transmi…
Browse files Browse the repository at this point in the history
…ssion_rec

Fix Haptic glove transmission - HapticGloveModule (Recovered PR)
  • Loading branch information
S-Dafarra authored Jun 25, 2024
2 parents afed05e + cec6912 commit 82d3dd9
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 72 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ build/

TAGS
compile_commands.json
CMakeLists.txt.user
CMakeLists.txt.user
.vscode/

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 14)

project(walking-teleoperation
VERSION 1.3.4)
VERSION 1.3.5)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(WalkingTeleoperationFindDependencies)
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/ergoCub-Teleoperation-2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parameters>--from openXRHeadsetParameters.ini</parameters>
<node>icub-virtualizer</node>
</module>

<module>
<name>yarp</name>
<parameters>repeat /depthCamera/repeated/rgbImage:o </parameters>
Expand Down
4 changes: 2 additions & 2 deletions cmake/WalkingTeleoperationFindDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ checkandset_dependency(CybSDK)
find_package(SRanipalSDK QUIET)
checkandset_dependency(SRanipalSDK)

find_package(IWear QUIET)
find_package(IWear 1.9.0 QUIET)
checkandset_dependency(IWear)

find_package(WearableActuators QUIET)
find_package(WearableActuators 1.9.0 QUIET)
checkandset_dependency(WearableActuators)


Expand Down
6 changes: 6 additions & 0 deletions modules/HapticGlove_module/include/GloveControlHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ class HapticGlove::GloveControlHelper
*/
bool getHandJointAngles(std::vector<double>& jointAngles);

/**
* Set the desired haptic feedback reference to the user fingertip
* @return true/false in case of success/failure
*/
bool sendFingertipHapticFeedbackReferences();

/**
* Set the desired force feedback reference to the user fingertip
* @param desiredValue desired force feedback values
Expand Down
14 changes: 12 additions & 2 deletions modules/HapticGlove_module/include/GloveWearable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <vector>
// wearable
#include <Wearable/IWear/IWear.h>
#include <thrift/WearableActuatorCommand.h>
#include <thrift/GloveActuatorCommand.h>
// YARP
#include <yarp/dev/PolyDriver.h>
#include <yarp/os/BufferedPort.h>
Expand Down Expand Up @@ -72,6 +72,8 @@ class HapticGlove::GloveWearableImpl
private:
std::string m_logPrefix;

const size_t m_numHapticFeedback; /**< Number of the motors to produce haptic feedback to the
human*/
const size_t m_numForceFeedback; /**< Number of the motors to produce force feedback to the
human*/
const size_t m_numVibrotactileFeedback; /**< Number of the vibrotactile to produce vibrotactile
Expand All @@ -83,7 +85,7 @@ class HapticGlove::GloveWearableImpl

wearable::IWear* m_iWear{nullptr}; /**< Sense glove wearable interface. */

BufferedPort<wearable::msg::WearableActuatorCommand> m_iWearActuatorPort;
BufferedPort<wearable::msg::GloveActuatorCommand> m_iWearGloveActuatorPort;

std::string m_handLinkName;

Expand Down Expand Up @@ -169,6 +171,14 @@ class HapticGlove::GloveWearableImpl
*/
bool getFingertipPoseValues(Eigen::MatrixXd& values);

/**
* set the Haptic feedback values associated with all the human hand fingertips
* @param values the vector of force and vibrotactile feedback values to the human fingertips, from thumb to
* pinky, range: [0, 100]
* @return true/false in case of success/failure
*/
bool setFingertipHapticFeedbackValues(const std::vector<int>& forceValues, const std::vector<int>& vibroValues);

/**
* set the force feedback actuator values associated with all the human hand fingertips
* @param values the vector of force feedback values to the human fingertips, from thumb to
Expand Down
3 changes: 3 additions & 0 deletions modules/HapticGlove_module/include/Teleoperation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ struct HapticGlove::Data
std::vector<double> humanJointValues; /// <summary> juman joint values
Eigen::MatrixXd humanFingertipPoses; /// <summary> human fingertip poses (size: number of hand
/// fingertips (i.e., 5) x 7)
std::vector<double>
humanHapticFeedbacks; /// <summary> haptic feedback vector to the human fingertips

std::vector<double>
humanForceFeedbacks; /// <summary> force feedback vector to the human fingertips

Expand Down
15 changes: 11 additions & 4 deletions modules/HapticGlove_module/src/GloveControlHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ bool GloveControlHelper::setFingertipForceFeedbackReferences(
/ m_maxForceFeedback);
}

return m_pImp->setFingertipForceFeedbackValues(m_desiredForceValues);
return true;
}

bool GloveControlHelper::setFingertipVibrotactileFeedbackReferences(
Expand All @@ -199,8 +199,14 @@ bool GloveControlHelper::setFingertipVibrotactileFeedbackReferences(
= (int)std::round(std::max(0.0, std::min(desiredValue[i], 100.0)));
}

return m_pImp->setFingertipVibrotactileValues(m_desiredVibrotactileValues);
return true;
}

bool GloveControlHelper::sendFingertipHapticFeedbackReferences()
{
return m_pImp->setFingertipHapticFeedbackValues(m_desiredForceValues, m_desiredVibrotactileValues);
}

bool GloveControlHelper::stopPalmVibrotactileFeedback()
{
return m_pImp->setPalmVibrotactileValue(to_underlying(
Expand All @@ -211,13 +217,13 @@ bool GloveControlHelper::stopPalmVibrotactileFeedback()
bool GloveControlHelper::stopVibrotactileFeedback()
{
std::fill(m_desiredVibrotactileValues.begin(), m_desiredVibrotactileValues.end(), 0.0);
return m_pImp->setFingertipVibrotactileValues(m_desiredVibrotactileValues);
return true;
}

bool GloveControlHelper::stopForceFeedback()
{
std::fill(m_desiredForceValues.begin(), m_desiredForceValues.end(), 0.0);
return m_pImp->setFingertipForceFeedbackValues(m_desiredForceValues);
return true;
}

bool GloveControlHelper::stopHapticFeedback()
Expand Down Expand Up @@ -361,6 +367,7 @@ bool GloveControlHelper::findHumanMotionRange()

std::vector<double> desiredValue(m_numVibrotactileFeedback, 35);
this->setFingertipVibrotactileFeedbackReferences(desiredValue);
this->sendFingertipHapticFeedbackReferences();
return true;
}

Expand Down
81 changes: 22 additions & 59 deletions modules/HapticGlove_module/src/GloveWearable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ GloveWearableImpl::GloveWearableImpl(const size_t& numFingers,
, m_numForceFeedback(numForceFeedback)
, m_numVibrotactileFeedback(numVibrotactileFeedback)
, m_numHandJoints(numHandJoints)
, m_numHapticFeedback(numForceFeedback + numVibrotactileFeedback)
{
m_logPrefix = "GloveWearableImpl::";
}
Expand Down Expand Up @@ -141,13 +142,13 @@ bool GloveWearableImpl::configure(const yarp::os::Searchable& config,
return false;
}

if (!m_iWearActuatorPort.open(portNameOut))
if (!m_iWearGloveActuatorPort.open(portNameOut))
{
yError() << m_logPrefix << portNameOut << " port already open.";
return false;
}

if (!Network::connect(m_iWearActuatorPort.getName(), portNameIn, "fast_tcp"))
if (!Network::connect(m_iWearGloveActuatorPort.getName(), portNameIn, "fast_tcp"))
{
yError() << m_logPrefix << "output port: " << portNameOut << "input port: " << portNameIn
<< " unable to connect the ports.";
Expand Down Expand Up @@ -327,63 +328,34 @@ bool GloveWearableImpl::getFingertipPoseValues(Eigen::MatrixXd& values)
return true;
}

bool GloveWearableImpl::setFingertipForceFeedbackValues(const std::vector<int>& values)
bool GloveWearableImpl::setFingertipHapticFeedbackValues(const std::vector<int>& forceValues, const std::vector<int>& vibroValues)
{
if (values.size() != m_numForceFeedback)
if (forceValues.size() + vibroValues.size() != m_numHapticFeedback)
{
yError() << m_logPrefix
<< "size of the force feedback vector is not equal to the size of the default "
"force feedback size.";
<< "size of the haptic feedback vector is not equal to the size of the default "
"haptic feedback size.";
}
for (size_t i = 0; i < values.size(); i++)
{
std::string fingerName = m_humanFingerNameList[i];

wearable::msg::WearableActuatorCommand& wearableActuatorCommand
= m_iWearActuatorPort.prepare();

wearableActuatorCommand.value = values[i];
wearableActuatorCommand.info.name = m_wearablePrefix
+ wearable::actuator::IHaptic::getPrefix() + fingerName
+ "::ForceFeedback";
wearableActuatorCommand.info.type = wearable::msg::ActuatorType::HAPTIC;
wearableActuatorCommand.duration = 0;

m_iWearActuatorPort.write(true); // writeStrict option for wearable haptic device should be
// set to true to avoid the data loss for all actuators
}
return true;
}
wearable::msg::GloveActuatorCommand& gloveActuatorCommand
= m_iWearGloveActuatorPort.prepare();
gloveActuatorCommand.forceValue.resize(m_numForceFeedback);
gloveActuatorCommand.vibroTactileValue.resize(m_numVibrotactileFeedback);

bool GloveWearableImpl::setFingertipVibrotactileValues(const std::vector<int>& values)
{
if (values.size() != m_numVibrotactileFeedback)
for (size_t i = 0; i < forceValues.size(); i++)
{
yError()
<< m_logPrefix
<< "size of the vibrotactile feedback vector is not equal to the size of the default "
"vibrotactile feedback size.";
gloveActuatorCommand.forceValue[i] = forceValues[i];
}

for (size_t i = 0; i < values.size(); i++)
for (size_t i = 0; i < vibroValues.size(); i++)
{
std::string fingerName = m_humanFingerNameList[i];

wearable::msg::WearableActuatorCommand& wearableActuatorCommand
= m_iWearActuatorPort.prepare();

wearableActuatorCommand.value = values[i];
wearableActuatorCommand.info.name = m_wearablePrefix
+ wearable::actuator::IHaptic::getPrefix() + fingerName
+ "::VibroTactileFeedback";

wearableActuatorCommand.info.type = wearable::msg::ActuatorType::HAPTIC;
wearableActuatorCommand.duration = 0;

m_iWearActuatorPort.write(true); // writeStrict option for wearable haptic device should be
// set to true to avoid the data loss for all actuators
gloveActuatorCommand.vibroTactileValue[i] = vibroValues[i];
}

gloveActuatorCommand.info.name = m_wearablePrefix
+ wearable::actuator::IHaptic::getPrefix() +
+ "HapticFeedback";
gloveActuatorCommand.info.type = wearable::msg::ActuatorType::HAPTIC;

m_iWearGloveActuatorPort.write();
return true;
}

Expand All @@ -403,15 +375,6 @@ bool GloveWearableImpl::setPalmVibrotactileValue(const int& value)
* Object_Grasp_30 = 9
*/

wearable::msg::WearableActuatorCommand& wearableActuatorCommand = m_iWearActuatorPort.prepare();

wearableActuatorCommand.value = value;
wearableActuatorCommand.info.name = m_wearablePrefix + wearable::actuator::IHaptic::getPrefix()
+ m_handLinkName + "::VibroTactileFeedback";
wearableActuatorCommand.info.type = wearable::msg::ActuatorType::HAPTIC;
wearableActuatorCommand.duration = 0;

m_iWearActuatorPort.write(false);
return true;
}

Expand All @@ -421,7 +384,7 @@ bool GloveWearableImpl::close()
m_iWear = nullptr;
m_wearableDevice.close();

m_iWearActuatorPort.close();
m_iWearGloveActuatorPort.close();

return true;
}
2 changes: 0 additions & 2 deletions modules/HapticGlove_module/src/HapticGloveModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ bool HapticGloveModule::configure(yarp::os::ResourceFinder& rf)
{
m_state = HapticGloveFSM::Configuring;

yarp::os::Value* value;

// check if the configuration file is empty
if (rf.isNull())
{
Expand Down
1 change: 1 addition & 0 deletions modules/HapticGlove_module/src/Teleoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ bool Teleoperation::run()
m_robotController->move();
m_humanGlove->setFingertipForceFeedbackReferences(m_data.humanForceFeedbacks);
m_humanGlove->setFingertipVibrotactileFeedbackReferences(m_data.humanVibrotactileFeedbacks);
m_humanGlove->sendFingertipHapticFeedbackReferences();
}

if (m_enableLogger)
Expand Down

0 comments on commit 82d3dd9

Please sign in to comment.