@@ -926,6 +926,10 @@ DxlError Dynamixel::SetSyncReadHandler(std::vector<uint8_t> id_arr)
926926 " set sync read (indirect addr) : addr %d, size %d\n " ,
927927 IN_ADDR, indirect_info_read_[id_arr.at (0 )].size );
928928
929+ if (group_sync_read_) {
930+ delete group_sync_read_;
931+ group_sync_read_ = nullptr ;
932+ }
929933 group_sync_read_ =
930934 new dynamixel::GroupSyncRead (
931935 port_handler_, packet_handler_,
@@ -1014,6 +1018,16 @@ DxlError Dynamixel::GetDxlValueFromSyncRead(double period_ms)
10141018
10151019DxlError Dynamixel::SetBulkReadItemAndHandler ()
10161020{
1021+ if (group_fast_bulk_read_) {
1022+ delete group_fast_bulk_read_;
1023+ group_fast_bulk_read_ = nullptr ;
1024+ }
1025+ group_fast_bulk_read_ = new dynamixel::GroupFastBulkRead (port_handler_, packet_handler_);
1026+
1027+ if (group_bulk_read_) {
1028+ delete group_bulk_read_;
1029+ group_bulk_read_ = nullptr ;
1030+ }
10171031 group_bulk_read_ = new dynamixel::GroupBulkRead (port_handler_, packet_handler_);
10181032
10191033 std::vector<uint8_t > indirect_id_arr;
@@ -1216,6 +1230,17 @@ DxlError Dynamixel::AddDirectRead(
12161230 id, item_name.c_str (), item_addr, item_size);
12171231 return DxlError::SET_BULK_READ_FAIL;
12181232 }
1233+
1234+ if (group_fast_bulk_read_->addParam (id, item_addr, item_size) == true ) {
1235+ fprintf (
1236+ stderr, " [ID:%03d] Add FastBulkRead item : [%s][%d][%d]\n " ,
1237+ id, item_name.c_str (), item_addr, item_size);
1238+ } else {
1239+ fprintf (
1240+ stderr, " [ID:%03d] Failed to FastBulkRead item : [%s][%d][%d]\n " ,
1241+ id, item_name.c_str (), item_addr, item_size);
1242+ return DxlError::SET_BULK_READ_FAIL;
1243+ }
12191244 return DxlError::OK;
12201245}
12211246
@@ -1230,6 +1255,11 @@ DxlError Dynamixel::GetDxlValueFromBulkRead(double period_ms)
12301255 DxlError comm_result = ProcessReadCommunication (port_handler_, period_ms, false , true );
12311256 if (comm_result == DxlError::OK) {
12321257 // Success, process data, and use fast bulk read permanently
1258+ if (group_bulk_read_) {
1259+ delete group_bulk_read_;
1260+ group_bulk_read_ = nullptr ;
1261+ }
1262+
12331263 for (auto it_read_data : read_data_list_) {
12341264 uint8_t id = it_read_data.id ;
12351265 uint16_t indirect_addr = indirect_info_read_[id].indirect_data_addr ;
@@ -1240,7 +1270,7 @@ DxlError Dynamixel::GetDxlValueFromBulkRead(double period_ms)
12401270 it_read_data.item_size ,
12411271 it_read_data.item_data_ptr_vec ,
12421272 [this ](uint8_t id, uint16_t addr, uint8_t size) {
1243- return group_bulk_read_ ->getData (id, addr, size);
1273+ return group_fast_bulk_read_ ->getData (id, addr, size);
12441274 });
12451275 } else {
12461276 ProcessReadData (
@@ -1250,7 +1280,7 @@ DxlError Dynamixel::GetDxlValueFromBulkRead(double period_ms)
12501280 indirect_info_read_[id].item_size ,
12511281 it_read_data.item_data_ptr_vec ,
12521282 [this ](uint8_t id, uint16_t addr, uint8_t size) {
1253- return group_bulk_read_ ->getData (id, addr, size);
1283+ return group_fast_bulk_read_ ->getData (id, addr, size);
12541284 });
12551285 }
12561286 }
@@ -1262,6 +1292,10 @@ DxlError Dynamixel::GetDxlValueFromBulkRead(double period_ms)
12621292 ++fast_read_fail_count_;
12631293 fprintf (stderr, " FastBulkRead TxRx failed (attempt %d/10)\n " , fast_read_fail_count_);
12641294 if (fast_read_fail_count_ >= 10 ) {
1295+ if (group_fast_bulk_read_) {
1296+ delete group_fast_bulk_read_;
1297+ group_fast_bulk_read_ = nullptr ;
1298+ }
12651299 // Permanently switch to normal bulk read
12661300 fprintf (stderr,
12671301 " FastBulkRead failed 10 times, switching to normal BulkRead permanently.\n " );
0 commit comments