-
Notifications
You must be signed in to change notification settings - Fork 468
Dynamixel Easy SDK update in cpp linux 64bit #664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GyuH13
wants to merge
37
commits into
main
Choose a base branch
from
feature-api-update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
0c29a54
api update in cpp linux 64bit
GyuH13 ed28160
Add exception in input param of getAllMotors
GyuH13 73c37dc
Use Makefile macro for control table path instead of hardcoding
GyuH13 be4e0a7
remove duplicate model_list
GyuH13 c530947
fix indentation
GyuH13 2ecc213
make getmotor function return unique_ptr
GyuH13 c469d8b
apply guard clause to improve readability
GyuH13 9865753
delete tab
GyuH13 f28c620
apply broadcastPing to getAllmotors function
GyuH13 f67d1d9
makefile typo error
GyuH13 f0485ca
add example
GyuH13 6ed0156
lint
GyuH13 fb3609a
Bump
GyuH13 c7ecd45
add const return in dxl Result object
GyuH13 a39c5d0
Remove changebaudrate
GyuH13 c75d8e7
header guard fix
GyuH13 ca75cf2
Make drive mode setup function to use parameter
GyuH13 2cc597e
example code update
GyuH13 080fb44
add motor group
GyuH13 1276415
add motor group
GyuH13 4ddebcf
remove example
GyuH13 7fa6d53
add pid gain function
GyuH13 cef960a
add current function
GyuH13 baad93e
unified motor object with motor proxy
GyuH13 bfb62ef
change function name which is named getMotor to createMotor
GyuH13 3ef96ec
remove motor header in group_executor.hpp
GyuH13 0af6a8a
lint
GyuH13 970dddf
bump
GyuH13 5a4733f
bump
GyuH13 aaff0f1
remove protocol arg in connector
GyuH13 b87a605
add error checking
GyuH13 90d55c6
change file structure
GyuH13 1f812ea
modified makefile
GyuH13 0052c5c
bump
GyuH13 160e3b9
change name of package to Easy SDK
GyuH13 0a4f971
reflect review
GyuH13 693076c
reflect review
GyuH13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Copyright 2025 ROBOTIS CO., LTD. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // Author: Hyungyu Kim | ||
|
|
||
| #ifndef DYNAMIXEL_SDK_INCLUDE_DYNAMIXEL_EASY_SDK_CONNECTOR_HPP_ | ||
| #define DYNAMIXEL_SDK_INCLUDE_DYNAMIXEL_EASY_SDK_CONNECTOR_HPP_ | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "dynamixel_sdk/dynamixel_sdk.h" | ||
| #include "dynamixel_easy_sdk/dynamixel_error.hpp" | ||
| #include "dynamixel_easy_sdk/motor.hpp" | ||
| #include "dynamixel_easy_sdk/group_executor.hpp" | ||
|
|
||
| namespace dynamixel | ||
| { | ||
| class Connector | ||
| { | ||
| public: | ||
| Connector(const std::string & port_name, int baud_rate); | ||
|
|
||
| virtual ~Connector(); | ||
|
|
||
| std::unique_ptr<Motor> createMotor(uint8_t id); | ||
| std::vector<std::unique_ptr<Motor>> createAllMotors(int start_id = 0, int end_id = 252); | ||
| std::unique_ptr<GroupExecutor> createGroupExecutor(); | ||
|
|
||
| Result<void, DxlError> write1ByteData(uint8_t id, uint16_t address, uint8_t value); | ||
| Result<void, DxlError> write2ByteData(uint8_t id, uint16_t address, uint16_t value); | ||
| Result<void, DxlError> write4ByteData(uint8_t id, uint16_t address, uint32_t value); | ||
|
|
||
| Result<uint8_t, DxlError> read1ByteData(uint8_t id, uint16_t address); | ||
| Result<uint16_t, DxlError> read2ByteData(uint8_t id, uint16_t address); | ||
| Result<uint32_t, DxlError> read4ByteData(uint8_t id, uint16_t address); | ||
|
|
||
| Result<void, DxlError> reboot(uint8_t id); | ||
| Result<uint16_t, DxlError> ping(uint8_t id); | ||
| Result<void, DxlError> factoryReset(uint8_t id, uint8_t option); | ||
|
|
||
| PortHandler * getPortHandler() const {return port_handler_.get();} | ||
| PacketHandler * getPacketHandler() const {return packet_handler_;} | ||
|
|
||
| private: | ||
| std::unique_ptr<PortHandler> port_handler_; | ||
| PacketHandler * packet_handler_; | ||
| }; | ||
| } // namespace dynamixel | ||
| #endif /* DYNAMIXEL_SDK_INCLUDE_DYNAMIXEL_EASY_SDK_CONNECTOR_HPP_ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright 2025 ROBOTIS CO., LTD. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // Author: Hyungyu Kim | ||
|
|
||
| #ifndef DYNAMIXEL_SDK_INCLUDE_DYNAMIXEL_EASY_SDK_CONTROL_TABLE_HPP_ | ||
| #define DYNAMIXEL_SDK_INCLUDE_DYNAMIXEL_EASY_SDK_CONTROL_TABLE_HPP_ | ||
|
|
||
| #include <cstdint> | ||
| #include <fstream> | ||
| #include <iostream> | ||
| #include <map> | ||
| #include <sstream> | ||
| #include <string> | ||
|
|
||
| #include "dynamixel_easy_sdk/dynamixel_error.hpp" | ||
|
|
||
| namespace dynamixel | ||
| { | ||
| struct ControlTableItem | ||
| { | ||
| uint16_t address; | ||
| uint8_t size; | ||
| }; | ||
|
|
||
| class ControlTable | ||
| { | ||
| public: | ||
| static const std::map<uint16_t, std::string> ParsingModelList(); | ||
| static const std::string getModelName(uint16_t model_number); | ||
| static const std::map<std::string, ControlTableItem> & getControlTable(uint16_t model_number); | ||
| }; | ||
| } // namespace dynamixel | ||
| #endif /* DYNAMIXEL_SDK_INCLUDE_DYNAMIXEL_EASY_SDK_CONTROL_TABLE_HPP_ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Copyright 2025 ROBOTIS CO., LTD. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // Author: Hyungyu Kim | ||
|
|
||
| #ifndef DYNAMIXEL_SDK_INCLUDE_DYNAMIXEL_EASY_SDK_DYNAMIXEL_EASY_SDK_HPP_ | ||
| #define DYNAMIXEL_SDK_INCLUDE_DYNAMIXEL_EASY_SDK_DYNAMIXEL_EASY_SDK_HPP_ | ||
|
|
||
|
|
||
| #include "dynamixel_easy_sdk/connector.hpp" | ||
| #include "dynamixel_easy_sdk/dynamixel_error.hpp" | ||
| #include "dynamixel_easy_sdk/motor.hpp" | ||
| #include "dynamixel_easy_sdk/group_executor.hpp" | ||
|
|
||
| #endif /* DYNAMIXEL_SDK_INCLUDE_DYNAMIXEL_EASY_SDK_DYNAMIXEL_EASY_SDK_HPP_ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| // Copyright 2025 ROBOTIS CO., LTD. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // Author: Hyungyu Kim | ||
|
|
||
| #ifndef DYNAMIXEL_SDK_INCLUDE_DYNAMIXEL_EASY_SDK_DYNAMIXEL_ERROR_HPP_ | ||
| #define DYNAMIXEL_SDK_INCLUDE_DYNAMIXEL_EASY_SDK_DYNAMIXEL_ERROR_HPP_ | ||
|
|
||
| #include <variant> | ||
| #include <stdexcept> | ||
| #include <string> | ||
|
|
||
| namespace dynamixel | ||
| { | ||
| enum class DxlError | ||
| { | ||
| SDK_COMM_SUCCESS = 0, // tx or rx packet communication success | ||
| SDK_COMM_PORT_BUSY = -1000, // Port is busy (in use) | ||
| SDK_COMM_TX_FAIL = -1001, // Failed transmit instruction packet | ||
| SDK_COMM_RX_FAIL = -1002, // Failed get status packet | ||
| SDK_COMM_TX_ERROR = -2000, // Incorrect instruction packet | ||
| SDK_COMM_RX_WAITING = -3000, // Now receiving status packet | ||
| SDK_COMM_RX_TIMEOUT = -3001, // There is no status packet | ||
| SDK_COMM_RX_CORRUPT = -3002, // Incorrect status packet | ||
| SDK_COMM_NOT_AVAILABLE = -9000, | ||
| SDK_ERRNUM_RESULT_FAIL = 1, // Failed to process the instruction packet. | ||
| SDK_ERRNUM_INSTRUCTION = 2, // Instruction error | ||
| SDK_ERRNUM_CRC = 3, // CRC check error | ||
| SDK_ERRNUM_DATA_RANGE = 4, // Data range error | ||
| SDK_ERRNUM_DATA_LENGTH = 5, // Data length error | ||
| SDK_ERRNUM_DATA_LIMIT = 6, // Data limit error | ||
| SDK_ERRNUM_ACCESS = 7, // Access error | ||
| EASY_SDK_FUNCTION_NOT_SUPPORTED = 11, // API does not support this function | ||
| EASY_SDK_MOTOR_TORQUE_OFF = 12, // Motor torque is off | ||
| EASY_SDK_OPERATING_MODE_MISMATCH = 13, // Operating mode is not appropriate for this function | ||
| EASY_SDK_ADD_PARAM_FAIL = 21, // Failed to add parameter | ||
| EASY_SDK_COMMAND_IS_EMPTY = 22, // No command to execute | ||
| EASY_SDK_DUPLICATE_ID = 23, // Duplicate ID in staged commands | ||
| EASY_SDK_FAIL_TO_GET_DATA = 24 // Failed to get data from motor | ||
| }; | ||
|
|
||
| template<typename T, typename E> | ||
| class Result | ||
| { | ||
| private: | ||
| std::variant<T, E> result; | ||
|
|
||
| public: | ||
| Result() = default; | ||
| Result(const T & return_value) | ||
| : result(return_value) | ||
| {} | ||
|
|
||
| Result(const E & error) | ||
| : result(error) | ||
| {} | ||
|
|
||
| bool isSuccess() const | ||
| { | ||
| return std::holds_alternative<T>(result); | ||
| } | ||
|
|
||
| T & value() | ||
| { | ||
| if (!isSuccess()) {throw std::logic_error("Result has no value.");} | ||
| return std::get<T>(result); | ||
| } | ||
| const T & value() const | ||
| { | ||
| if (!isSuccess()) {throw std::logic_error("Result has no value.");} | ||
| return std::get<T>(result); | ||
| } | ||
|
|
||
GyuH13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| E & error() | ||
| { | ||
| if (isSuccess()) {throw std::logic_error("Result has no error.");} | ||
| return std::get<E>(result); | ||
| } | ||
|
|
||
| const E & error() const | ||
| { | ||
| if (isSuccess()) {throw std::logic_error("Result has no error.");} | ||
| return std::get<E>(result); | ||
| } | ||
| }; | ||
|
|
||
| template<typename E> | ||
| class Result<void, E> | ||
| { | ||
| private: | ||
| std::variant<std::monostate, E> result; | ||
|
|
||
| public: | ||
| Result() | ||
| : result(std::monostate{}) | ||
| {} | ||
|
|
||
| Result(const E & error) | ||
| : result(error) | ||
| {} | ||
|
|
||
| bool isSuccess() const | ||
| { | ||
| return std::holds_alternative<std::monostate>(result); | ||
| } | ||
|
|
||
| E & error() | ||
| { | ||
| if (!std::holds_alternative<E>(result)) { | ||
| throw std::logic_error("Result has no error."); | ||
| } | ||
| return std::get<E>(result); | ||
| } | ||
|
|
||
| const E & error() const | ||
| { | ||
| if (!std::holds_alternative<E>(result)) { | ||
| throw std::logic_error("Result has no error."); | ||
| } | ||
| return std::get<E>(result); | ||
| } | ||
| }; | ||
|
|
||
| class DxlRuntimeError : public std::runtime_error | ||
| { | ||
| public: | ||
| explicit DxlRuntimeError(const std::string & message) | ||
| : std::runtime_error(message) {} | ||
| }; | ||
|
|
||
| std::string getErrorMessage(DxlError error_code); | ||
| } // namespace dynamixel | ||
|
|
||
| #endif /* DYNAMIXEL_SDK_INCLUDE_DYNAMIXEL_EASY_SDK_DYNAMIXEL_ERROR_HPP_ */ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.