Skip to content

Commit 1b7d690

Browse files
committed
- packet timeout in broadcastPing() overflow bug fixed.
- bug in python removeStuffing() fixed.
1 parent 1cff9c9 commit 1b7d690

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

c++/src/dynamixel_sdk/protocol2_packet_handler.cpp

100755100644
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ int Protocol2PacketHandler::broadcastPing(PortHandler *port, std::vector<uint8_t
506506
uint8_t txpacket[10] = {0};
507507
uint8_t rxpacket[STATUS_LENGTH * MAX_ID] = {0};
508508

509+
double tx_time_per_byte = (1000.0 / (double)port->getBaudRate()) * 10.0;
510+
509511
txpacket[PKT_ID] = BROADCAST_ID;
510512
txpacket[PKT_LENGTH_L] = 3;
511513
txpacket[PKT_LENGTH_H] = 0;
@@ -519,7 +521,8 @@ int Protocol2PacketHandler::broadcastPing(PortHandler *port, std::vector<uint8_t
519521
}
520522

521523
// set rx timeout
522-
port->setPacketTimeout((uint16_t)(wait_length * 30));
524+
//port->setPacketTimeout((uint16_t)(wait_length * 30));
525+
port->setPacketTimeout(((double)wait_length * tx_time_per_byte) + (3.0 * (double)MAX_ID) + 16.0);
523526

524527
while(1)
525528
{

c/src/dynamixel_sdk/protocol2_packet_handler.c

100755100644
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,8 @@ void broadcastPing2(int port_num)
577577
uint16_t rx_length = 0;
578578
uint16_t wait_length = STATUS_LENGTH * MAX_ID;
579579

580+
double tx_time_per_byte = (1000.0 / (double)getBaudRate(port_num)) * 10.0;
581+
580582
packetData[port_num].broadcast_ping_id_list = (uint8_t *)calloc(255, sizeof(uint8_t));
581583
if (packetData[port_num].broadcast_ping_id_list == NULL)
582584
{
@@ -610,7 +612,8 @@ void broadcastPing2(int port_num)
610612
}
611613

612614
// set rx timeout
613-
setPacketTimeout(port_num, (uint16_t)(wait_length * 30));
615+
//setPacketTimeout(port_num, (uint16_t)(wait_length * 30));
616+
setPacketTimeoutMSec(port_num, ((double)wait_length * tx_time_per_byte) + (3.0 * (double)MAX_ID) + 16.0);
614617

615618
while (1)
616619
{

python/src/dynamixel_sdk/protocol2_packet_handler.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
from .robotis_def import *
2323

24-
TXPACKET_MAX_LEN = 4 * 1024
25-
RXPACKET_MAX_LEN = 4 * 1024
24+
TXPACKET_MAX_LEN = 1 * 1024
25+
RXPACKET_MAX_LEN = 1 * 1024
2626

2727
# for Protocol 2.0 Packet
2828
PKT_HEADER0 = 0
@@ -383,6 +383,8 @@ def broadcastPing(self, port):
383383
txpacket = [0] * 10
384384
rxpacket = []
385385

386+
tx_time_per_byte = (1000.0 / port.getBaudRate()) *10.0;
387+
386388
txpacket[PKT_ID] = BROADCAST_ID
387389
txpacket[PKT_LENGTH_L] = 3
388390
txpacket[PKT_LENGTH_H] = 0
@@ -394,7 +396,8 @@ def broadcastPing(self, port):
394396
return data_list, result
395397

396398
# set rx timeout
397-
port.setPacketTimeout(wait_length * 1)
399+
#port.setPacketTimeout(wait_length * 1)
400+
port.setPacketTimeoutMillis((wait_length * tx_time_per_byte) + (3.0 * MAX_ID) + 16.0);
398401

399402
while True:
400403
rxpacket += port.readPort(wait_length - rx_length)

ros/src/dynamixel_sdk/protocol2_packet_handler.cpp

100755100644
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ int Protocol2PacketHandler::broadcastPing(PortHandler *port, std::vector<uint8_t
506506
uint8_t txpacket[10] = {0};
507507
uint8_t rxpacket[STATUS_LENGTH * MAX_ID] = {0};
508508

509+
double tx_time_per_byte = (1000.0 / (double)port->getBaudRate()) * 10.0;
510+
509511
txpacket[PKT_ID] = BROADCAST_ID;
510512
txpacket[PKT_LENGTH_L] = 3;
511513
txpacket[PKT_LENGTH_H] = 0;
@@ -519,7 +521,8 @@ int Protocol2PacketHandler::broadcastPing(PortHandler *port, std::vector<uint8_t
519521
}
520522

521523
// set rx timeout
522-
port->setPacketTimeout((uint16_t)(wait_length * 30));
524+
//port->setPacketTimeout((uint16_t)(wait_length * 30));
525+
port->setPacketTimeout(((double)wait_length * tx_time_per_byte) + (3.0 * (double)MAX_ID) + 16.0);
523526

524527
while(1)
525528
{

ros/src/dynamixel_sdk/protocol2_packet_handler.py

100755100644
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,9 @@ def removeStuffing(self, packet):
197197
packet[i + PKT_INSTRUCTION - 1] == 0xFF) and (packet[i + PKT_INSTRUCTION - 2] == 0xFF):
198198
# FF FF FD FD
199199
packet_length_out = packet_length_out - 1
200-
i += 1
201-
202-
packet[index] = packet[i + PKT_INSTRUCTION]
203-
index += 1
200+
else:
201+
packet[index] = packet[i + PKT_INSTRUCTION]
202+
index += 1
204203

205204
packet[index] = packet[PKT_INSTRUCTION + packet_length_in - 2]
206205
packet[index + 1] = packet[PKT_INSTRUCTION + packet_length_in - 1]
@@ -384,6 +383,8 @@ def broadcastPing(self, port):
384383
txpacket = [0] * 10
385384
rxpacket = []
386385

386+
tx_time_per_byte = (1000.0 / port.getBaudRate()) *10.0;
387+
387388
txpacket[PKT_ID] = BROADCAST_ID
388389
txpacket[PKT_LENGTH_L] = 3
389390
txpacket[PKT_LENGTH_H] = 0
@@ -395,7 +396,8 @@ def broadcastPing(self, port):
395396
return data_list, result
396397

397398
# set rx timeout
398-
port.setPacketTimeout(wait_length * 1)
399+
#port.setPacketTimeout(wait_length * 1)
400+
port.setPacketTimeoutMillis((wait_length * tx_time_per_byte) + (3.0 * MAX_ID) + 16.0);
399401

400402
while True:
401403
rxpacket += port.readPort(wait_length - rx_length)

0 commit comments

Comments
 (0)