@@ -1109,14 +1109,64 @@ void RobotisController::process()
1109
1109
{
1110
1110
if (gazebo_mode_ == false )
1111
1111
{
1112
- queue_mutex_.lock ();
1112
+ // BulkRead Rx
1113
+ for (auto & it : port_to_bulk_read_)
1114
+ {
1115
+ robot_->ports_ [it.first ]->setPacketTimeout (0.0 );
1116
+ it.second ->rxPacket ();
1117
+ }
1113
1118
1114
- for (auto & it : port_to_sync_write_position_)
1119
+ // -> save to robot->dxls_[]->dxl_state_
1120
+ if (robot_->dxls_ .size () > 0 )
1115
1121
{
1116
- it.second ->txPacket ();
1117
- it.second ->clearParam ();
1122
+ for (auto & dxl_it : robot_->dxls_ )
1123
+ {
1124
+ Dynamixel *dxl = dxl_it.second ;
1125
+ std::string port_name = dxl_it.second ->port_name_ ;
1126
+ std::string joint_name = dxl_it.first ;
1127
+
1128
+ if (dxl->bulk_read_items_ .size () > 0 )
1129
+ {
1130
+ uint32_t data = 0 ;
1131
+ for (int i = 0 ; i < dxl->bulk_read_items_ .size (); i++)
1132
+ {
1133
+ ControlTableItem *item = dxl->bulk_read_items_ [i];
1134
+ if (port_to_bulk_read_[port_name]->isAvailable (dxl->id_ , item->address_ , item->data_length_ ) == true )
1135
+ {
1136
+ data = port_to_bulk_read_[port_name]->getData (dxl->id_ , item->address_ , item->data_length_ );
1137
+
1138
+ // change dxl_state
1139
+ if (dxl->present_position_item_ != 0 && item->item_name_ == dxl->present_position_item_ ->item_name_ )
1140
+ dxl->dxl_state_ ->present_position_ = dxl->convertValue2Radian (data) - dxl->dxl_state_ ->position_offset_ ; // remove offset
1141
+ else if (dxl->present_velocity_item_ != 0 && item->item_name_ == dxl->present_velocity_item_ ->item_name_ )
1142
+ dxl->dxl_state_ ->present_velocity_ = dxl->convertValue2Velocity (data);
1143
+ else if (dxl->present_current_item_ != 0 && item->item_name_ == dxl->present_current_item_ ->item_name_ )
1144
+ dxl->dxl_state_ ->present_torque_ = dxl->convertValue2Torque (data);
1145
+ else if (dxl->goal_position_item_ != 0 && item->item_name_ == dxl->goal_position_item_ ->item_name_ )
1146
+ dxl->dxl_state_ ->goal_position_ = dxl->convertValue2Radian (data) - dxl->dxl_state_ ->position_offset_ ; // remove offset
1147
+ else if (dxl->goal_velocity_item_ != 0 && item->item_name_ == dxl->goal_velocity_item_ ->item_name_ )
1148
+ dxl->dxl_state_ ->goal_velocity_ = dxl->convertValue2Velocity (data);
1149
+ else if (dxl->goal_current_item_ != 0 && item->item_name_ == dxl->goal_current_item_ ->item_name_ )
1150
+ dxl->dxl_state_ ->goal_torque_ = dxl->convertValue2Torque (data);
1151
+ else
1152
+ dxl->dxl_state_ ->bulk_read_table_ [item->item_name_ ] = data;
1153
+ }
1154
+ }
1155
+
1156
+ // -> update time stamp to Robot->dxls[]->dynamixel_state.update_time_stamp
1157
+ dxl->dxl_state_ ->update_time_stamp_ = TimeStamp (present_state.header .stamp .sec , present_state.header .stamp .nsec );
1158
+ }
1159
+ }
1118
1160
}
1119
1161
1162
+ queue_mutex_.lock ();
1163
+
1164
+ // for (auto& it : port_to_sync_write_position_)
1165
+ // {
1166
+ // it.second->txPacket();
1167
+ // it.second->clearParam();
1168
+ // }
1169
+
1120
1170
if (direct_sync_write_.size () > 0 )
1121
1171
{
1122
1172
for (int i = 0 ; i < direct_sync_write_.size (); i++)
@@ -1128,6 +1178,10 @@ void RobotisController::process()
1128
1178
}
1129
1179
1130
1180
queue_mutex_.unlock ();
1181
+
1182
+ // BulkRead Tx
1183
+ for (auto & it : port_to_bulk_read_)
1184
+ it.second ->txPacket ();
1131
1185
}
1132
1186
}
1133
1187
@@ -1553,9 +1607,22 @@ void RobotisController::syncWriteItemCallback(const robotis_controller_msgs::Syn
1553
1607
void RobotisController::setControllerModeCallback (const std_msgs::String::ConstPtr &msg)
1554
1608
{
1555
1609
if (msg->data == " DirectControlMode" )
1610
+ {
1611
+ for (auto & it : port_to_bulk_read_)
1612
+ {
1613
+ robot_->ports_ [it.first ]->setPacketTimeout (0.0 );
1614
+ it.second ->rxPacket ();
1615
+ }
1556
1616
controller_mode_ = DirectControlMode;
1617
+ }
1557
1618
else if (msg->data == " MotionModuleMode" )
1619
+ {
1620
+ for (auto & it : port_to_bulk_read_)
1621
+ {
1622
+ it.second ->txPacket ();
1623
+ }
1558
1624
controller_mode_ = MotionModuleMode;
1625
+ }
1559
1626
}
1560
1627
1561
1628
void RobotisController::setJointStatesCallback (const sensor_msgs::JointState::ConstPtr &msg)
0 commit comments