Skip to content

Dynamixel SDK cpp RAII updates#681

Open
GyuH13 wants to merge 11 commits into
mainfrom
feature-cpp-raii
Open

Dynamixel SDK cpp RAII updates#681
GyuH13 wants to merge 11 commits into
mainfrom
feature-cpp-raii

Conversation

@GyuH13

@GyuH13 GyuH13 commented Apr 13, 2026

Copy link
Copy Markdown
Member

This PR refactors the C++ SDK and ROS 2 C++ wrapper internals to use RAII-based buffer management instead of manual new[]/delete[] and malloc/free. Dynamic packet, group read/write, and error buffers are migrated to std::vector<uint8_t>, reducing manual memory handling and making ownership clearer across the packet handlers, group handlers, and fast read paths.

In addition, the PR updates package and library versioning for the 5.0.0 release. The standalone C++ library and ROS 2 shared library now declare VERSION 5.0.0 and SOVERSION 3 to reflect the C++ ABI change caused by public class layout updates. Related version metadata was also aligned across C, C++, Python, documentation, Arduino metadata, and ROS package manifests/changelogs.

The PR also revises the standalone C++ uninstall flow. Instead of relying on install_manifest.txt, the uninstall script now removes SDK-owned install paths by name under the configured install prefix, including headers, libraries, CMake package files, and shared data such as the control table.

GyuH13 added 7 commits April 7, 2026 17:54
…ng with the new release. Enhancements include safer dynamic storage in C++ SDK and unified versioning.
….0 and SOVERSION 3 for ROS 2 shared library, and updated uninstall process to remove SDK-owned paths by name.
…local buffers, replacing them with stack-allocated vectors for improved memory management and performance.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request upgrades the Dynamixel SDK to version 5.0.0, transitioning from manual memory management to std::vector for group and packet buffers in both the standalone C++ SDK and ROS 2 wrappers. The update also includes modernizing casts to static_cast, replacing bzero with memset, and refactoring the CMake uninstall logic. Review feedback focuses on enhancing robustness by using std::vector::size() instead of manual length calculations during packet transmission, which prevents potential buffer over-reads if parameter population is incomplete.

Comment thread c++/src/dynamixel_sdk/group_bulk_write.cpp Outdated
Comment thread c++/src/dynamixel_sdk/group_sync_write.cpp Outdated
Comment thread ros/dynamixel_sdk/src/dynamixel_sdk/group_bulk_write.cpp Outdated
Comment thread ros/dynamixel_sdk/src/dynamixel_sdk/group_sync_write.cpp Outdated
Comment thread c++/src/dynamixel_sdk/group_bulk_read.cpp
Comment thread c++/src/dynamixel_sdk/group_bulk_read.cpp
Comment thread c++/src/dynamixel_sdk/group_sync_read.cpp
Comment thread c++/src/dynamixel_sdk/group_fast_bulk_read.cpp
GyuH13 added 2 commits April 14, 2026 15:37
…ite classes to prevent transmission errors. Return COMM_TX_ERROR for invalid parameter sizes before executing write operations.
@GyuH13 GyuH13 self-assigned this Apr 14, 2026
GyuH13 added 2 commits April 16, 2026 13:19
…lecting the new release. Changes include enhancements in the C++ SDK and consistent versioning across C, C++, Python, and ROS 2 packages.

@Jack-Punter Jack-Punter left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just came to take a look at to see how these functions where working for something and one things thats bugged me when i've looked before is the use of dynamic memory, espicially in the read/write paths which in practice are likely to be used in hot-loops in controllers where people might desire some real-time guarantees. I noticed this PR, thought i'd have a look and see whats being changed.

I haven't done a thorough review, just looking at some of the places I was interested in in my investigation and imo theres room to remove some of the allocations that are going on here, especially in the "fast" read paths. While your changes definitely improve the situation by only doing one allocaiton per instance, I think itd be better to avoid the allocation and indirection entierly.

Comment on lines +82 to +84
if (rxpacket_.size() < static_cast<size_t>(RXPACKET_MAX_LEN))
rxpacket_.resize(static_cast<size_t>(RXPACKET_MAX_LEN));
uint8_t *rxpacket = rxpacket_.data();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is definitely better than doing a malloc/free evey time you read from the bus, im of the opinion it would be better to avoid memory allocations and the additional branch (even if it will only trigger once) in these methods all together. Especially as they're likely to be used in hot-loops where real-time considerations might need to be made.
RXPACKET_MAX_LEN is only 250 bytes so this could easily just be a static array either as a member or just as a local.

Comment on lines +64 to +66
if (rxpacket_.size() < static_cast<size_t>(RXPACKET_MAX_LEN))
rxpacket_.resize(static_cast<size_t>(RXPACKET_MAX_LEN));
uint8_t *rxpacket = rxpacket_.data();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here and in the same 2 places in the ros folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants