...
POST No. 2407858
dynamixel speed
2020-05-13 11:12:59 manamin1373
hello thanks for your guidance this is mu code.can you fix it to change dynamixel speed (through Moving speed). #include #include "std_msgs/String.h" #include "dynamixel_sdk_ros1_read_write/GetPosition.h" #include "dynamixel_sdk_ros1_read_write/SetPosition.h" #include "dynamixel_sdk/dynamixel_sdk.h" using namespace dynamixel; // Control table address #define ADDR_MX_TORQUE_ENABLE 24 // Control table address is different in Dynamixel model #define ADDR_MX_GOAL_POSITION 30 #define ADDR_MX_PRESENT_POSITION 36 // Protocol version #define PROTOCOL_VERSION 1.0 // See which protocol version is used in the Dynamixel // Default setting #define DXL_ID 1 // Dynamixel ID: 1 #define BAUDRATE 57600 #define DEVICENAME "/dev/ttyUSB0" // Check which port is being used on your controller // ex) Windows: "COM1" Linux: "/dev/ttyUSB0" Mac: "/dev/tty.usbserial-*" #define TORQUE_ENABLE 1 // Value for enabling the torque #define TORQUE_DISABLE 0 // Value for disabling the torque #define DXL_MINIMUM_POSITION_VALUE 00 // Dynamixel will rotate between this value #define DXL_MAXIMUM_POSITION_VALUE 4090 // and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.) #define DXL_MOVING_STATUS_THRESHOLD 10 // Dynamixel moving status threshold #define ESC_ASCII_VALUE 0x1b int main(int argc, char **argv) { ros::init(argc, argv, "dynamixel_sdk_simple_example_node"); ros::NodeHandle nh; dynamixel::PortHandler *portHandler = dynamixel::PortHandler::getPortHandler(DEVICENAME); dynamixel::PacketHandler *packetHandler = dynamixel::PacketHandler::getPacketHandler(PROTOCOL_VERSION); int index = 0; int dxl_comm_result = COMM_TX_FAIL; // Communication result int dxl_goal_position[2] = {DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE}; // Goal position uint8_t dxl_error = 0; // Dynamixel error uint16_t dxl_present_position = 0; // Present position // Open port if (portHandler->openPort()) { printf("Succeeded to open the port!n"); } else { printf("Failed to open the port!n"); printf("Press any key to terminate...n"); //getch(); return 0; } // Set port baudrate if (portHandler->setBaudRate(BAUDRATE)) { printf("Succeeded to change the baudrate!n"); } else { printf("Failed to change the baudrate!n"); printf("Press any key to terminate...n"); //getch(); return 0; } // Enable Dynamixel Torque dxl_comm_result = packetHandler->write1ByteTxRx(portHandler, DXL_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE, &dxl_error); if (dxl_comm_result != COMM_SUCCESS) { printf("%sn", packetHandler->getTxRxResult(dxl_comm_result)); } else if (dxl_error != 0) { printf("%sn", packetHandler->getRxPacketError(dxl_error)); } else { printf("Dynamixel has been successfully connected n"); } while (ros::ok()) { /* printf("Press any key to continue! (or press ESC to quit!)n"); if (getch() == ESC_ASCII_VALUE) break; */ // Write goal position dxl_comm_result = packetHandler->write2ByteTxRx(portHandler, DXL_ID, ADDR_MX_GOAL_POSITION, dxl_goal_position[index], &dxl_error); if (dxl_comm_result != COMM_SUCCESS) { printf("%sn", packetHandler->getTxRxResult(dxl_comm_result)); } else if (dxl_error != 0) { printf("%sn", packetHandler->getRxPacketError(dxl_error)); } do { // Read present position dxl_comm_result = packetHandler->read2ByteTxRx(portHandler, DXL_ID, ADDR_MX_PRESENT_POSITION, &dxl_present_position, &dxl_error); if (dxl_comm_result != COMM_SUCCESS) { printf("%sn", packetHandler->getTxRxResult(dxl_comm_result)); } else if (dxl_error != 0) { printf("%sn", packetHandler->getRxPacketError(dxl_error)); } printf("[ID:%03d] GoalPos:%03d PresPos:%03dn", DXL_ID, dxl_goal_position[index], dxl_present_position); }while((abs(dxl_goal_position[index] - dxl_present_position) > DXL_MOVING_STATUS_THRESHOLD)); // Change goal position if (index == 0) { index = 1; } else { index = 0; } //ros::spin(); } // Disable Dynamixel Torque dxl_comm_result = packetHandler->write1ByteTxRx(portHandler, DXL_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE, &dxl_error); if (dxl_comm_result != COMM_SUCCESS) { printf("%sn", packetHandler->getTxRxResult(dxl_comm_result)); } else if (dxl_error != 0) { printf("%sn", packetHandler->getRxPacketError(dxl_error)); } // Close port portHandler->closePort(); return 0; }
2020-05-13 11:12:59
manamin1373
2020-05-13 11:58:11 Will Son

Hi,


I had quite some fun time in decrypting your secret code xD

If you set DYNAMIXEL to Joint Mode and trying to reduce the speed while in motion, you can set the Moving Speed address(32) something as below.

You should define the ADDR_MX_MOVING_SPEED to 32 just like other address definitions, and writing 0 will use the maximum speed while 100 will use about 10% of the max speed.


// Change goal position
if (index == 0)
{
index = 1;
dxl_comm_result = packetHandler->write2ByteTxRx(portHandler, DXL_ID, ADDR_MX_MOVING_SPEED, 0, &dxl_error);
}
else
{
index = 0;
dxl_comm_result = packetHandler->write2ByteTxRx(portHandler, DXL_ID, ADDR_MX_MOVING_SPEED, 100, &dxl_error);
}


Thank you.

2020-05-13 11:58:11
willson
Reply
웹에디터 시작 웹 에디터 끝