Skip to content

Commit f4473aa

Browse files
authored
Merge pull request #58 from ROBOTIS-GIT/develop
Develop
2 parents 317012f + 7406f46 commit f4473aa

File tree

2 files changed

+59
-13
lines changed

2 files changed

+59
-13
lines changed

robotis_controller/include/robotis_controller/robotis_controller.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include "robotis_controller_msgs/SyncWriteItem.h"
3737
#include "robotis_controller_msgs/JointCtrlModule.h"
3838
#include "robotis_controller_msgs/GetJointModule.h"
39+
#include "robotis_controller_msgs/SetJointModule.h"
40+
#include "robotis_controller_msgs/SetModule.h"
3941

4042
#include "robotis_device/robot.h"
4143
#include "robotis_framework_common/motion_module.h"
@@ -137,7 +139,9 @@ class RobotisController : public Singleton<RobotisController>
137139
void setJointStatesCallback(const sensor_msgs::JointState::ConstPtr &msg);
138140
void setJointCtrlModuleCallback(const robotis_controller_msgs::JointCtrlModule::ConstPtr &msg);
139141
void setCtrlModuleCallback(const std_msgs::String::ConstPtr &msg);
140-
bool getCtrlModuleCallback(robotis_controller_msgs::GetJointModule::Request &req, robotis_controller_msgs::GetJointModule::Response &res);
142+
bool getJointCtrlModuleService(robotis_controller_msgs::GetJointModule::Request &req, robotis_controller_msgs::GetJointModule::Response &res);
143+
bool setJointCtrlModuleService(robotis_controller_msgs::SetJointModule::Request &req, robotis_controller_msgs::SetJointModule::Response &res);
144+
bool setCtrlModuleService(robotis_controller_msgs::SetModule::Request &req, robotis_controller_msgs::SetModule::Response &res);
141145

142146
void gazeboJointStatesCallback(const sensor_msgs::JointState::ConstPtr &msg);
143147

