Skip to content

Commit

Permalink
Add ENABLE_MUJOCO option.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmurooka committed Apr 30, 2024
1 parent 91faaf7 commit 8a2ddaf
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 18 deletions.
15 changes: 12 additions & 3 deletions 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_MUJOCO "Enable MuJoCo tactile sensor" ON)
option(ENABLE_ESKIN "Enable e-Skin tactile sensor" ON)

include(cmake/base.cmake)
Expand All @@ -28,11 +29,19 @@ endif()
# eigen_conversions
pkg_check_modules(eigen_conversions REQUIRED IMPORTED_TARGET eigen_conversions)

# mujoco_tactile_sensor_plugin
find_package(PkgConfig)
pkg_check_modules(mujoco_tactile_sensor_plugin REQUIRED IMPORTED_TARGET
mujoco_tactile_sensor_plugin)

if(ENABLE_MUJOCO)
# mujoco_tactile_sensor_plugin
pkg_check_modules(mujoco_tactile_sensor_plugin REQUIRED IMPORTED_TARGET
mujoco_tactile_sensor_plugin)
message("-- Enable MuJoCo")
else()
message("-- Disable MuJoCo")
endif()

if(ENABLE_ESKIN)
# eskin_ros_utils
pkg_check_modules(eskin_ros_utils REQUIRED IMPORTED_TARGET eskin_ros_utils)
message("-- Enable e-Skin")
else()
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mc_rtc plugin to use tactile sensor in controller via ROS interface
### Dependencies
- [mc_rtc](https://jrl-umi3218.github.io/mc_rtc)
- [isri-aist/MujocoTactileSensorPlugin](https://github.com/isri-aist/MujocoTactileSensorPlugin) (Install as a ROS package)
- An option to build without dependency on the MuJoCo tactile sensor is also supported.
- [eSkinRosUtils](https://github.com/isri-aist/eSkinRosUtils)
- An option to build without dependency on the e-Skin tactile sensor is also supported.

Expand All @@ -24,7 +25,7 @@ $ mkdir ${HOME}/src && cd ${HOME}/src
$ git clone [email protected]:isri-aist/McRtcTactileSensorPlugin.git --recursive
$ cd McRtcTactileSensorPlugin
$ mkdir build && cd build
$ cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo # Add "-DENABLE_ESKIN=OFF" option if you do not use e-Skin tactile sensor
$ cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo # Add "-DENABLE_MUJOCO=OFF" or "-DENABLE_ESKIN=OFF" options if necessary
$ make
$ make install
```
Expand Down
18 changes: 13 additions & 5 deletions include/McRtcTactileSensorPlugin/TactileSensorPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#include <ros/callback_queue.h>
#include <ros/ros.h>

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

namespace mc_plugin
Expand Down Expand Up @@ -61,14 +63,16 @@ struct TactileSensorPlugin : public mc_control::GlobalPlugin
inline void after(mc_control::MCGlobalController & gc) override{};

protected:
#if ENABLE_MUJOCO
/** \brief ROS callback of tactile sensor topic from MuJoCo.
\param sensorMsg sensor message
\param sensorIdx sensor index
*/
void mujocoSensorCallback(const mujoco_tactile_sensor_plugin::TactileSensorData::ConstPtr & sensorMsg,
size_t sensorIdx);
#endif

#ifdef ENABLE_ESKIN
#if ENABLE_ESKIN
/** \brief ROS callback of tactile sensor topic from e-Skin.
\param sensorMsg sensor message
\param sensorIdx sensor index
Expand All @@ -81,12 +85,16 @@ struct TactileSensorPlugin : public mc_control::GlobalPlugin
std::vector<SensorInfo> sensorInfoList_;

//! Sensor message list
#ifdef ENABLE_ESKIN
#if ENABLE_MUJOCO && 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
#elif ENABLE_MUJOCO && !ENABLE_ESKIN
std::vector<std::variant<std::nullptr_t, std::shared_ptr<mujoco_tactile_sensor_plugin::TactileSensorData>>>
#elif !ENABLE_MUJOCO && ENABLE_ESKIN
std::vector<std::variant<std::nullptr_t, std::shared_ptr<eskin_ros_utils::PatchData>>>
#else
std::vector<std::variant<std::nullptr_t>>
#endif
sensorMsgList_;

Expand Down
17 changes: 13 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ set(AUTOLOAD_TactileSensor_PLUGIN
OFF
CACHE INTERNAL "Automatically load TactileSensor plugin")
add_plugin(TactileSensor TactileSensorPlugin.cpp)
target_link_libraries(
TactileSensor PUBLIC PkgConfig::eigen_conversions
PkgConfig::mujoco_tactile_sensor_plugin)
target_link_libraries(TactileSensor PUBLIC PkgConfig::eigen_conversions)

if(ENABLE_MUJOCO)
target_compile_definitions(TactileSensor PUBLIC ENABLE_MUJOCO=1)
target_link_libraries(TactileSensor
PUBLIC PkgConfig::mujoco_tactile_sensor_plugin)
else()
target_compile_definitions(TactileSensor PUBLIC ENABLE_MUJOCO=0)
endif()

if(ENABLE_ESKIN)
target_compile_definitions(TactileSensor PUBLIC ENABLE_ESKIN)
target_compile_definitions(TactileSensor PUBLIC ENABLE_ESKIN=1)
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})
else()
target_compile_definitions(TactileSensor PUBLIC ENABLE_ESKIN=0)
endif()
21 changes: 16 additions & 5 deletions src/TactileSensorPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ void TactileSensorPlugin::init(mc_control::MCGlobalController & gc, const mc_rtc
std::string msgTypeStr = sensorConfig("msgType");
if(msgTypeStr == "mujoco")
{
#if ENABLE_MUJOCO
sensorInfo.msgType = MsgType::Mujoco;
#else
mc_rtc::log::error_and_throw(
"[mc_plugin::TactileSensorPlugin] MuJoCo is disabled. Rebuild with the \"-DENABLE_MUJOCO=ON\" option.");
#endif
}
else if(msgTypeStr == "eskin")
{
#ifdef ENABLE_ESKIN
#if ENABLE_ESKIN
sensorInfo.msgType = MsgType::Eskin;
#else
mc_rtc::log::error_and_throw(
Expand Down Expand Up @@ -91,14 +96,16 @@ void TactileSensorPlugin::init(mc_control::MCGlobalController & gc, const mc_rtc
sensorSubList_.clear();
for(size_t sensorIdx = 0; sensorIdx < sensorInfoList_.size(); sensorIdx++)
{
#if ENABLE_MUJOCO
if(sensorInfoList_[sensorIdx].msgType == MsgType::Mujoco)
{
sensorSubList_.push_back(nh_->subscribe<mujoco_tactile_sensor_plugin::TactileSensorData>(
sensorInfoList_[sensorIdx].topicName, 1,
std::bind(&TactileSensorPlugin::mujocoSensorCallback, this, std::placeholders::_1, sensorIdx)));
}
#ifdef ENABLE_ESKIN
else // if(sensorInfoList_[sensorIdx].msgType == MsgType::Eskin)
#endif
#if ENABLE_ESKIN
if(sensorInfoList_[sensorIdx].msgType == MsgType::Eskin)
{
sensorSubList_.push_back(nh_->subscribe<eskin_ros_utils::PatchData>(
sensorInfoList_[sensorIdx].topicName, 1,
Expand Down Expand Up @@ -138,6 +145,7 @@ void TactileSensorPlugin::before(mc_control::MCGlobalController & gc)
{
// Do nothing
}
#if ENABLE_MUJOCO
else if(std::holds_alternative<std::shared_ptr<mujoco_tactile_sensor_plugin::TactileSensorData>>(
sensorMsgList_[sensorIdx]))
{
Expand All @@ -163,7 +171,8 @@ void TactileSensorPlugin::before(mc_control::MCGlobalController & gc)
sva::PTransformd tactileToForceTrans = forceSensorPose * tactileSensorPose.inv();
wrench = tactileToForceTrans.dualMul(wrench);
}
#ifdef ENABLE_ESKIN
#endif
#if 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 Down Expand Up @@ -194,14 +203,16 @@ void TactileSensorPlugin::before(mc_control::MCGlobalController & gc)
}
}

#if ENABLE_MUJOCO
void TactileSensorPlugin::mujocoSensorCallback(
const mujoco_tactile_sensor_plugin::TactileSensorData::ConstPtr & sensorMsg,
size_t sensorIdx)
{
sensorMsgList_[sensorIdx] = std::make_shared<mujoco_tactile_sensor_plugin::TactileSensorData>(*sensorMsg);
}
#endif

#ifdef ENABLE_ESKIN
#if 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);
Expand Down

0 comments on commit 8a2ddaf

Please sign in to comment.