mercredi 3 mai 2017

Motion Conversion Templates / Unit Conversion Templates for Stepper Motor motion calculations

I have an applicaton written in C++ (with support for C++11 standards). This application interacts with a stepper motor, in order to move an object. I'd like to create some template classes and function, for 'fluent'-style motion calculation APIs.

To begin, lets assume all stepper motors have a common set of conversion factors, which differ from motor to motor:

  • "Microsteps" per "Step"
  • "Steps" per "Revolution"
  • "Millimeters traveled," per "Revolution"

Using these parameters, I should be able to establish a "Stepper Motor Profile," where each model of the motor has the above parameters defined. For instance:

typedef ModelXStepperMotor = StepperMotorProfile<
    50.0, // Millimeters per revolution
    100, // Steps per revolution
    15> // Microsteps per Step

Once a profile for a stepper motor has been established, I should be able to create a "Conversion" class. This class provides APIs allowing a user to easily calculate (or 'convert') one unit of measurement to another, based on the current motor profile. For example:

MotorConversion<ModelXStepperMotor> convert;
auto microsteps = convert.FromMillimeters(200.0).ToMicrosteps();
auto millimeters = convert.FromSteps(12).ToMillimeters();

Understanding this involves a combination of templates and fluent-syntax objects, I'm having trouble making the connection between StepperMotorProfile and the containing MotorConversion class.

Would someone be so kind as to help me wrap my head around what such a StepperMotorProfile template class might look like?

  • Do the template arguments need to be exposed as static consts?
  • Would a 'wrapper' template class (such as the MotorConversion class) have access to the child's template arguments, or do they require the const members to access?
  • Would compile-time calculations be possible using this API? What would need to change, if not?

Aucun commentaire:

Enregistrer un commentaire