Forum Rule: Always post complete source code & details to reproduce any issue!
Page 3 of 3 FirstFirst 1 2 3
Results 51 to 61 of 61

Thread: New Stepper Motor Library

  1. #51
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    366
    Which Arduino / Teensyduino version do you use? Compiles here without problem for Arduino 1.8.5 and Teensyduino 1.44. (Of course you need to add

    #include "RotateControl.h"
    #include "ResponsiveAnalogRead.h"
    to the code from #47, but it looks like you did that. Do you have any other includes in your code?

  2. #52
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    366
    Ups, found it. I had a slightly newer version locally. It correctly includes <cmath> instead of <math.h>. This avoids conflicts with macros defined in wiring.h. Just uploaded the newest version which should fix it.
    Last edited by luni; 12-28-2018 at 04:29 PM.

  3. #53
    Junior Member
    Join Date
    Dec 2018
    Location
    Portugal
    Posts
    3
    Quote Originally Posted by luni View Post
    Ups, found it. I had a slightly newer version locally. It correctly includes <cmath> instead of <math.h>. This avoids conflicts with macros defined in wiring.h. Just uploaded the newest version which should fix it.
    I tried your example code and it works now (Arduino 1.8.5 and Teensyduino 1.45).

    I will do some more tests and report back if I find any bugs.

    Once again, thanks a lot for your effort!!!

  4. #54
    Junior Member
    Join Date
    Dec 2018
    Location
    Portugal
    Posts
    3
    Hi Luni,

    Do you know of a straightforward way to modify the library to have minimum speeds and accelerations less than 1?

    Thanks!

  5. #55
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    366
    Are you sure that you need a stepper library for speeds below 1s? You won't need acceleration for that low speeds so you can just do something like:
    Code:
    ...
    
    while(notAtTarget)
    {
      digitalWriteFast(stepPin,HIGH)
      delayMicroseconds(10);
      digitalWriteFast(stepPin,LOW)
    
      delay(1000); 
      ...
    }
    ...
    Anyway, here some information from an older discussion about the same requirement: https://github.com/luni64/TeensyStep/issues/9

  6. #56
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    366

    Speed Override Demo

    Here a quick video demonstrating the new speed override feature of TeensyStep. It first accelerates a disk with 4 holes to 1500 rpm and then synchronizes the speed and position of a second motor to the disk by adjusting its speed on the fly. After the motors run synchronized pins of the second motor dive into the holes of the disk at 1500 rpm.

    https://youtu.be/o9pRKvfJtoU

  7. #57
    Junior Member
    Join Date
    Jan 2019
    Posts
    3
    Hello,

    I have tried your new library and everything seems to work except the stopAsync() function. The motor just goes to the target position with the velocity that it had when the stopAsync() function was called and then stops abruptly. Am I doing something wrong?

    Thank you.

    Code:
    #include <StepControl.h>
    
    Stepper motor(23, 22);         // STEP pin: 23, DIR pin: 22
    StepControl<> controller;    // Use default settings 
    
    void setup(){
    
    
      motor.setAcceleration(18750);
      motor.setMaxSpeed(18750);
      motor.setInverseRotation(true);
    }
    
    void loop() 
    {
    
      motor.setTargetAbs(-100000);
      controller.moveAsync(motor);    // Do the move
      delay(2000);
      controller.stopAsync();
      delay(2000);
      
      motor.setTargetAbs(0);
      controller.move(motor);    // Do the move
      delay(1000);
      controller.stopAsync();
    }

  8. #58
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    366
    I didn't test your code yet but there are some things to note:

    First block in loop:
    Instead of the delay(2000) after the stopAsync you should wait until the motor really stopped (e.g. place a while(controller.isRunning(){delay(10);} after stopAsync) or you can use stop() instead which does exactly this. Sending new target position while the motor runs will mess up internal state of the motor. (Since this seems to be a common error I'll add some checks in the call...)

    Second block:
    After your stopAsync you leave the loop without waiting for the motor to stop. A couple of microseconds later you set a new targetPosition while the motor is in full movement. This won't work.

    Unless you really need it, I recommend to use the synchronous (blocking) commands instead of the async (non blocking) commands. I.e. move() instead of moveAsync(), and stop() instead of stopAsync()

  9. #59
    Junior Member
    Join Date
    Jan 2019
    Posts
    3
    Hello luni,

    Thank you for the quick reply and for pointing the mistakes in my test code. I believe I have fixed them.

    Unfortunately neither the stop() or stopAsync() functions seem to work properly for me with this new library. The code below just moves once (i.e. doesn't loop) to the position 100000 and back to 0 and completely ignores both the stop() and stopAsync() commands (the code below works fine with the old library).


    Code:
    #include <StepControl.h>
    
    Stepper motor(23, 22);         // STEP pin: 23, DIR pin: 22
    StepControl<> controller;    // Use default settings
    
    void setup() {
    
    
      motor.setAcceleration(18750);
      motor.setMaxSpeed(18750);
      motor.setInverseRotation(true);
    }
    
    void loop()
    {
    
      motor.setTargetAbs(100000);
      
      controller.moveAsync(motor);    // Do the move (non-blocking)
      
      delay(2000);
      
      controller.stop();              // Stop the motor before move is finished (blocking)
      
    
      motor.setTargetAbs(0);
      
      controller.moveAsync(motor);         // Do the move (non-blocking)
      
      delay(1000);
      
      controller.stopAsync();             // Stop the motor before move is finished (non-blocking)
      
      while (controller.isRunning()) {
        delay(10);                        // Wait until the motor is stopped 
      }
    }

  10. #60
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    366
    Sorry for the late response, I was busy with another project on the weekend. You are right, there was a bug in the development branch. I hope I fixed it, can you give it a try (Branch: develop)?

    Here the code which I tried:
    Code:
    #include "TeensyStep.h"
    
    Stepper motor(23, 22);  // STEP pin: 23, DIR pin: 22
    StepControl controller; // Use default settings
    
    void setup()
    {
      motor
          .setAcceleration(18750)
          .setMaxSpeed(18750)
          .setInverseRotation(true);
    }
    
    void loop()
    {
      motor.setTargetAbs(100000);
    
      controller.moveAsync(motor); // Do the move (non-blocking)
      delay(2000);
      controller.stop();           // Stop the motor before move is finished (blocking)
    
      motor.setTargetAbs(0);
      controller.moveAsync(motor); // Do the move (non-blocking)
      delay(1000);
      controller.stopAsync();      // Stop the motor before move is finished (non-blocking)
    
      while (controller.isRunning())
      {
        delay(10); // Wait until the motor is stopped
      }  
    }

  11. #61
    Junior Member
    Join Date
    Jan 2019
    Posts
    3
    Hi luni,

    Thank you very much for your help! The functions seem to work as expected now. I'm trying to build a camera slider and your library seems to be perfect for this application.

    Cheers

Posting Permissions

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