1414* limitations under the License.
1515*******************************************************************************/
1616
17- #if defined(__linux__) || defined(__APPLE__)
18- #include < fcntl.h>
19- #include < termios.h>
20- #define STDIN_FILENO 0
21- #elif defined(_WIN32) || defined(_WIN64)
22- #include < conio.h>
23- #endif
17+ #include " Arm.h"
2418
25- #include < stdlib.h>
26- #include < stdio.h>
27-
28- #include " dynamixel_sdk.h" // Uses DYNAMIXEL SDK library
29-
30- #define X_SERIES
31-
32- #define ADDR_TORQUE_ENABLE 64
33- #define ADDR_GOAL_POSITION 116
34- #define ADDR_PRESENT_POSITION 132
35- #define MINIMUM_POSITION_LIMIT 0 // Refer to the Minimum Position Limit of product eManual
36- #define MAXIMUM_POSITION_LIMIT 4095 // Refer to the Maximum Position Limit of product eManual
37- #define BAUDRATE 57600
38-
39- // DYNAMIXEL Protocol Version (1.0 / 2.0)
40- // https://emanual.robotis.com/docs/en/dxl/protocol2/
41- #define PROTOCOL_VERSION 2.0
42-
43- // Factory default ID of all DYNAMIXEL is 1
44- #define DXL_ID 1
19+ // Constants relevant to shoulder swivel
20+ constexpr int ROBOCLAW_SHOULDER_ADDR = 0x82 ;
21+ constexpr int ROBOCLAW_CHANNEL_1 = 1 ;
22+ constexpr int ROBOCLAW_CHANNEL_2 = 2 ;
4523
46- // Use the actual port assigned to the U2D2.
47- // ex) Windows: "COM*", Linux: "/dev/ttyUSB*", Mac: "/dev/tty.usbserial-*"
48- # define DEVICENAME " /dev/ttyUSB0 "
24+ const long SERIAL_BAUD_RATE = 38400 ;
25+ const uint8_t RUN_CURRENT_PERCENT = 100 ;
26+ const uint8_t HOLD_CURRENT_STANDSTILL = 0 ;
4927
50- #define TORQUE_ENABLE 1
51- #define TORQUE_DISABLE 0
52- #define DXL_MOVING_STATUS_THRESHOLD 20 // DYNAMIXEL moving status threshold
53- #define ESC_ASCII_VALUE 0x1b
28+ const int32_t RUN_VELOCITY = 40000 ;
29+ const int32_t STOP_VELOCITY = 0 ;
5430
31+ const long SERIAL_BAUD_RATE = 38400 ;
32+ const uint8_t RUN_CURRENT_PERCENT = 100 ;
33+ const uint8_t HOLD_CURRENT_STANDSTILL = 0 ;
5534
5635int main () {
5736 // Initialize PortHandler instance
@@ -169,55 +148,8 @@ int main() {
169148 // Close port
170149 portHandler->closePort ();
171150 return 0 ;
172- }
173-
174- // Include relevant libraries from StepperArm C++ file
175- #include < RoboClaw.h>
176- #include " urc.ph.h"
177-
178-
179- // Constants relevant to shoulder swivel
180- constexpr int ROBOCLAW_SHOULDER_ADDR = 0x82 ;
181- constexpr int ROBOCLAW_CHANNEL_1 = 1 ;
182- constexpr int ROBOCLAW_CHANNEL_2 = 2 ;
183-
184- const long SERIAL_BAUD_RATE = 38400 ;
185- const uint8_t RUN_CURRENT_PERCENT = 100 ;
186- const uint8_t HOLD_CURRENT_STANDSTILL = 0 ;
187-
188- const int32_t RUN_VELOCITY = 40000 ;
189- const int32_t STOP_VELOCITY = 0 ;
190-
191- const long SERIAL_BAUD_RATE = 38400 ;
192- const uint8_t RUN_CURRENT_PERCENT = 100 ;
193- const uint8_t HOLD_CURRENT_STANDSTILL = 0 ;
194151
195- void run_roboclaw_effort (int address, int channel, int effort) {
196-
197- int hash = address * 10 + channel;
198- if (lastCommand.count (hash) > 0 && lastCommand[hash] == effort) return ;
199- lastCommand[hash] = effort;
200-
201- uint8_t addr = address;
202- bool isReversed = (effort < 0 );
203- uint8_t requestedSpeed = abs (effort);
204-
205- if (channel == 1 ) {
206- if (isReversed) {
207- roboclaw.BackwardM1 (addr, requestedSpeed);
208- } else {
209- roboclaw.ForwardM1 (addr, requestedSpeed);
210- }
211- } else if (channel == 2 ) {
212- if (isReversed) {
213- roboclaw.BackwardM2 (addr, requestedSpeed);
214- } else {
215- roboclaw.ForwardM2 (addr, requestedSpeed);
216- }
217- }
218- }
219-
220- int main () {
152+ // START OF URC-FIRMWARE MAIN FUNCTION
221153 pinMode (LED_BUILTIN, OUTPUT);
222154 pinMode (2 , OUTPUT);
223155 pinMode (SERVO_PWM_PIN, OUTPUT);
@@ -303,4 +235,29 @@ int main() {
303235 digitalToggle (LED_BUILTIN);
304236 }
305237 }
238+ }
239+
240+ void run_roboclaw_effort (int address, int channel, int effort) {
241+
242+ int hash = address * 10 + channel;
243+ if (lastCommand.count (hash) > 0 && lastCommand[hash] == effort) return ;
244+ lastCommand[hash] = effort;
245+
246+ uint8_t addr = address;
247+ bool isReversed = (effort < 0 );
248+ uint8_t requestedSpeed = abs (effort);
249+
250+ if (channel == 1 ) {
251+ if (isReversed) {
252+ roboclaw.BackwardM1 (addr, requestedSpeed);
253+ } else {
254+ roboclaw.ForwardM1 (addr, requestedSpeed);
255+ }
256+ } else if (channel == 2 ) {
257+ if (isReversed) {
258+ roboclaw.BackwardM2 (addr, requestedSpeed);
259+ } else {
260+ roboclaw.ForwardM2 (addr, requestedSpeed);
261+ }
262+ }
306263}
0 commit comments