ambrop72 / aprinter

3D printer firmware written in C++
Other
143 stars 42 forks source link

Feature request for duplication of the steps control sequence to another pins #8

Closed a0s closed 10 years ago

a0s commented 10 years ago

I have RAMPS-FD board with six channels - six stepper driver that i can control. This channels is X, Y, Z, E0-MOT, E1-MOT, E2-MOT. X, Y, Z to control for movement, and E0-MOT to control the extruder. Therefore i have two empty channels. I have Prusa i3 printer with two motors for Z-axis. My problem is that i need control two motors by one stepper driver (Polulu DRV8825). I don't want to connect motors sequentially or parallel, i think its bad idea in general. I want using E2-MOT channel for second stepper driver of Z axis. First and second of Z-axis's stepper drivers should working synchronously for prevent printer damage. I guess that the configuration might look like this https://github.com/orangeudav/aprinter/commit/6367faf05ecb25410c758b68a05ab851a94f2c2c (aprinter-rampsfd.cpp) And control code should looks like

template <typename ThisContext>
static void stepOn (ThisContext c)
{
    auto *s = Steppers::Object::self(c);
    s->debugAccess(c);
    Context::Pins::template set<typename ThisDef::StepPin>(c, true);            

    // If this axis have one, two etc PrinterMainSlaveAxisParams - call stepOn for all of them
}

template <typename ThisContext>
static void stepOff (ThisContext c)
{
    auto *s = Steppers::Object::self(c);
    s->debugAccess(c);
    Context::Pins::template set<typename ThisDef::StepPin>(c, false);

    // If this axis have one, two etc PrinterMainSlaveAxisParams - call stepOff for all of them
}

I do not know enough C++11 and templates to implement this :(

ambrop72 commented 10 years ago

Thanks for the request, that'll be easy to implement.

ambrop72 commented 10 years ago

In your slave axes proposal, why do you have a Name in PrinterMainSlaveAxisParams? For the axis itself that identifies the axis in G0/G1 etc., but in your case I don't see how it is useful.

a0s commented 10 years ago

Yes, name not need. I I'm not going to re-use these pins anywhere.

ambrop72 commented 10 years ago

Should be all set. Here's how you use it:

PrinterMainAxisParams<
    ...
    PrinterMainNoMicroStepParams, // Don't forget the comma.
    MakeTypeList<
        PrinterMainSlaveStepperParams<
            DuePinA9, // DirPin
            DuePinA10, // StepPin
            DuePinA11, // EnablePin
            false // InvertDir
        >
    >
>

So, add this list of slave steppers to the axis. There's no need to change definitions of other axes since SlaveSteppersList defaults to EmptyTypeList.

a0s commented 10 years ago

Thank you for commit, it work great!

a0s commented 10 years ago

Hmm, for now (995d4b876ef11e6a2ed5ae987d110c980eed0d8a) i don't see PrinterMainSlaveStepperParams example and for my config

           ...
           AxisDriverService<
                At91Sam3xClockInterruptTimerService<At91Sam3xClockTC3, At91Sam3xClockCompA>, // StepperTimer
                TheAxisDriverPrecisionParams // PrecisionParams
            >,
            PrinterMainNoMicroStepParams,
            MakeTypeList<
                PrinterMainSlaveStepperParams<
                    DuePin47, // DirPin
                    DuePin32, // StepPin
                    DuePin45, // EnablePin
                    false // InvertDir
                >
            >
        >,
        PrinterMainAxisParams<
            'E', // Name
            DuePin28, // DirPin
            DuePin36, // StepPin
            ...

i got

./main/aprinter-rampsfd.cpp:422:17: error: type/value mismatch at argument 4 in template parameter list for 'template<class TDirPin, class TStepPin, class TEnablePin, class TInvertDir> struct APrinter::PrinterMainSlaveStepperParams'
                 >
                 ^
compilation terminated due to -Wfatal-errors.
ambrop72 commented 10 years ago

You need to make some changes in your main file due to the introduction of the runtime configuration system. You probably noticed that but I forgot to update the wiki for the slave steppers thing.

The problem is the InvertDir parameter. You need to pass a boolean configuration option (declared with APRINTER_CONFIG_OPTION_BOOL), not a boolean value. See XInvertDir for example. You should name the option with a unique name (e.g. XSlave1InvertDir).