1- // create a general class file that holds same previously used
2- // functions that we can call in different substystem cpp files
3- // such as arm, science, and drivetrain
1+ /*
2+ Utilizing this header file as an interface to house empty skeletons for
3+ all the general motor functions that will be used across different
4+ subsystems (arm, science, drivetrain)
5+ */
46
57#ifdef MOTORS_H
68#define MOTORS_H
79
8- /* *************************GENERAL LIBRARIES**************************/
9- /* ******************TO BE UTILIZED FOR ALL MOTORS*******************/
10-
11- #include < Arduino.h>
12- #include < FlexCAN_T4.h> // CAN enabling tool
13- #include " SoloCAN.hpp" // SOLO UNO motor controller's library
14- #include < QNEthernet.h> // Teensy's ethernet library
15- #include < map>
16- #include " urc.ph.h" // Protobuf header file for compiling code
17- #include " Messages.hpp" // Protobuff decode functions (encodeResponse, decodeResponse)
18-
19- #include " pb_encode.h" // Protobuf encode functions
20- #include " pb_decode.h" // Protobuf decode functions
21-
22- /* *************************DYNAMIXEL LIBRARIES**************************/
23- /* ********************TO BE UTILIZED FOR ARM.CPP*********************/
24-
25- #if defined(__linux__)
26- #include < fcntl.h>
27- #include < termios.h>
28- #define STDIN_FILENO 0
29- #elif defined(_WIN64)
30- #include < conio.h>
31- #endif
32-
33- #include < stdlib.h>
34- #include < stdio.h>
35-
36- #include " dynamixel_sdk.h" // Uses DYNAMIXEL SDK library
37- #define PROTOCOL_VERSION 2.0 // Dynamixel Protocol Version
38- #define DXL_ID 1 // Default ID for Dynamixel servos
39- #define DEVICENAME " /dev/ttyUSB0" // Linux port assigned to U2D2 (USB-to-serial converter)
40-
41- #define X_SERIES // Type of Dynamixel servos we are using
42-
43- #define ADDR_TORQUE_ENABLE 64
44- #define ADDR_GOAL_POSITION 116
45- #define ADDR_PRESENT_POSITION 132
46- #define MINIMUM_POSITION_LIMIT 0 // Refer to the Minimum Position Limit of product eManual
47- #define MAXIMUM_POSITION_LIMIT 4095 // Refer to the Maximum Position Limit of product eManual
48- #define BAUDRATE 57600
49-
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
54-
55- /* *************************GENERAL MOTOR FUNCTIONS**************************/
56- void handleLEDRequest (NewStatusLightCommand message);
57- int clampDriveRequest (int speedReference);
58- void handleDriveRequest (DrivetrainRequest message);
59-
60- /* *************************STEPPER ARM FUNCTIONS**************************/
61- void test_stepper ();
62- void test_stepper_2 ();
63- void run_stepper ();
64- void run_stepper_2 ();
65- void run_roboclaw_speed (int address, int channel, int speed);
66- void run_roboclaw_effort (int address, int channel, int effort);
10+ class Motor {
11+ public:
12+ // Essential so that children classes are cleaned up properly
13+ virtual ~Motor () = default ;
14+
15+ // Disable slicing as safety precaution
16+ Motor (const Motor&) = delete ;
17+ Motor& operator = (const Motor&) = delete ;
18+
19+ // General motor methods that each motor in every subsystem may need
20+ // UPDATE AS WE GO ALONG
21+ virtual void setSpeed (double speed) = 0;
22+ virtual void setPosition (double position) = 0;
23+ virtual void setEffort (double torque) = 0;
24+ virtual void stop () = 0;
25+ };
6726
6827#endif
0 commit comments