Forum Rule: Always post complete source code & details to reproduce any issue!
Page 6 of 6 FirstFirst ... 4 5 6
Results 126 to 140 of 140

Thread: New Stepper Motor Library

  1. #126
    Junior Member
    Join Date
    Nov 2020
    Posts
    10
    I am moving up to a 4.1 from a 3.6 with an existing program that uses the RotateControl in TeensyStep library (which works mavelously using the 3.6, BTW.)
    Of course, the compiler chokes on RotateControl as the structure of the TeensyStep4 library is quite different than the old TeensyStep.

    The existing program uses these lines:

    #define Y_STEP_PIN 23 // Spool on Y-axis stepper
    #define Y_DIR_PIN 18 // Spool direction
    float SpoolPPR = (360.0 / 1.8) * 16.0; // (360° / angle per steps°) * microsteps
    float SpoolPPS = SpoolPPR / 60.0; // 1.0 RPM base speed for Spool

    Stepper motor_1(Y_STEP_PIN,Y_DIR_PIN );
    RotateControl Spool;
    motor_1
    .setMaxSpeed(SpoolPPS) // steps/s
    .setAcceleration(20000); // steps/s^2
    Spool.rotateAsync(motor_1);
    Spool.overrideSpeed(SpoolRPM); // Sets the spool speed as the program is running and is called as the spool RPM needs to change

    This asynchronously runs the the stepper quite nicely with a 3.6 under the old TeensyStep library. :-)

    A simple example snippet, translated into the the new format would be enormously helpful. Enormously.

    Bill D.

  2. #127
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    2,061
    overrideSpeed is not yet implemented in TeensyStep4. I'll see if I can do a test version. Give me a day or two.

  3. #128
    Junior Member
    Join Date
    Nov 2020
    Posts
    10
    Thank you so much!

  4. #129
    Junior Member
    Join Date
    Nov 2020
    Posts
    10
    Hi Luni,

    Is there some clever way to get TeensyStep4 (as written) to asynchronously run motors and alter the speed on the fly?

    Can I update the value in setMaxSpeed() in TeensyStep4 while the motor is operating?

    Bill D.

  5. #130
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    2,061
    Quote Originally Posted by killacycle View Post
    Hi Luni,
    Is there some clever way to get TeensyStep4 (as written) to asynchronously run motors and alter the speed on the fly?
    Can I update the value in setMaxSpeed() in TeensyStep4 while the motor is operating?
    Bill D.
    @killacycle: Pushed a quick implementation of overrideSpeed. Can you give it a try?

  6. #131
    Junior Member
    Join Date
    Nov 2020
    Posts
    10
    Quote Originally Posted by luni View Post
    @killacycle: Pushed a quick implementation of overrideSpeed. Can you give it a try?
    Thank you so much. :-)

    I will give it a try first thing tomorrow and will let you know how it works. Again, thanks in advance!

    Best, Bill D.

  7. #132
    Junior Member
    Join Date
    Nov 2020
    Posts
    10

    TeensyStep4 library

    Quote Originally Posted by luni View Post
    @killacycle: Pushed a quick implementation of overrideSpeed. Can you give it a try?
    Hmm... Won't compile. :-(

    I think I might be missing some portion of the library perhaps? Is there an additional library that needs to be included in my code?

    If you were to post very simple example code that uses TeensyStep4 and its new subroutine(s) might be helpful.

    Compiler says:
    >>>>>>>>>>>>>>>>>>>>>>>>

    In file included from C:\Users\NEW\Documents\Arduino\libraries\TeensySte p4-main\src\teensystep4.cpp:7:0:
    C:\Users\NEW\Documents\Arduino\libraries\TeensySte p4-main\src\timers/Teensy4/TMR/TMR.h:176:51: error: 'IMXRT_TMR1_ADDRESS' was not declared in this scope
    static constexpr uintptr_t tmrAddresses[]{IMXRT_TMR1_ADDRESS, IMXRT_TMR2_ADDRESS, IMXRT_TMR3_ADDRESS, IMXRT_TMR4_ADDRESS};
    ^
    C:\Users\NEW\Documents\Arduino\libraries\TeensySte p4-main\src\timers/Teensy4/TMR/TMR.h:176:71: error: 'IMXRT_TMR2_ADDRESS' was not declared in this scope
    static constexpr uintptr_t tmrAddresses[]{IMXRT_TMR1_ADDRESS, IMXRT_TMR2_ADDRESS, IMXRT_TMR3_ADDRESS, IMXRT_TMR4_ADDRESS};
    ^
    C:\Users\NEW\Documents\Arduino\libraries\TeensySte p4-main\src\timers/Teensy4/TMR/TMR.h:176:91: error: 'IMXRT_TMR3_ADDRESS' was not declared in this scope
    static constexpr uintptr_t tmrAddresses[]{IMXRT_TMR1_ADDRESS, IMXRT_TMR2_ADDRESS, IMXRT_TMR3_ADDRESS, IMXRT_TMR4_ADDRESS};
    ^
    C:\Users\NEW\Documents\Arduino\libraries\TeensySte p4-main\src\timers/Teensy4/TMR/TMR.h:176:111: error: 'IMXRT_TMR4_ADDRESS' was not declared in this scope
    static constexpr uintptr_t tmrAddresses[]{IMXRT_TMR1_ADDRESS, IMXRT_TMR2_ADDRESS, IMXRT_TMR3_ADDRESS, IMXRT_TMR4_ADDRESS};
    >>>>>>>

  8. #133
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    2,061
    C:\Users\NEW\Documents\Arduino\libraries\TeensySte p4-main\src\teensystep4.cpp
    Looks like something went wrong installing the library? There is a space in your installation path: "..\libraries\TeensySte p4-main\src...".

  9. #134
    Junior Member
    Join Date
    Nov 2020
    Posts
    10
    I managed to get the code to compile by moving the individual library components into tabs directly associated with my main program code so they would become local code.

    I then renamed the include calls in my local copy to refer to the files in the program tabs. (Basically, I carefully removed the subfile structure from the library, in my local copy.)

    Tomorrow, I will connect the hardware and see how it runs! :-)

    Many thanks for writing this very powerful stepper driver library for the Teensy platform!

    Bill D.

    I am located in New Zealand, so I am shifted by about half of a day from the rest of the world. :-)

  10. #135
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    2,061
    I managed to get the code to compile by moving the individual library components into tabs directly associated with my main program code so they would become local code.
    Good that it works now. However, while manually copying files to your source folder certainly works it should not be necessary. It should be enough to download the *.zip from Github and do a "zip install" using the library manager. As you know, TeensyStep4 is in a very experimental stage. Thus, a lot of changes can be expected. Manually copying files and adjusting the include paths can get quite tedius quickly.

  11. #136
    Junior Member
    Join Date
    Nov 2020
    Posts
    10
    Luni wrote: "However, while manually copying files to your source folder certainly works it should not be necessary. It should be enough to download the *.zip from Github and do a "zip install" using the library manager."

    The TeensyStep4 library is not visible to the library manager (under "tools"), which is understandable for such a new library. I am not sure that "zip install" is an option under the library manager.
    Zip install _is_ an option under "sketch" then "add library" however. Adding a zip library by that method somehow does not work correctly when the zip directory has libraries in sub-directories, it seems. :-( Not sure why, but I suspect it doesn't see the sub-folder branches in the library. That is exactly what I tried initially.

    Since the compiler wasn't managing to find the libraries in the sub-folders when I did a normal zip install, I figured I would pull the library files into tabs in the code using "sketch" "add file" and then edit the paths in the local files to remove the sub-folder structure.

  12. #137
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    1,244
    Quote Originally Posted by killacycle View Post
    Luni wrote: "However, while manually copying files to your source folder certainly works it should not be necessary. It should be enough to download the *.zip from Github and do a "zip install" using the library manager."

    The TeensyStep4 library is not visible to the library manager (under "tools"), which is understandable for such a new library. I am not sure that "zip install" is an option under the library manager.
    Zip install _is_ an option under "sketch" then "add library" however. Adding a zip library by that method somehow does not work correctly when the zip directory has libraries in sub-directories, it seems. :-( Not sure why, but I suspect it doesn't see the sub-folder branches in the library. That is exactly what I tried initially.

    Since the compiler wasn't managing to find the libraries in the sub-folders when I did a normal zip install, I figured I would pull the library files into tabs in the code using "sketch" "add file" and then edit the paths in the local files to remove the sub-folder structure.
    I just tried it using Sketch.Include Library.Add .ZIP Library... and it worked just fine, creating all the sub libraries as they exist in the GitHub source.
    When you post in the future, instead of writing
    Luni wrote: "However, while manually copying files to your source folder certainly works it should not be necessary. It should be enough to download the *.zip from Github and do a "zip install" using the library manager."
    could you include it between quote tags as I have done above.

  13. #138
    Junior Member
    Join Date
    Oct 2022
    Posts
    1
    Hi,
    I'm using TeensyStep for the first time in a project. Everything is going well so far. I just have a first basic question that I can't solve on my own:
    To drive the motor, I use controller.stop();(motor), because the function blocks and I can automatically transfer new parameters only at the reversal points.
    Now I've created an interrupt routine to be able to stop the motor at any time (via an interrupt pin).
    With controller.stop(); unfortunately it doesn't work. Also controller.stopAsync(); doesn't really work.

    How can I stop a by controller.move() activated motion (e.g. with interrupt) without loosing steps???

    Thanks in advance

    As required here, I post my code for it:

    Code:
    #include "Arduino.h"
    #include "TeensyStep.h"
    
    Stepper motor(22,23);
    StepControl controller; 
    
    const byte interruptPin1 = 33;
    
    int32_t targetposition = 0; // Vordere, errechnete Zielpositon
    int32_t backposition = 0; // Hintere, errechnete Zieposition
    int32_t initialtarget = 0; // Initialisierte (während Setup festgelegte) max. Zielposition
    int32_t initialback = 0; // Initialisierte (während Setup festgelegte) max. Backposition
    // int reps = 0; //Anzahl Wiederholungen FOR
    String buttons_read = ""; // Zwischenspreeicher Auslesen Button
    int32_t ownmmaxspeed = 0; // Eigener Wert für MaxSpeed aus dem der aktuelle Speed errechnet wird
    int32_t ownminspeed = 0; // Eigener Wert für minimale Laufgeschwindigkeit ca. 1/2 Hub/Sec
    int32_t safetyspeed = 0; // Für Rückzug nach STOP
    int32_t motorspeed_prozent = 50; // Geschwindigkeit 0-100 in 10-er Schritten zum Berechnen der Frequnz f. Motor
    int32_t progressSpeed = 0; // Wert zur Übertragzng an SpeedGauge
    int32_t actualspeed = 0;
    int32_t accelfactor = 0; //Multiplikator für Bems-/Beschleunigungsrampen
    int32_t stepwide = 0; // 5-10-20... % Schritte für Geschwindigkeit +/-
    int32_t risedeep = 0; // Wert um die Tiefe pro Hub zu erhöhen
    
    int32_t sondercounter = 0; // Anzahl Schleifen Sonderfunktion
    int32_t sonderprogramm = 0; // Sonderfunktion ein/aus
    int32_t sonderteiler = 0; // Zur Berechnung aus sondercounter abgeleiteter Wert zur Berechnung der Tiefenschritte
    
    void isrStop()
    {
      Serial.println("Interrupt");
      Serial.println(motor.getPosition());
    
      controller.stop();
      
      Serial2.print("progressSpeed.val=");
      Serial2.print(0);
      Serial2.write(0xFF);
      Serial2.write(0xFF);
      Serial2.write(0xFF);
      delay(5);
    
      actualspeed = 0;
      
      // Rouine zur Rückfahrt auf den Homepoint oder neue Referenzfahrt folgt hier
    
    }
    
    void setup() 
    { 
        pinMode(interruptPin1, INPUT);
        attachInterrupt(digitalPinToInterrupt(interruptPin1), isrStop, FALLING);
        
        // Setup some motor properties
        ownmmaxspeed = 15300; 
        ownminspeed = 2550; 
        motorspeed_prozent = 30; // Startwert nach Initialisierung
        initialtarget = 4000;
        initialback = 0;
        targetposition = initialtarget;
        backposition = initialback;
        accelfactor = 3;
        stepwide = 10;
        risedeep = (targetposition-backposition);
        safetyspeed = 1500;
    
        sonderprogramm = 1; // Sonderfunktion ein/aus
        sondercounter = 5; // Anzahl Schleifen Sonderfunktion
        sonderteiler = sondercounter; // Initial aus Anzahl Schleifen abgeleiteter Wert zur Berechnung der Tiefenschritte
    
        actualspeed = map(motorspeed_prozent, stepwide, 100, ownminspeed, ownmmaxspeed);
        motor.setMaxSpeed(actualspeed);
        motor.setAcceleration(actualspeed*accelfactor);    // stp/s^2
        motor.setPosition(0);
        motor.setTargetAbs(targetposition);
        progressSpeed = motorspeed_prozent * 1.8;
    
        Serial.begin(9800);
        Serial2.begin(115200);
        delay(20);
        
        Serial2.print("progressSpeed.val=");
        Serial2.print(progressSpeed);
        Serial2.write(0xFF);
        Serial2.write(0xFF);
        Serial2.write(0xFF);
        delay(5);
    
    }
    
    void serialRunWatch()
    {
        buttons_read += char (Serial2.read());
        if ((buttons_read == "D") && (motorspeed_prozent > 0))
        {
           motorspeed_prozent = motorspeed_prozent - stepwide;
           progressSpeed = motorspeed_prozent * 1.8;
           Serial2.clear();
        }
    
        if ((buttons_read == "U") && (motorspeed_prozent < 100))
        {
          motorspeed_prozent = motorspeed_prozent + stepwide;
          progressSpeed = motorspeed_prozent * 1.8;
          Serial2.clear();
        }
    
        if ((buttons_read == "8") && (motorspeed_prozent <= 100))
        {
          motorspeed_prozent = 80;
          progressSpeed = motorspeed_prozent * 1.8;
          Serial2.clear();
        }
    
        if ((buttons_read == "S") && (motorspeed_prozent != 0))
        {
          motorspeed_prozent = 0;
          progressSpeed = motorspeed_prozent * 1.8;
          Serial2.clear();
        }
    
        buttons_read = "";    
        
        Serial2.print("progressSpeed.val=");
        Serial2.print(progressSpeed);
        Serial2.write(0xFF);
        Serial2.write(0xFF);
        Serial2.write(0xFF);
        delay(5);
    
        actualspeed = map(motorspeed_prozent, stepwide, 100, ownminspeed, ownmmaxspeed);
        if (actualspeed < ownminspeed)
        {
          actualspeed = 0;
        }
    
        accelfactor = map(actualspeed, ownminspeed, ownmmaxspeed, 3, 10);
    
        Serial.println(actualspeed);
        Serial.println(accelfactor);
    
    }
    
    void riseDeep5x()
    {
      
      targetposition = risedeep - (risedeep/sonderteiler*sondercounter) + (risedeep/sonderteiler);
      // targetposition = ((1/sondercounter) * risedeep); 
      sondercounter = sondercounter-1;
      if (sondercounter == 0)
      {
        sondercounter = sonderteiler;
      }
    
      Serial.println(targetposition);
      Serial.println(sondercounter);
    
    }
    
    void loop()
    
    {
    
      if (Serial2.available() > 0)
      {
        serialRunWatch();
      }
    
      if (motor.getPosition() == targetposition)
      { 
        if (actualspeed != 0)
        {
        motor.setMaxSpeed(actualspeed); 
        motor.setAcceleration(actualspeed*accelfactor);
        }
        motor.setTargetAbs(backposition);
    
      if (sonderprogramm == 1)
      {
        riseDeep5x();
      }
    
      }
    
      if (motor.getPosition() == backposition)
      {
        motor.setMaxSpeed(actualspeed); 
        motor.setAcceleration(actualspeed*accelfactor);
        motor.setTargetAbs(targetposition);
      }
    
      if ((actualspeed != 0) || (motor.getPosition() != 0))
      {
      controller.move(motor);
      }
      
      delay(5);
    
    }

  14. #139
    Junior Member
    Join Date
    Mar 2023
    Posts
    3
    Does this also work for teensy 4.1? I'm thinking I could just make some slight modification such as

    TeensyStep.h
    Code:
    #elif defined(__IMXRT1052__) || defined(__IMXRT1062__)
    #include "timer/teensy4/TimerField.h"
    Would this be sufficient?

  15. #140
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    17,140
    No reason to include " defined(__IMXRT1052__) " - the 1052 was dismissed long ago after 1062 was made the chosen MCU for T_4.x and is no longer supported or maintained.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •