@@ -671,8 +671,12 @@ void RobotisController::msgQueueThread()
671
671
}
672
672
673
673
/* 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 );
676
680
677
681
ros::WallDuration duration (robot_->getControlCycle () / 1000.0 );
678
682
while (ros_node.ok ())
@@ -1677,24 +1681,33 @@ void RobotisController::setJointStatesCallback(const sensor_msgs::JointState::Co
1677
1681
1678
1682
void RobotisController::setCtrlModuleCallback (const std_msgs::String::ConstPtr &msg)
1679
1683
{
1684
+ if (set_module_thread_.joinable ())
1685
+ set_module_thread_.join ();
1686
+
1680
1687
std::string _module_name_to_set = msg->data ;
1681
1688
1682
1689
set_module_thread_ = boost::thread (boost::bind (&RobotisController::setCtrlModuleThread, this , _module_name_to_set));
1683
1690
}
1684
1691
1685
1692
void RobotisController::setCtrlModule (std::string module_name)
1686
1693
{
1694
+ if (set_module_thread_.joinable ())
1695
+ set_module_thread_.join ();
1696
+
1687
1697
set_module_thread_ = boost::thread (boost::bind (&RobotisController::setCtrlModuleThread, this , module_name));
1688
1698
}
1689
1699
void RobotisController::setJointCtrlModuleCallback (const robotis_controller_msgs::JointCtrlModule::ConstPtr &msg)
1690
1700
{
1691
1701
if (msg->joint_name .size () != msg->module_name .size ())
1692
1702
return ;
1693
1703
1704
+ if (set_module_thread_.joinable ())
1705
+ set_module_thread_.join ();
1706
+
1694
1707
set_module_thread_ = boost::thread (boost::bind (&RobotisController::setJointCtrlModuleThread, this , msg));
1695
1708
}
1696
1709
1697
- bool RobotisController::getCtrlModuleCallback (robotis_controller_msgs::GetJointModule::Request &req,
1710
+ bool RobotisController::getJointCtrlModuleService (robotis_controller_msgs::GetJointModule::Request &req,
1698
1711
robotis_controller_msgs::GetJointModule::Response &res)
1699
1712
{
1700
1713
for (unsigned int idx = 0 ; idx < req.joint_name .size (); idx++)
@@ -1713,6 +1726,41 @@ bool RobotisController::getCtrlModuleCallback(robotis_controller_msgs::GetJointM
1713
1726
return true ;
1714
1727
}
1715
1728
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
+
1716
1764
void RobotisController::setJointCtrlModuleThread (const robotis_controller_msgs::JointCtrlModule::ConstPtr &msg)
1717
1765
{
1718
1766
// stop module list
@@ -1906,6 +1954,7 @@ void RobotisController::setJointCtrlModuleThread(const robotis_controller_msgs::
1906
1954
if (_current_module_msg.joint_name .size () == _current_module_msg.module_name .size ())
1907
1955
current_module_pub_.publish (_current_module_msg);
1908
1956
}
1957
+
1909
1958
void RobotisController::setCtrlModuleThread (std::string ctrl_module)
1910
1959
{
1911
1960
// stop module
0 commit comments