29 #if defined(__linux__) || defined(__APPLE__)
33 #define STDIN_FILENO 0
34 #elif defined(_WIN32) || defined(_WIN64)
44 #define ADDR_OPERATING_MODE 0x06
45 #define ADDR_TORQUE_ENABLE 0x30
46 #define ADDR_GOAL_POSITION 0x4e
47 #define ADDR_PRESENT_POSITION 0x5a
50 #define PROTOCOL_VERSION 2.0
54 #define BAUDRATE 1000000
55 #define DEVICENAME "/dev/ttyACM1"
58 #define TORQUE_ENABLE 1
59 #define TORQUE_DISABLE 0
60 #define MAX_POSITION_VALUE -1
61 #define DXL_MOVING_STATUS_THRESHOLD 20
62 #define EXT_POSITION_CONTROL_MODE 3
64 #define ESC_ASCII_VALUE 0x1b
65 #define SPACE_ASCII_VALUE 0x20
69 #if defined(__linux__) || defined(__APPLE__)
70 struct termios oldt, newt;
72 tcgetattr(STDIN_FILENO, &oldt);
74 newt.c_lflag &= ~(ICANON | ECHO);
75 tcsetattr(STDIN_FILENO, TCSANOW, &newt);
77 tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
79 #elif defined(_WIN32) || defined(_WIN64)
86 #if defined(__linux__) || defined(__APPLE__)
87 struct termios oldt, newt;
91 tcgetattr(STDIN_FILENO, &oldt);
93 newt.c_lflag &= ~(ICANON | ECHO);
94 tcsetattr(STDIN_FILENO, TCSANOW, &newt);
95 oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
96 fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
100 tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
101 fcntl(STDIN_FILENO, F_SETFL, oldf);
110 #elif defined(_WIN32) || defined(_WIN64)
117 #if defined(__linux__) || defined(__APPLE__)
118 usleep(waitTime * 1000);
119 #elif defined(_WIN32) || defined(_WIN64)
138 uint8_t mcy_error = 0;
139 int32_t mcy_present_position = 0;
144 printf(
"Succeeded to open the port!\n");
148 printf(
"Failed to open the port!\n");
149 printf(
"Press any key to terminate...\n");
157 printf(
"Succeeded to change the baudrate!\n");
161 printf(
"Failed to change the baudrate!\n");
162 printf(
"Press any key to terminate...\n");
167 uint8_t operating_mode = 0;
171 printf(
"%s\n", packetHandler->
getTxRxResult(mcy_comm_result));
173 else if (mcy_error != 0)
184 printf(
"%s\n", packetHandler->
getTxRxResult(mcy_comm_result));
186 else if (mcy_error != 0)
192 printf(
"Control_enable has been disabled \n");
200 printf(
"%s\n", packetHandler->
getTxRxResult(mcy_comm_result));
202 else if (mcy_error != 0)
210 printf(
"Operating mode changed to extended position control mode. \n");
219 printf(
"%s\n", packetHandler->
getTxRxResult(mcy_comm_result));
221 else if (mcy_error != 0)
227 printf(
"Mercury has been successfully connected \n");
232 printf(
" Press SPACE key to clear multi-turn information! (or press ESC to quit!)\n");
238 printf(
"%s\n", packetHandler->
getTxRxResult(mcy_comm_result));
240 else if (mcy_error != 0)
251 printf(
"%s\n", packetHandler->
getTxRxResult(mcy_comm_result));
253 else if (mcy_error != 0)
269 printf(
"\n Clearing Multi-Turn Information... \n");
277 printf(
"%s\n", packetHandler->
getTxRxResult(mcy_comm_result));
279 else if (mcy_error != 0)
284 printf(
"[ID:%03d] GoalPos:%03d New PresPos:%03d \n",
MCY_ID,
MAX_POSITION_VALUE, (mcy_present_position - 8192) % 16384);
290 printf(
"%s\n", packetHandler->
getTxRxResult(mcy_comm_result));
292 else if (mcy_error != 0)
308 printf(
"%s\n", packetHandler->
getTxRxResult(mcy_comm_result));
310 else if (mcy_error != 0)
323 printf(
"%s\n", packetHandler->
getTxRxResult(mcy_comm_result));
325 else if (mcy_error != 0)
The class that inherits Protocol1PacketHandler class or Protocol2PacketHandler class.
virtual const char * getTxRxResult(int result)=0
The function that gets description of communication result.
virtual int write1ByteTxRx(PortHandler *port, uint8_t id, uint16_t address, uint8_t data, uint8_t *error=0)=0
The function that calls PacketHandler::writeTxRx() for writing 1 byte data and receives the packet @d...
virtual const char * getRxPacketError(uint8_t error)=0
The function that gets description of hardware error.
virtual int read4ByteTxRx(PortHandler *port, uint8_t id, uint16_t address, uint32_t *data, uint8_t *error=0)=0
The function that calls PacketHandler::readTxRx() function for reading 4 byte data @description The f...
virtual int clearMultiTurn(PortHandler *port, uint8_t id, uint8_t *error=0)=0
The function that resets the multi-turn revolution count @description The function makes an instructi...
virtual int readTxRx(PortHandler *port, uint8_t id, uint16_t address, uint16_t length, uint8_t *data, uint8_t *error=0)=0
The function that transmits INST_READ instruction packet, and read data from received packet @descrip...
virtual int write4ByteTxRx(PortHandler *port, uint8_t id, uint16_t address, uint32_t data, uint8_t *error=0)=0
The function that calls PacketHandler::writeTxRx() for writing 4 byte data and receives the packet @d...
static PacketHandler * getPacketHandler()
The function that returns PacketHandler instance.
The class for port control that inherits PortHandlerLinux, PortHandlerWindows, PortHandlerMac,...
static PortHandler * getPortHandler(const char *port_name)
The function that gets PortHandler class inheritance @description The function gets class inheritance...
virtual bool openPort()=0
The function that opens the port @description The function calls PortHandlerLinux::setBaudRate() to o...
virtual bool setBaudRate(const int baudrate)=0
The function that sets baudrate into the port handler @description The function sets baudrate into th...
virtual void closePort()=0
The function that closes the port @description The function closes the port.
#define EXT_POSITION_CONTROL_MODE
#define ADDR_PRESENT_POSITION
void msecSleep(int waitTime)
#define ADDR_OPERATING_MODE
#define DXL_MOVING_STATUS_THRESHOLD
#define ADDR_GOAL_POSITION
#define SPACE_ASCII_VALUE
#define ADDR_TORQUE_ENABLE
#define MAX_POSITION_VALUE