I have an application in which I will be controlling the position of several DC motors as if they were servos. Ultimately, this will end up in a library. I want to create a nice structure to the motors to treat all properties the same and to make it universal.
Here is what I have:
7 motors that will use an external ADC
1 motor will use an internal ADC
2 motors will use an optical interrupter and limit switches
Common properties I can see among them:
LUPin (forward pin)
RDPin (reverse pin)
Chan (the channel of the motor, but this would really be known by the struct array, right?)
Dir (value for direction: Stopped = 0, forward = 1, Reverse = 2)
Currpos (current position of the feedback)
pos (last commanded position)
Min (minimum position value)
Max (Maximum position value)
Not common:
External ADC channel
Internal ADC channel
Encoder (pin used for the optical interrupter)
LU_LIM (pin - limit switch for one extreme)
RD_LIM (pin - limit switch for the other extreme)
To make it truly universal, there should also be properties such as:
Speed (PWM value)
EncoderA (for quadrature encoders)
EnablePin (if used, some controllers do)
Ultimately, I would like to provide a library that allows for different types of motors and feedback to be controlled as servos. I probably don't need to flag what type of feedback, and instead just rely on the main code to handle that and just update currpos in the structure. Given that, it probably makes sense to store the feedback related stuff (pins, channels, etc..) in a separate array managed by the end user.
So, I guess I am looking more for logical help than I am in actually creating the structure (I know how to do that part) and whether a structure is the right thing to use for this.
I'm sure I missed something important, but I will leave it here and hope for some questions, suggestions, or feedback.