robotis_controller/src/robotis_controller/robotis_controller.cpp

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,8 @@ void RobotisController::initializeDevice(const std::string init_file_path)
485485
bulkread_data_length += addr_leng;
486486
for (int l = 0; l < addr_leng; l++)
487487
{
488-
//ROS_WARN("[%12s] INDIR_ADDR: %d, ITEM_ADDR: %d", joint_name.c_str(), indirect_addr, dxl->ctrl_table_[dxl->bulk_read_items_[i]->item_name_]->address_ + l);
488+
// ROS_WARN("[%12s] INDIR_ADDR: %d, ITEM_ADDR: %d", joint_name.c_str(), indirect_addr, dxl->ctrl_table[dxl->bulk_read_items[i]->item_name]->address + _l);
489+
489490
read2Byte(joint_name, indirect_addr, &data16);
490491
if (data16 != dxl->ctrl_table_[dxl->bulk_read_items_[i]->item_name_]->address_ + l)
491492
{
@@ -657,8 +658,12 @@ void RobotisController::msgQueueThread()
657658
}
658659

659660
/* service */
660-
ros::ServiceServer joint_module_server = ros_node.advertiseService("/robotis/get_present_joint_ctrl_modules",
661-
&RobotisController::getCtrlModuleCallback, this);
661+
ros::ServiceServer get_joint_module_server = ros_node.advertiseService("/robotis/get_present_joint_ctrl_modules",
662+
&RobotisController::getJointCtrlModuleService, this);
663+
ros::ServiceServer set_joint_module_server = ros_node.advertiseService("/robotis/set_present_joint_ctrl_modules",
664+
&RobotisController::setJointCtrlModuleService, this);
665+
ros::ServiceServer set_module_server = ros_node.advertiseService("/robotis/set_present_ctrl_modules",
666+
&RobotisController::setCtrlModuleService, this);
662667

663668
ros::WallDuration duration(robot_->getControlCycle() / 1000.0);
664669
while(ros_node.ok())
@@ -1663,24 +1668,33 @@ void RobotisController::setJointStatesCallback(const sensor_msgs::JointState::Co
16631668

16641669
void RobotisController::setCtrlModuleCallback(const std_msgs::String::ConstPtr &msg)
16651670
{
1671+
if(set_module_thread_.joinable())
1672+
set_module_thread_.join();
1673+
16661674
std::string _module_name_to_set = msg->data;
16671675

16681676
set_module_thread_ = boost::thread(boost::bind(&RobotisController::setCtrlModuleThread, this, _module_name_to_set));
16691677
}
16701678

16711679
void RobotisController::setCtrlModule(std::string module_name)
16721680
{
1681+
if(set_module_thread_.joinable())
1682+
set_module_thread_.join();
1683+
16731684
set_module_thread_ = boost::thread(boost::bind(&RobotisController::setCtrlModuleThread, this, module_name));
16741685
}
16751686
void RobotisController::setJointCtrlModuleCallback(const robotis_controller_msgs::JointCtrlModule::ConstPtr &msg)
16761687
{
16771688
if (msg->joint_name.size() != msg->module_name.size())
16781689
return;
16791690

1691+
if(set_module_thread_.joinable())
1692+
set_module_thread_.join();
1693+
16801694
set_module_thread_ = boost::thread(boost::bind(&RobotisController::setJointCtrlModuleThread, this, msg));
16811695
}
16821696

1683-
bool RobotisController::getCtrlModuleCallback(robotis_controller_msgs::GetJointModule::Request &req,
1697+
bool RobotisController::getJointCtrlModuleService(robotis_controller_msgs::GetJointModule::Request &req,
16841698
robotis_controller_msgs::GetJointModule::Response &res)
16851699
{
16861700
for (unsigned int idx = 0; idx < req.joint_name.size(); idx++)
@@ -1699,6 +1713,41 @@ bool RobotisController::getCtrlModuleCallback(robotis_controller_msgs::GetJointM
16991713
return true;
17001714
}
17011715

1716+
bool RobotisController::setJointCtrlModuleService(robotis_controller_msgs::SetJointModule::Request &req, robotis_controller_msgs::SetJointModule::Response &res)
1717+
{
1718+
if(set_module_thread_.joinable())
1719+
set_module_thread_.join();
1720+
1721+
robotis_controller_msgs::JointCtrlModule modules;
1722+
modules.joint_name = req.joint_name;
1723+
modules.module_name = req.module_name;
1724+
1725+
robotis_controller_msgs::JointCtrlModule::ConstPtr msg_ptr(new robotis_controller_msgs::JointCtrlModule(modules));
1726+
1727+
if (modules.joint_name.size() != modules.module_name.size())
1728+
return false;
1729+
1730+
set_module_thread_ = boost::thread(boost::bind(&RobotisController::setJointCtrlModuleThread, this, msg_ptr));
1731+
1732+
set_module_thread_.join();
1733+
1734+
return true;
1735+
}
1736+
1737+
bool RobotisController::setCtrlModuleService(robotis_controller_msgs::SetModule::Request &req, robotis_controller_msgs::SetModule::Response &res)
1738+
{
1739+
if(set_module_thread_.joinable())
1740+
set_module_thread_.join();
1741+
1742+
std::string _module_name_to_set = req.module_name;
1743+
1744+
set_module_thread_ = boost::thread(boost::bind(&RobotisController::setCtrlModuleThread, this, _module_name_to_set));
1745+
1746+
set_module_thread_.join();
1747+
1748+
return true;
1749+
}
1750+
17021751
void RobotisController::setJointCtrlModuleThread(const robotis_controller_msgs::JointCtrlModule::ConstPtr &msg)
17031752
{
17041753
// stop module list
@@ -1873,14 +1922,6 @@ void RobotisController::setJointCtrlModuleThread(const robotis_controller_msgs::
18731922

18741923
queue_mutex_.unlock();
18751924

1876-
// log
1877-
// std::cout << "Enable Joint Ctrl Module : " << std::endl;
1878-
// for(std::list<MotionModule *>::iterator _m_it = motion_modules_.begin(); _m_it != motion_modules_.end(); _m_it++)
1879-
// {
1880-
// if((*_m_it)->GetModuleEnable() == true)
1881-
// std::cout << " - " << (*_m_it)->GetModuleName() << std::endl;
1882-
// }
1883-
18841925
// publish current module
18851926
robotis_controller_msgs::JointCtrlModule _current_module_msg;
18861927
for(std::map<std::string, Dynamixel *>::iterator _dxl_iter = robot_->dxls_.begin(); _dxl_iter != robot_->dxls_.end(); ++_dxl_iter)
@@ -1892,6 +1933,7 @@ void RobotisController::setJointCtrlModuleThread(const robotis_controller_msgs::
18921933
if(_current_module_msg.joint_name.size() == _current_module_msg.module_name.size())
18931934
current_module_pub_.publish(_current_module_msg);
18941935
}
1936+
18951937
void RobotisController::setCtrlModuleThread(std::string ctrl_module)
18961938
{
18971939
// stop module

0 commit comments

Comments
 (0)