Skip to content

Commit 5e9278e

Browse files
committed
added serivce for setting module
1 parent 0076da8 commit 5e9278e

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

robotis_controller/include/robotis_controller/robotis_controller.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
#include "robotis_controller_msgs/SyncWriteItem.h"
5151
#include "robotis_controller_msgs/JointCtrlModule.h"
5252
#include "robotis_controller_msgs/GetJointModule.h"
53+
#include "robotis_controller_msgs/SetJointModule.h"
54+
#include "robotis_controller_msgs/SetModule.h"
5355

5456
#include "robotis_device/robot.h"
5557
#include "robotis_framework_common/motion_module.h"
@@ -151,7 +153,9 @@ class RobotisController : public Singleton<RobotisController>
151153
void setJointStatesCallback(const sensor_msgs::JointState::ConstPtr &msg);
152154
void setJointCtrlModuleCallback(const robotis_controller_msgs::JointCtrlModule::ConstPtr &msg);
153155
void setCtrlModuleCallback(const std_msgs::String::ConstPtr &msg);
154-
bool getCtrlModuleCallback(robotis_controller_msgs::GetJointModule::Request &req, robotis_controller_msgs::GetJointModule::Response &res);
156+
bool getJointCtrlModuleService(robotis_controller_msgs::GetJointModule::Request &req, robotis_controller_msgs::GetJointModule::Response &res);
157+
bool setJointCtrlModuleService(robotis_controller_msgs::SetJointModule::Request &req, robotis_controller_msgs::SetJointModule::Response &res);
158+
bool setCtrlModuleService(robotis_controller_msgs::SetModule::Request &req, robotis_controller_msgs::SetModule::Response &res);
155159

156160
void gazeboJointStatesCallback(const sensor_msgs::JointState::ConstPtr &msg);
157161

robotis_controller/src/robotis_controller/robotis_controller.cpp

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,12 @@ void RobotisController::msgQueueThread()
671671
}
672672

673673
/* service */
674-
ros::ServiceServer joint_module_server = ros_node.advertiseService("/robotis/get_present_joint_ctrl_modules",
675-
&RobotisController::getCtrlModuleCallback, this);
674+
ros::ServiceServer get_joint_module_server = ros_node.advertiseService("/robotis/get_present_joint_ctrl_modules",
675+
&RobotisController::getJointCtrlModuleService, this);
676+
ros::ServiceServer set_joint_module_server = ros_node.advertiseService("/robotis/set_present_joint_ctrl_modules",
677+
&RobotisController::setJointCtrlModuleService, this);
678+
ros::ServiceServer set_module_server = ros_node.advertiseService("/robotis/set_present_ctrl_modules",
679+
&RobotisController::setCtrlModuleService, this);
676680

677681
ros::WallDuration duration(robot_->getControlCycle() / 1000.0);
678682
while(ros_node.ok())
@@ -1677,24 +1681,33 @@ void RobotisController::setJointStatesCallback(const sensor_msgs::JointState::Co
16771681

16781682
void RobotisController::setCtrlModuleCallback(const std_msgs::String::ConstPtr &msg)
16791683
{
1684+
if(set_module_thread_.joinable())
1685+
set_module_thread_.join();
1686+
16801687
std::string _module_name_to_set = msg->data;
16811688

16821689
set_module_thread_ = boost::thread(boost::bind(&RobotisController::setCtrlModuleThread, this, _module_name_to_set));
16831690
}
16841691

16851692
void RobotisController::setCtrlModule(std::string module_name)
16861693
{
1694+
if(set_module_thread_.joinable())
1695+
set_module_thread_.join();
1696+
16871697
set_module_thread_ = boost::thread(boost::bind(&RobotisController::setCtrlModuleThread, this, module_name));
16881698
}
16891699
void RobotisController::setJointCtrlModuleCallback(const robotis_controller_msgs::JointCtrlModule::ConstPtr &msg)
16901700
{
16911701
if (msg->joint_name.size() != msg->module_name.size())
16921702
return;
16931703

1704+
if(set_module_thread_.joinable())
1705+
set_module_thread_.join();
1706+
16941707
set_module_thread_ = boost::thread(boost::bind(&RobotisController::setJointCtrlModuleThread, this, msg));
16951708
}
16961709

1697-
bool RobotisController::getCtrlModuleCallback(robotis_controller_msgs::GetJointModule::Request &req,
1710+
bool RobotisController::getJointCtrlModuleService(robotis_controller_msgs::GetJointModule::Request &req,
16981711
robotis_controller_msgs::GetJointModule::Response &res)
16991712
{
17001713
for (unsigned int idx = 0; idx < req.joint_name.size(); idx++)
@@ -1713,6 +1726,41 @@ bool RobotisController::getCtrlModuleCallback(robotis_controller_msgs::GetJointM
17131726
return true;
17141727
}
17151728

1729+
bool RobotisController::setJointCtrlModuleService(robotis_controller_msgs::SetJointModule::Request &req, robotis_controller_msgs::SetJointModule::Response &res)
1730+
{
1731+
if(set_module_thread_.joinable())
1732+
set_module_thread_.join();
1733+
1734+
robotis_controller_msgs::JointCtrlModule modules;
1735+
modules.joint_name = req.joint_name;
1736+
modules.module_name = req.module_name;
1737+
1738+
robotis_controller_msgs::JointCtrlModule::ConstPtr msg_ptr(new robotis_controller_msgs::JointCtrlModule(modules));
1739+
1740+
if (modules.joint_name.size() != modules.module_name.size())
1741+
return false;
1742+
1743+
set_module_thread_ = boost::thread(boost::bind(&RobotisController::setJointCtrlModuleThread, this, msg_ptr));
1744+
1745+
set_module_thread_.join();
1746+
1747+
return true;
1748+
}
1749+
1750+
bool RobotisController::setCtrlModuleService(robotis_controller_msgs::SetModule::Request &req, robotis_controller_msgs::SetModule::Response &res)
1751+
{
1752+
if(set_module_thread_.joinable())
1753+
set_module_thread_.join();
1754+
1755+
std::string _module_name_to_set = req.module_name;
1756+
1757+
set_module_thread_ = boost::thread(boost::bind(&RobotisController::setCtrlModuleThread, this, _module_name_to_set));
1758+
1759+
set_module_thread_.join();
1760+
1761+
return true;
1762+
}
1763+
17161764
void RobotisController::setJointCtrlModuleThread(const robotis_controller_msgs::JointCtrlModule::ConstPtr &msg)
17171765
{
17181766
// stop module list
@@ -1906,6 +1954,7 @@ void RobotisController::setJointCtrlModuleThread(const robotis_controller_msgs::
19061954
if(_current_module_msg.joint_name.size() == _current_module_msg.module_name.size())
19071955
current_module_pub_.publish(_current_module_msg);
19081956
}
1957+
19091958
void RobotisController::setCtrlModuleThread(std::string ctrl_module)
19101959
{
19111960
// stop module

0 commit comments

Comments
 (0)