-
Notifications
You must be signed in to change notification settings - Fork 33
Bump 1.5.0 #95
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
Bump 1.5.0 #95
Changes from all commits
7835626
ab4879c
3229677
1c8563b
d09ef99
9574a83
f292f69
668afd0
fe2eb62
ad32bde
d562b83
324fd61
fcb8b29
4343a04
88ae1fb
d4c7ad6
ee76bca
73e1f97
0477c66
8c3990f
02d1c65
81087c2
156b962
9ba58cf
bd00040
931e073
68d0d28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
| #include <cstdarg> | ||
| #include <memory> | ||
| #include <functional> | ||
| #include <utility> | ||
|
|
||
| namespace dynamixel_hardware_interface | ||
| { | ||
|
|
@@ -164,6 +165,7 @@ typedef struct | |
| */ | ||
| typedef struct | ||
| { | ||
| uint8_t comm_id; ///< Communication ID used to reach the device. | ||
| uint8_t id; ///< ID of the Dynamixel motor. | ||
| ControlItem control_item; ///< Control item details. | ||
| uint32_t data; ///< Data associated with the control item. | ||
|
|
@@ -197,7 +199,7 @@ class Dynamixel | |
| // item write variable | ||
| std::vector<RWItemBufInfo> write_item_buf_; | ||
| std::vector<RWItemBufInfo> read_item_buf_; | ||
| std::map<uint8_t /*id*/, bool> torque_state_; | ||
| std::map<std::pair<uint8_t /*comm_id*/, uint8_t /*id*/>, bool> torque_state_; | ||
|
|
||
| // read item (sync or bulk) variable | ||
| bool read_type_; | ||
|
|
@@ -234,26 +236,25 @@ class Dynamixel | |
| // direct inform for bulk write | ||
| std::map<uint8_t /*id*/, IndirectInfo> direct_info_write_; | ||
|
|
||
| std::map<uint8_t /*id*/, uint8_t> comm_id_; | ||
|
|
||
| public: | ||
| explicit Dynamixel(const char * path); | ||
| ~Dynamixel(); | ||
|
|
||
| // DXL Communication Setting | ||
| DxlError InitDxlComm(std::vector<uint8_t> id_arr, std::string port_name, std::string baudrate); | ||
| DxlError SetupPort(const std::string & port_name, const std::string & baudrate); | ||
| DxlError InitDxlComm(uint8_t comm_id, uint8_t id); | ||
| DxlError Reboot(uint8_t id); | ||
| void RWDataReset(); | ||
|
|
||
| // DXL Read Setting | ||
| DxlError SetDxlReadItems( | ||
| uint8_t id, uint8_t comm_id, std::vector<std::string> item_names, | ||
| uint8_t comm_id, uint8_t id, std::vector<std::string> item_names, | ||
| std::vector<std::shared_ptr<double>> data_vec_ptr); | ||
| DxlError SetMultiDxlRead(); | ||
|
|
||
| // DXL Write Setting | ||
| DxlError SetDxlWriteItems( | ||
| uint8_t id, uint8_t comm_id, std::vector<std::string> item_names, | ||
| uint8_t comm_id, uint8_t id, std::vector<std::string> item_names, | ||
| std::vector<std::shared_ptr<double>> data_vec_ptr); | ||
| DxlError SetMultiDxlWrite(); | ||
|
|
||
|
|
@@ -264,34 +265,44 @@ class Dynamixel | |
|
|
||
| // Set Dxl Option | ||
| // DxlError SetOperatingMode(uint8_t id, uint8_t dynamixel_mode); | ||
| DxlError DynamixelEnable(std::vector<uint8_t> id_arr); | ||
| DxlError DynamixelDisable(std::vector<uint8_t> id_arr); | ||
| DxlError DynamixelEnable(const std::vector<std::pair<uint8_t, uint8_t>> & comm_id_id_arr); | ||
| DxlError DynamixelDisable(const std::vector<std::pair<uint8_t, uint8_t>> & comm_id_id_arr); | ||
|
|
||
| // DXL Item Write | ||
| DxlError WriteItem(uint8_t id, std::string item_name, uint32_t data); | ||
| DxlError WriteItem(uint8_t id, uint16_t addr, uint8_t size, uint32_t data); | ||
| DxlError WriteItem(uint8_t comm_id, uint8_t id, std::string item_name, uint32_t data); | ||
| DxlError WriteItem(uint8_t comm_id, uint8_t id, uint16_t addr, uint8_t size, uint32_t data); | ||
| DxlError InsertWriteItemBuf(uint8_t id, std::string item_name, uint32_t data); | ||
| DxlError WriteItemBuf(); | ||
|
|
||
| // DXL Item Read | ||
| DxlError ReadItem(uint8_t id, std::string item_name, uint32_t & data); | ||
| DxlError ReadItem(uint8_t comm_id, uint8_t id, std::string item_name, uint32_t & data); | ||
| DxlError InsertReadItemBuf(uint8_t id, std::string item_name); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| DxlError ReadItemBuf(); | ||
| bool CheckReadItemBuf(uint8_t id, std::string item_name); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The signature for bool CheckReadItemBuf(uint8_t comm_id, uint8_t id, std::string item_name); |
||
| uint32_t GetReadItemDataBuf(uint8_t id, std::string item_name); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| DynamixelInfo GetDxlInfo() {return dxl_info_;} | ||
| std::map<uint8_t, bool> GetDxlTorqueState() {return torque_state_;} | ||
| std::map<std::pair<uint8_t, uint8_t>, bool> GetDxlTorqueState() {return torque_state_;} | ||
|
|
||
| static std::string DxlErrorToString(DxlError error_num); | ||
|
|
||
| DxlError ReadDxlModelFile(uint8_t id, uint16_t model_num); | ||
| DxlError ReadDxlModelFile(uint8_t id, uint16_t model_num, uint8_t firmware_version); | ||
| DxlError ReadFirmwareVersion(uint8_t id, uint8_t & firmware_version); | ||
| DxlError ReadDxlModelFile(uint8_t comm_id, uint8_t id, uint16_t model_num); | ||
| DxlError ReadDxlModelFile( | ||
| uint8_t comm_id, uint8_t id, uint16_t model_num, | ||
| uint8_t firmware_version); | ||
| DxlError ReadFirmwareVersion(uint8_t comm_id, uint8_t id, uint8_t & firmware_version); | ||
|
|
||
| void SetCommId(uint8_t id, uint8_t comm_id) {comm_id_[id] = comm_id;} | ||
| DxlError InitTorqueStates( | ||
| std::vector<std::pair<uint8_t, uint8_t>> comm_id_id_arr, | ||
| bool disable_torque = false); | ||
|
|
||
| DxlError InitTorqueStates(std::vector<uint8_t> id_arr, bool disable_torque = false); | ||
| void OverrideUnitInfo( | ||
| uint8_t comm_id, | ||
| uint8_t id, | ||
| const std::string & data_name, | ||
| double unit_multiplier, | ||
| bool is_signed, | ||
| double offset_value); | ||
|
|
||
| private: | ||
| bool checkReadType(); | ||
|
|
@@ -334,7 +345,7 @@ class Dynamixel | |
| std::function<uint32_t(uint8_t, uint16_t, uint8_t)> get_data_func); | ||
|
|
||
| DxlError ProcessDirectReadData( | ||
| uint8_t id, | ||
| uint8_t comm_id, | ||
| const std::vector<uint16_t> & item_addrs, | ||
| const std::vector<std::string> & item_names, | ||
| const std::vector<uint8_t> & item_sizes, | ||
|
|
@@ -372,6 +383,7 @@ class Dynamixel | |
|
|
||
| // Helper function for value conversion with unit info | ||
| double ConvertValueWithUnitInfo( | ||
| uint8_t comm_id, | ||
| uint8_t id, | ||
| std::string item_name, | ||
| uint32_t raw_value, | ||
|
|
@@ -380,6 +392,7 @@ class Dynamixel | |
|
|
||
| // Helper function for converting unit values to raw values | ||
| uint32_t ConvertUnitValueToRawValue( | ||
| uint8_t comm_id, | ||
| uint8_t id, | ||
| std::string item_name, | ||
| double unit_value, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,7 @@ typedef struct | |
| std::vector<ControlItem> item; | ||
| std::map<std::string, double> unit_map; | ||
| std::map<std::string, bool> sign_type_map; | ||
| std::map<std::string, double> offset_map; | ||
| } DxlInfo; | ||
|
|
||
| class DynamixelInfo | ||
|
|
@@ -69,56 +70,74 @@ class DynamixelInfo | |
| uint8_t ExtractFirmwareVersionFromFilename(const std::string & filename); | ||
|
|
||
| public: | ||
| // Id, Control table | ||
| std::map<uint8_t, DxlInfo> dxl_info_; | ||
| // comm_id -> (id -> Control table) | ||
| std::map<uint8_t, std::map<uint8_t, DxlInfo>> dxl_info_by_comm_; | ||
|
|
||
| DynamixelInfo() {} | ||
| ~DynamixelInfo() {} | ||
|
|
||
| void SetDxlModelFolderPath(const char * path); | ||
| void InitDxlModelInfo(); | ||
|
|
||
| void ReadDxlModelFile(uint8_t id, uint16_t model_num); | ||
| void ReadDxlModelFile(uint8_t id, uint16_t model_num, uint8_t firmware_version); | ||
| bool GetDxlControlItem(uint8_t id, std::string item_name, uint16_t & addr, uint8_t & size); | ||
| bool CheckDxlControlItem(uint8_t id, std::string item_name); | ||
| void ReadDxlModelFile(uint8_t comm_id, uint8_t id, uint16_t model_num); | ||
| void ReadDxlModelFile(uint8_t comm_id, uint8_t id, uint16_t model_num, uint8_t firmware_version); | ||
| bool GetDxlControlItem( | ||
| uint8_t comm_id, uint8_t id, std::string item_name, uint16_t & addr, | ||
| uint8_t & size); | ||
| bool CheckDxlControlItem(uint8_t comm_id, uint8_t id, std::string item_name); | ||
|
Comment on lines
+84
to
+87
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For improved performance and to adhere to C++ best practices, bool GetDxlControlItem(
uint8_t comm_id, uint8_t id, const std::string & item_name, uint16_t & addr,
uint8_t & size);
bool CheckDxlControlItem(uint8_t comm_id, uint8_t id, const std::string & item_name); |
||
|
|
||
| bool GetDxlUnitValue(uint8_t id, std::string data_name, double & unit_value); | ||
| bool GetDxlSignType(uint8_t id, std::string data_name, bool & is_signed); | ||
| bool GetDxlUnitValue(uint8_t comm_id, uint8_t id, std::string data_name, double & unit_value); | ||
| bool GetDxlSignType(uint8_t comm_id, uint8_t id, std::string data_name, bool & is_signed); | ||
| bool GetDxlOffsetValue(uint8_t comm_id, uint8_t id, std::string data_name, double & offset_value); | ||
|
|
||
| // Template-based conversion methods | ||
| template<typename T> | ||
| double ConvertValueToUnit(uint8_t id, std::string data_name, T value); | ||
| double ConvertValueToUnit(uint8_t comm_id, uint8_t id, std::string data_name, T value); | ||
|
|
||
| template<typename T> | ||
| T ConvertUnitToValue(uint8_t id, std::string data_name, double unit_value); | ||
| T ConvertUnitToValue(uint8_t comm_id, uint8_t id, std::string data_name, double unit_value); | ||
|
|
||
| // Helper method for internal use | ||
| double GetUnitMultiplier(uint8_t id, std::string data_name); | ||
| double GetUnitMultiplier(uint8_t comm_id, uint8_t id, std::string data_name); | ||
|
|
||
| int32_t ConvertRadianToValue(uint8_t id, double radian); | ||
| double ConvertValueToRadian(uint8_t id, int32_t value); | ||
| int32_t ConvertRadianToValue(uint8_t comm_id, uint8_t id, double radian); | ||
| double ConvertValueToRadian(uint8_t comm_id, uint8_t id, int32_t value); | ||
|
|
||
| std::string GetModelName(uint16_t model_number) const; | ||
| }; | ||
|
|
||
| // Template implementations | ||
| template<typename T> | ||
| double DynamixelInfo::ConvertValueToUnit(uint8_t id, std::string data_name, T value) | ||
| double DynamixelInfo::ConvertValueToUnit( | ||
| uint8_t comm_id, uint8_t id, std::string data_name, | ||
| T value) | ||
| { | ||
| auto it = dxl_info_[id].unit_map.find(data_name); | ||
| if (it != dxl_info_[id].unit_map.end()) { | ||
| return static_cast<double>(value) * it->second; | ||
| auto & info = dxl_info_by_comm_[comm_id][id]; | ||
| auto it = info.unit_map.find(data_name); | ||
| if (it != info.unit_map.end()) { | ||
| double converted_value = static_cast<double>(value) * it->second; | ||
| auto offset_it = info.offset_map.find(data_name); | ||
| if (offset_it != info.offset_map.end()) { | ||
| converted_value += offset_it->second; | ||
| } | ||
| return converted_value; | ||
| } | ||
| return static_cast<double>(value); | ||
| } | ||
|
|
||
| template<typename T> | ||
| T DynamixelInfo::ConvertUnitToValue(uint8_t id, std::string data_name, double unit_value) | ||
| T DynamixelInfo::ConvertUnitToValue( | ||
| uint8_t comm_id, uint8_t id, std::string data_name, | ||
| double unit_value) | ||
| { | ||
| auto it = dxl_info_[id].unit_map.find(data_name); | ||
| if (it != dxl_info_[id].unit_map.end()) { | ||
| return static_cast<T>(unit_value / it->second); | ||
| auto & info = dxl_info_by_comm_[comm_id][id]; | ||
| auto it = info.unit_map.find(data_name); | ||
| if (it != info.unit_map.end()) { | ||
| double adjusted_value = unit_value; | ||
| auto offset_it = info.offset_map.find(data_name); | ||
| if (offset_it != info.offset_map.end()) { | ||
| adjusted_value -= offset_it->second; | ||
| } | ||
| return static_cast<T>(adjusted_value / it->second); | ||
| } | ||
| return static_cast<T>(unit_value); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The signature for
InsertWriteItemBufshould includecomm_idto properly support virtual devices, wherecomm_idcan be different fromid. The current implementation assumescomm_id == id, which is incorrect for virtual devices accessed via services.