Skip to content

Commit

Permalink
Add option ENABLE_ESKIN.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmurooka committed Apr 25, 2024
1 parent 3d577dd commit 55ab9f7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
uses: jrl-umi3218/github-actions/build-cmake-project@master
with:
build-type: ${{ matrix.build-type }}
options: -DINSTALL_DOCUMENTATION=${{ env.UPLOAD_DOCUMENTATION }}
options: -DENABLE_ESKIN=OFF -DINSTALL_DOCUMENTATION=${{ env.UPLOAD_DOCUMENTATION }}
- name: Upload documentation
if: env.UPLOAD_DOCUMENTATION == 'true'
run: |
Expand Down
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set(CXX_DISABLE_WERROR ON)
set(CMAKE_COLOR_DIAGNOSTICS ON)

option(INSTALL_DOCUMENTATION "Generate and install the documentation" OFF)
option(ENABLE_ESKIN "Enable e-Skin tactile sensor" ON)

include(cmake/base.cmake)
project(${PROJECT_NAME} LANGUAGES CXX)
Expand All @@ -31,7 +32,12 @@ pkg_check_modules(eigen_conversions REQUIRED IMPORTED_TARGET eigen_conversions)
find_package(PkgConfig)
pkg_check_modules(mujoco_tactile_sensor_plugin REQUIRED IMPORTED_TARGET
mujoco_tactile_sensor_plugin)
pkg_check_modules(eskin_ros_utils REQUIRED IMPORTED_TARGET eskin_ros_utils)
if(ENABLE_ESKIN)
pkg_check_modules(eskin_ros_utils REQUIRED IMPORTED_TARGET eskin_ros_utils)
message("-- Enable e-Skin")
else()
message("-- Disable e-Skin")
endif()

install(FILES etc/TactileSensor.yaml
DESTINATION "${MC_PLUGINS_RUNTIME_INSTALL_PREFIX}/etc")
Expand Down
16 changes: 12 additions & 4 deletions include/McRtcTactileSensorPlugin/TactileSensorPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <ros/callback_queue.h>
#include <ros/ros.h>

#include <eskin_ros_utils/PatchData.h>
#ifdef ENABLE_ESKIN
# include <eskin_ros_utils/PatchData.h>
#endif
#include <mujoco_tactile_sensor_plugin/TactileSensorData.h>
#include <variant>

Expand Down Expand Up @@ -66,20 +68,26 @@ struct TactileSensorPlugin : public mc_control::GlobalPlugin
void mujocoSensorCallback(const mujoco_tactile_sensor_plugin::TactileSensorData::ConstPtr & sensorMsg,
size_t sensorIdx);

#ifdef ENABLE_ESKIN
/** \brief ROS callback of tactile sensor topic from e-Skin.
\param sensorMsg sensor message
\param sensorIdx sensor index
*/
\param sensorMsg sensor message
\param sensorIdx sensor index
*/
void eskinSensorCallback(const eskin_ros_utils::PatchData::ConstPtr & sensorMsg, size_t sensorIdx);
#endif

protected:
//! Sensor information list
std::vector<SensorInfo> sensorInfoList_;

//! Sensor message list
#ifdef ENABLE_ESKIN
std::vector<std::variant<std::nullptr_t,
std::shared_ptr<mujoco_tactile_sensor_plugin::TactileSensorData>,
std::shared_ptr<eskin_ros_utils::PatchData>>>
#else
std::vector<std::variant<std::nullptr_t, std::shared_ptr<mujoco_tactile_sensor_plugin::TactileSensorData>>>
#endif
sensorMsgList_;

