-
Notifications
You must be signed in to change notification settings - Fork 64
Add API for getting moving status #147
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
Changes from 3 commits
b83c947
27faec4
2f3c03d
c055572
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -915,6 +915,33 @@ bool Dynamixel2Arduino::getTorqueEnableStat(uint8_t id) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ret; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint8_t Dynamixel2Arduino::getMovingStatus(uint8_t id) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint16_t model_num = getModelNumberFromTable(id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint8_t ret = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(model_num == UNREGISTERED_MODEL){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(setModelNumber(id, getModelNumber(id)) == true){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model_num = getModelNumberFromTable(id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(model_num == AX12A || model_num == AX12W || model_num == AX18A || model_num == DX113 || model_num == DX116 || model_num == DX117 || model_num == RX10 || model_num == RX24F || model_num == RX28 || model_num == RX64 || model_num == EX106 || model_num == MX12W || model_num == MX28 || model_num == MX64 || model_num == MX106 || model_num == XL320) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setLastLibErrCode(DXL_LIB_ERROR_NOT_SUPPORTED); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else if(model_num == YM070_210_M001_RH || model_num == YM070_210_B001_RH || model_num == YM070_210_R051_RH || model_num == YM070_210_R099_RH || model_num == YM070_210_A051_RH || model_num == YM070_210_A099_RH || model_num == YM080_230_M001_RH || model_num == YM080_230_B001_RH || model_num == YM080_230_R051_RH || model_num == YM080_230_R099_RH || model_num == YM080_230_A051_RH || model_num == YM080_230_A099_RH) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setLastLibErrCode(DXL_LIB_ERROR_NOT_SUPPORTED); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+929
to
+935
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. This block checks for a long list of specific model numbers to determine if the Could this be simplified by using a
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ret = (uint8_t)readControlTableItem(ControlTableItem::MOVING_STATUS, id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ret; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int32_t Dynamixel2Arduino::readControlTableItem(uint8_t item_idx, uint8_t id, uint32_t timeout) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int32_t ret = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -48,6 +48,14 @@ enum D2ALibErrorCode | |||||||||||||||||||||||||||||||||||||||||||||||||||
| D2A_LIB_ERROR_UNKNOWN_MODEL_NUMBER | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| enum MovingStatus | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| IN_POSITION = 0x01, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| PROFILE_ONGOING = 0x02, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| FOLLOWING_ERROR = 0x08, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| VELOCITY_PROFILE = 0x30 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| class Dynamixel2Arduino : public DYNAMIXEL::Master | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| public: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -387,6 +395,40 @@ class Dynamixel2Arduino : public DYNAMIXEL::Master | |||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool getTorqueEnableStat(uint8_t id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @brief It is API for getting the moving status of DYNAMIXEL. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @code | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * const int DXL_DIR_PIN = 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Dynamixel2Arduino dxl(Serial1, DXL_DIR_PIN); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * status = dxl.getMovingStatus(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * if (status & IN_POSITION == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Serial.print("Arrived"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * if (status & PROFILE_ONGOING == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Serial.print("Profile is in progress"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * if (status & FOLLOWING_ERROR == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Serial.print("Not following desired position trajectory"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * if (status & VELOCITY_PROFILE == 0xC0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Serial.print("Using trapezoidal profile"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * else if (status & VELOCITY_PROFILE == 0x80) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Serial.print("Using triangular profile"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * else if (status & VELOCITY_PROFILE == 0x40) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Serial.print("Using rectangular profile"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Serial.print("Not using any profile (step)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+403
to
+424
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 example code in the documentation uses
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @endcode | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param id DYNAMIXEL Actuator's ID. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return It returns the data read from DXL control table item. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * If the read fails, 0 is returned. Whether or not this is an actual value can be confirmed with @getLastLibErrCode(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint8_t getMovingStatus(uint8_t id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @brief It is API for getting data of a DYNAMIXEL control table item. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @code | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
This block attempts to set the model number if it's unregistered. However, if
setModelNumberfails,model_numwill remainUNREGISTERED_MODEL, and the subsequent checks will be performed with an invalid model number. It would be better to check the return value ofsetModelNumberand skip the unsupported model check if it fails. Also, thesetModelNumberfunction already sets the last lib error code if it fails, so there is no need to set it again in theelseblock.