@@ -621,6 +621,8 @@ void RobotisController::msgQueueThread()
621
621
ros_node.setCallbackQueue (&callback_queue);
622
622
623
623
/* subscriber */
624
+ ros::Subscriber write_control_table_sub = ros_node.subscribe (" /robotis/write_control_table" , 5 ,
625
+ &RobotisController::writeControlTableCallback, this );
624
626
ros::Subscriber sync_write_item_sub = ros_node.subscribe (" /robotis/sync_write_item" , 10 ,
625
627
&RobotisController::syncWriteItemCallback, this );
626
628
ros::Subscriber joint_ctrl_modules_sub = ros_node.subscribe (" /robotis/set_joint_ctrl_modules" , 10 ,
@@ -1405,6 +1407,52 @@ void RobotisController::removeSensorModule(SensorModule *module)
1405
1407
sensor_modules_.remove (module );
1406
1408
}
1407
1409
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
+
1408
1456
void RobotisController::syncWriteItemCallback (const robotis_controller_msgs::SyncWriteItem::ConstPtr &msg)
1409
1457
{
1410
1458
for (int i = 0 ; i < msg->joint_name .size (); i++)
@@ -1430,7 +1478,18 @@ void RobotisController::syncWriteItemCallback(const robotis_controller_msgs::Syn
1430
1478
}
1431
1479
}
1432
1480
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
+ }
1434
1493
1435
1494
dynamixel::PortHandler *port = robot_->ports_ [device->port_name_ ];
1436
1495
dynamixel::PacketHandler *packet_handler = dynamixel::PacketHandler::getPacketHandler (device->protocol_version_ );
@@ -1519,11 +1578,6 @@ void RobotisController::setCtrlModuleCallback(const std_msgs::String::ConstPtr &
1519
1578
{
1520
1579
std::string _module_name_to_set = msg->data ;
1521
1580
1522
-
1523
-
1524
-
1525
-
1526
-
1527
1581
set_module_thread_ = boost::thread (boost::bind (&RobotisController::setCtrlModuleThread, this , _module_name_to_set));
1528
1582
}
1529
1583
@@ -1756,18 +1810,6 @@ void RobotisController::setCtrlModuleThread(std::string ctrl_module)
1756
1810
// stop module
1757
1811
std::list<MotionModule *> stop_modules;
1758
1812
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
-
1771
1813
if (ctrl_module == " " || ctrl_module == " none" )
1772
1814
{
1773
1815
// enqueue all modules in order to stop
@@ -1973,19 +2015,6 @@ void RobotisController::setCtrlModuleThread(std::string ctrl_module)
1973
2015
1974
2016
if (current_module_msg.joint_name .size () == current_module_msg.module_name .size ())
1975
2017
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 (" ----- ----- -----" );
1989
2018
}
1990
2019
1991
2020
void RobotisController::gazeboJointStatesCallback (const sensor_msgs::JointState::ConstPtr &msg)
0 commit comments