//! ROS variables
Expand Down
14 changes: 9 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ set(AUTOLOAD_TactileSensor_PLUGIN
OFF
CACHE INTERNAL "Automatically load TactileSensor plugin")
add_plugin(TactileSensor TactileSensorPlugin.cpp)
target_include_directories(TactileSensor PUBLIC ${eskin_ros_utils_INCLUDE_DIRS})
target_link_directories(TactileSensor PUBLIC ${eskin_ros_utils_LIBRARY_DIRS})
target_link_libraries(
TactileSensor
PUBLIC PkgConfig::eigen_conversions PkgConfig::mujoco_tactile_sensor_plugin
${eskin_ros_utils_LIBRARIES})
TactileSensor PUBLIC PkgConfig::eigen_conversions
PkgConfig::mujoco_tactile_sensor_plugin)
if(ENABLE_ESKIN)
target_compile_definitions(TactileSensor PUBLIC ENABLE_ESKIN)
target_include_directories(TactileSensor
PUBLIC ${eskin_ros_utils_INCLUDE_DIRS})
target_link_directories(TactileSensor PUBLIC ${eskin_ros_utils_LIBRARY_DIRS})
target_link_libraries(TactileSensor PUBLIC ${eskin_ros_utils_LIBRARIES})
endif()
11 changes: 11 additions & 0 deletions src/TactileSensorPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ void TactileSensorPlugin::init(mc_control::MCGlobalController & gc, const mc_rtc
}
else if(msgTypeStr == "eskin")
{
#ifdef ENABLE_ESKIN
sensorInfo.msgType = MsgType::Eskin;
#else
mc_rtc::log::error_and_throw(
"[mc_plugin::TactileSensorPlugin] e-Skin is disabled. Rebuild with the \"-DENABLE_ESKIN=ON\" option.");
#endif
}
else
{
Expand Down Expand Up @@ -92,12 +97,14 @@ void TactileSensorPlugin::init(mc_control::MCGlobalController & gc, const mc_rtc
sensorInfoList_[sensorIdx].topicName, 1,
std::bind(&TactileSensorPlugin::mujocoSensorCallback, this, std::placeholders::_1, sensorIdx)));
}
#ifdef ENABLE_ESKIN
else // if(sensorInfoList_[sensorIdx].msgType == MsgType::Eskin)
{
sensorSubList_.push_back(nh_->subscribe<eskin_ros_utils::PatchData>(
sensorInfoList_[sensorIdx].topicName, 1,
std::bind(&TactileSensorPlugin::eskinSensorCallback, this, std::placeholders::_1, sensorIdx)));
}
#endif
}

reset(gc);
Expand Down Expand Up @@ -156,6 +163,7 @@ void TactileSensorPlugin::before(mc_control::MCGlobalController & gc)
sva::PTransformd tactileToForceTrans = forceSensorPose * tactileSensorPose.inv();
wrench = tactileToForceTrans.dualMul(wrench);
}
#ifdef ENABLE_ESKIN
else if(std::holds_alternative<std::shared_ptr<eskin_ros_utils::PatchData>>(sensorMsgList_[sensorIdx]))
{
const auto & sensorMsg = std::get<std::shared_ptr<eskin_ros_utils::PatchData>>(sensorMsgList_[sensorIdx]);
Expand All @@ -181,6 +189,7 @@ void TactileSensorPlugin::before(mc_control::MCGlobalController & gc)
sva::PTransformd tactileToForceTrans = forceSensorPose * tactileSensorPose.inv();
wrench = tactileToForceTrans.dualMul(wrench);
}
#endif
forceSensor.wrench(wrench);
}
}
Expand All @@ -192,10 +201,12 @@ void TactileSensorPlugin::mujocoSensorCallback(
sensorMsgList_[sensorIdx] = std::make_shared<mujoco_tactile_sensor_plugin::TactileSensorData>(*sensorMsg);
}

#ifdef ENABLE_ESKIN
void TactileSensorPlugin::eskinSensorCallback(const eskin_ros_utils::PatchData::ConstPtr & sensorMsg, size_t sensorIdx)
{
sensorMsgList_[sensorIdx] = std::make_shared<eskin_ros_utils::PatchData>(*sensorMsg);
}
#endif
} // namespace mc_plugin

EXPORT_MC_RTC_PLUGIN("TactileSensor", mc_plugin::TactileSensorPlugin)

0 comments on commit 55ab9f7

Please sign in to comment.