Repository navigation
Fix busy loop in rxpacket and support baudrates over 230400 in MacOS - #694
Conversation
…ing IOSSIOSPEED. Update documentation to reflect changes in baud rate handling.
… reads and improve error handling. Update Protocol1 and Protocol2 packet handlers to check for read errors.
…/dynamixelsdk into feature-add-pollin
…ly on COMM_RX_FAIL
cho0h5
left a comment
There was a problem hiding this comment.
The poll change does not affect AIS.
LGTM👍
…cket() and improve error handling in the method.
|
I tested this PR with a U2D2 and two DXLs at 1 Mbps.
Would it be possible to add handling for these cases before merging? |
|
yun-goon
left a comment
There was a problem hiding this comment.
Thanks for the clarification. The CPU usage improvement is clear, and I did not observe a ping latency regression when data was ready, so I’m approving this PR.
As a follow-up, please add explicit handling for POLLERR, POLLHUP, and POLLNVAL. When POLLIN | POLLHUP is returned, pending data should be drained first, and terminal errors should then be mapped to -1 so that the upper layer reports COMM_RX_FAIL instead of a timeout.
Summary
poll()inreadPort()to avoid busy-wait. Wait up to 1 ms for serial data before returning.Problem code
PacketHandler::rxPacket()receives a status packet by callingPortHandler::readPort()repeatedly in awhileloop.PortHandler::readPort()callsread()on the serial fd and returns immediately. The fd is opened withO_NONBLOCK, and termios is set toVMIN = 0,VTIME = 0, soread()returns at once when the receive buffer is empty.readPort()returns 0 bytes immediately, and therxPacket()loop spins as fast as it can until the packet timeout.Problems
read()system calls and extra scheduler load.Solution
readPort(), callpoll()on the serial fd beforeread(), and wait up to 1 ms for the fd to become readable. If data arrives, read it immediately. If not, wait 1 ms and return 0.