Skip to content

Commit 303e24c

Browse files
committed
- added WriteControlTable msg callback
1 parent 260c03b commit 303e24c

File tree

1 file changed

+60
-31
lines changed

1 file changed

+60
-31
lines changed

robotis_controller/src/robotis_controller/robotis_controller.cpp

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,8 @@ void RobotisController::msgQueueThread()
621621
ros_node.setCallbackQueue(&callback_queue);
622622

623623
/* subscriber */
624+
ros::Subscriber write_control_table_sub = ros_node.subscribe("/robotis/write_control_table", 5,
625+
&RobotisController::writeControlTableCallback, this);
624626
ros::Subscriber sync_write_item_sub = ros_node.subscribe("/robotis/sync_write_item", 10,
625627
&RobotisController::syncWriteItemCallback, this);
626628
ros::Subscriber joint_ctrl_modules_sub = ros_node.subscribe("/robotis/set_joint_ctrl_modules", 10,
@@ -1405,6 +1407,52 @@ void RobotisController::removeSensorModule(SensorModule *module)
14051407
sensor_modules_.remove(module);
14061408
}
14071409

1410+
void RobotisController::writeControlTableCallback(const robotis_controller_msgs::WriteControlTable::ConstPtr &msg)
1411+
{
1412+
Device *device = NULL;
1413+
1414+
auto dev_it1 = robot_->dxls_.find(msg->joint_name);
1415+
if(dev_it1 != robot_->dxls_.end())
1416+
{
1417+
device = dev_it1->second;
1418+
}
1419+
else
1420+
{
1421+
auto dev_it2 = robot_->sensors_.find(msg->joint_name);
1422+
if(dev_it2 != robot_->sensors_.end())
1423+
{
1424+
device = dev_it2->second;
1425+
}
1426+
else
1427+
{
1428+
ROS_WARN("[WriteControlTable] Unknown device : %s", msg->joint_name.c_str());
1429+
return;
1430+
}
1431+
}
1432+
1433+
ControlTableItem *item = NULL;
1434+
auto item_it = device->ctrl_table_.find(msg->start_item_name);
1435+
if(item_it != device->ctrl_table_.end())
1436+
{
1437+
item = item_it->second;
1438+
}
1439+
else
1440+
{
1441+
ROS_WARN("WriteControlTable] Unknown item : %s", msg->start_item_name.c_str());
1442+
return;
1443+
}
1444+
1445+
dynamixel::PortHandler *port = robot_->ports_[device->port_name_];
1446+
dynamixel::PacketHandler *packet_handler = dynamixel::PacketHandler::getPacketHandler(device->protocol_version_);
1447+
1448+
if (item->access_type_ == Read)
1449+
return;
1450+
1451+
direct_sync_write_.push_back(new dynamixel::GroupSyncWrite(port, packet_handler, item->address_, msg->data_length));
1452+
1453+
direct_sync_write_[direct_sync_write_.size() - 1]->addParam(device->id_, (uint8_t *)(msg->data.data()));
1454+
}
1455+
14081456
void RobotisController::syncWriteItemCallback(const robotis_controller_msgs::SyncWriteItem::ConstPtr &msg)
14091457
{
14101458
for (int i = 0; i < msg->joint_name.size(); i++)
@@ -1430,7 +1478,18 @@ void RobotisController::syncWriteItemCallback(const robotis_controller_msgs::Syn
14301478
}
14311479
}
14321480

1433-
ControlTableItem *item = device->ctrl_table_[msg->item_name];
1481+
// ControlTableItem *item = device->ctrl_table_[msg->item_name];
1482+
ControlTableItem *item = NULL;
1483+
auto item_it = device->ctrl_table_.find(msg->item_name);
1484+
if(item_it != device->ctrl_table_.end())
1485+
{
1486+
item = item_it->second;
1487+
}
1488+
else
1489+
{
1490+
ROS_WARN("SyncWriteItem] Unknown item : %s", msg->item_name.c_str());
1491+
continue;
1492+
}
14341493

14351494
dynamixel::PortHandler *port = robot_->ports_[device->port_name_];
14361495
dynamixel::PacketHandler *packet_handler = dynamixel::PacketHandler::getPacketHandler(device->protocol_version_);
@@ -1519,11 +1578,6 @@ void RobotisController::setCtrlModuleCallback(const std_msgs::String::ConstPtr &
15191578
{
15201579
std::string _module_name_to_set = msg->data;
15211580

1522-
1523-
1524-
1525-
1526-
15271581
set_module_thread_ = boost::thread(boost::bind(&RobotisController::setCtrlModuleThread, this, _module_name_to_set));
15281582
}
15291583

@@ -1756,18 +1810,6 @@ void RobotisController::setCtrlModuleThread(std::string ctrl_module)
17561810
// stop module
17571811
std::list<MotionModule *> stop_modules;
17581812

1759-
ROS_INFO("----- Before -----");
1760-
for (auto& d_it : robot_->dxls_)
1761-
{
1762-
std::string joint_name = d_it.first;
1763-
1764-
Dynamixel *dxl = d_it.second;
1765-
double goal_position = dxl->dxl_state_->goal_position_;
1766-
1767-
fprintf(stderr, "%s : %f \n", joint_name.c_str(), goal_position);
1768-
}
1769-
ROS_INFO("----- ----- -----");
1770-
17711813
if (ctrl_module == "" || ctrl_module == "none")
17721814
{
17731815
// enqueue all modules in order to stop
@@ -1973,19 +2015,6 @@ void RobotisController::setCtrlModuleThread(std::string ctrl_module)
19732015

19742016
if (current_module_msg.joint_name.size() == current_module_msg.module_name.size())
19752017
current_module_pub_.publish(current_module_msg);
1976-
1977-
1978-
ROS_INFO("----- After -----");
1979-
for (auto& d_it : robot_->dxls_)
1980-
{
1981-
std::string joint_name = d_it.first;
1982-
1983-
Dynamixel *dxl = d_it.second;
1984-
double goal_position = dxl->dxl_state_->goal_position_;
1985-
1986-
fprintf(stderr, "%s : %f \n", joint_name.c_str(), goal_position);
1987-
}
1988-
ROS_INFO("----- ----- -----");
19892018
}
19902019

19912020
void RobotisController::gazeboJointStatesCallback(const sensor_msgs::JointState::ConstPtr &msg)

0 commit comments

Comments
 (0)