Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: TeensyStep - How to switch from 1 speed to another

  1. #1
    Junior Member
    Join Date
    Dec 2018
    Location
    Toronto Canada
    Posts
    6

    TeensyStep - How to switch from 1 speed to another

    I'm stuck on figuring out how to actively choose a new speed and have my motors accel/decel from current to the new speed. The code below ramps up to the right speed, but on the new speed command it pops to Zero then starts the second speed. I suspect the delays are part of the issue, but still unsure how to resolve.

    My goal will be to have 10x motors spinning at their own constant speed. When a new set of speeds are received, each motor will adjust to their new desired RPM.

    thanks for any help!

    Code:
    #include <StepControl.h>
    
    Stepper motor_1(10, 9);         // STEP pin: 10, DIR pin: 9
    Stepper motor_2(5, 9);         // STEP pin: 5, DIR pin: 9
    StepControl<> controller;    // Use default settings 
    
    void setup(){
      motor_1
        .setPullInSpeed(800)
        .setAcceleration(40000); //lower = slow. ?won't go above max speed
    }
    
    void loop() {
    
      motor_1.setMaxSpeed(4000);
      controller.rotateAsync(motor_1);    // Do the move
      delay(10000); //how long to run for. at time, start decel
      
      motor_1.setMaxSpeed(400);
      controller.rotateAsync(motor_1, motor_2);    // Do the move
      delay(5000);
    }

  2. #2
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    307
    Sorry, currently this is not possible. The library was designed to efficiently move a bunch of motors synchronized to a target position. It precalculates all movement parameters before the run. Changing those parameters on the fly will generate a mess.

    However, since this requirements pops up regularly I'm already working on a new controller which will allow synchronized rotation of up to 10 motors with on the fly adjustable speed.

    My goal will be to have 10x motors spinning at their own constant speed.
    Unfortunately the Teensies only have four 32bit timers. TeensyStep needs one of those timers for each independently moving group of motors.

    Click image for larger version. 

Name:	motors.png 
Views:	0 
Size:	19.1 KB 
ID:	15317

    So, if you really need those 10 motors running independently on one Teensy, TeensyStep unfortunately is not the right tool.
    Last edited by luni; 12-07-2018 at 09:32 PM.

  3. #3
    Junior Member
    Join Date
    Dec 2018
    Location
    Toronto Canada
    Posts
    6
    Thanks for the quick and thorough reply.

    Ok no problem on not being able to run 10, but is there any way to run for 1 motor to run at a constant speed, then accel/decel to a new constant speed? Apologies if im misreading what you wrote above, I wouldn't want to not use this amazing library if I simply have to buy more teensy's.

    Or what about using a very very large target position, and instead of stopping at the target, a new position & slightly different maxSpeed is immediately chosen and the library switches instantly.

    I suspect there would be a hiccup at the change but haven't tested yet. My motors are spinning constant speeds between1700-2000 PPS (500-600 micros/pulse).

    Looking forward to future iterations of your library! Thanks for all of your hard work.

  4. #4
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    307
    ...but is there any way to run for 1 motor to run at a constant speed, then accel/decel to a new constant speed?
    Currently not, but most probably this should be possible in a couple of days.

    Or what about using a very very large target position, and instead of stopping at the target, a new position & slightly different maxSpeed is immediately chosen and the library switches instantly. I suspect there would be a hiccup at the change but haven't tested yet.
    I'm afraid playing around with this is just wasting your time, the current design is simply not capable to do this. Anyway, I'd be happy if you could test the new controller as soon as it is ready.

  5. #5
    Junior Member
    Join Date
    Dec 2018
    Location
    Toronto Canada
    Posts
    6
    Oh wow, sure thing. More than happy to test it out whenever you are ready. My coding skills aren't stellar but my application is pretty direct so should still be helpful.

    Thanks for being direct about capabilities. I'm creating an installation for mid-January but plan to revise it for additional uses down the road. If I buy drivers that work for 5v and 3.3v I can switch between Arduino/teensy at any point.

    Reach out anytime.

  6. #6
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    307
    Great, the new controller works already. I need to clean up the code and optimize some parts but this makes good progress.
    I'm creating an installation for mid-January but plan to revise it for additional uses down the road.
    Just curious Is this going to be an art installation?

    If I buy drivers that work for 5v and 3.3v I can switch between Arduino/teensy at any point.
    Yesterday I ordered one of those cheap TB6600 "industrial" drivers for some tests. Pictures showing the inside of those drivers do not look very reassuring (as usual, you get what you pay for...) Anyway, I will have a look if they are really compatible to 3.3V as they state (doubt it...).

  7. #7
    Junior Member
    Join Date
    Dec 2018
    Location
    Toronto Canada
    Posts
    6
    Awesome, excited to see it. Yep, its for an art installation ... 10-12x motors spinning at constant but precise RPMs to create an optical illusion.

    I'm trying to get beyond the phase of ordering random pieces, but the TB6600 was one of them. Also have a DRV8825, A4988 Pololu, and Big Easy Driver (A4988).

    I read in one of the comments that its not even a 6600 chip in some of these drivers (though I don't really understand chip-level details). I haven't opened mine up yet to see the guts, but the casing screws are so tightly screwed in the metal is a bit bent ... can't be a good sign for QC hah.

    Might need to order another driver sample that properly accepts 3.3v logic. Reach out if I can help at all.

Posting Permissions

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