Forum Rule: Always post complete source code & details to reproduce any issue!
Page 4 of 4 FirstFirst ... 2 3 4
Results 76 to 85 of 85

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

  1. #76
    I Did some more tests and found that estop (in master branch) works only in one direction:

    Code:
    #include "TeensyStep.h"
    
    Stepper motor(22, 41);
    RotateControl RotCtrl(5, 1000);
    StepControl StpCtrl(5, 1000);
    
    void setup() {
      motor
      .setMaxSpeed(-2000)
      .setAcceleration(2000);
      RotCtrl.rotateAsync(motor);
    
      delay(1000);
    
      RotCtrl.emergencyStop();
      motor.setTargetRel(300);    // works
      StpCtrl.move(motor);
    
      delay(2000);
      
      motor
      .setMaxSpeed(2000)
      .setAcceleration(2000);
      RotCtrl.rotateAsync(motor);
    
      delay(1000);
    
      RotCtrl.emergencyStop();
      motor.setTargetRel(-300);    // does not work: moves into wrong direction
      StpCtrl.move(motor);
    }
    
    void loop() {}

  2. #77
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    423
    EDIT2: I did some more tests: the 3rd code block of #21 does not work.
    I tried this but it seems to work as it should. Here the LA output. (The peaks shown in the third trace are generated directly after the stop commands)

    Click image for larger version. 

Name:	slow1.jpg 
Views:	6 
Size:	35.5 KB 
ID:	16619

    I Did some more tests and found that estop (in master branch) works only in one direction:
    This is already fixed in the DevTimer branch. Can you give it a try? it also includes the re implementation of the PullInSpeed you requested above...

    Here the traces (I did reduce the delay between the two blocks from 2s to 0.5s to get a more compact display)
    Click image for larger version. 

Name:	slow2.jpg 
Views:	6 
Size:	23.3 KB 
ID:	16620

  3. #78
    Quote Originally Posted by luni View Post
    I tried this but it seems to work as it should. Here the LA output. (The peaks shown in the third trace are generated directly after the stop commands)
    I will try to give some examples... Here my observations. The following works in master branch but not in dev-timer:
    Code:
    #include "TeensyStep.h"
    
    Stepper motor(48, 47);
    RotateControl controller(5, 1000);
    
    void setup() {
      motor
      .setMaxSpeed(124)
      .setAcceleration(198);
    
      controller.rotateAsync(motor);
      delay(2000);
      controller.stop();
    
      motor
      .setMaxSpeed(-124)
      .setAcceleration(198);
      
      controller.rotateAsync(motor);
      delay(2000);
      controller.stop();
    }
    
    void loop() {}
    The next code block works also in dev-timer:
    Code:
    #include "TeensyStep.h"
    
    Stepper motor(48, 47);
    RotateControl controller(5, 1000);
    
    void setup() {
      motor
      .setMaxSpeed(124)
      .setPullInSpeed(200);
    
      controller.rotateAsync(motor);
      delay(2000);
      controller.stop();
    
      motor
      .setMaxSpeed(-124);
      
      controller.rotateAsync(motor);
      delay(2000);
      controller.stop();
    }
    
    void loop() {}
    The following does not work in dev-timer:
    Code:
    #include "TeensyStep.h"
    
    Stepper motor(48, 47);
    RotateControl controller(5, 1000);
    
    void setup() {
      motor
      .setMaxSpeed(124)
      .setAcceleration(198);
    
      controller.rotateAsync(motor);
      delay(2000);
      controller.stop();
    
      motor
      .setMaxSpeed(-124)
      .setPullInSpeed(200);
      
      controller.rotateAsync(motor);
      delay(2000);
      controller.stop();
    }
    
    void loop() {}
    And finally: this moves the motor, but pullin does not override the acceleration (again dev-timer):
    Code:
    #include "TeensyStep.h"
    
    Stepper motor(48, 47);
    RotateControl controller(5, 1000);
    
    void setup() {
      motor
      .setMaxSpeed(124)
      .setAcceleration(198)
      .setPullInSpeed(200);
      
      controller.rotateAsync(motor);
      delay(2000);
      controller.stop();
    }
    
    void loop() {}

  4. #79
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    423
    Thanks again for finding all those bugs! Very helpful indeed.
    It might be easier to continue this discussion on GitHub. I opened an issue here: https://github.com/luni64/TeensyStep/issues/47

  5. #80
    Junior Member
    Join Date
    Nov 2013
    Posts
    14
    Hi Luni
    I also posted in another thread but this one might be more applicable.
    I wonder if you could give me some advice on my project?
    I have a carriage on a 6m long guide. The carriage is pulled by a 8Nm stepper power by a 48v supply. The stepper has a 1:2 reduction and the looped belt has a ratio of 1:0.6. The carriage will move about 400mm per revolution of the motor.
    The objective:
    I have to accelerate the carriage in the first 2m to 8m/s then maintain that for 2m and then decelerate for the last 2m. This is done both ways.

    I am having problems conceptualizing how to use the library to achieve this. If the acceleration could be specified for a distance or a duration, then it could be done.
    Any suggestions will help please.

  6. #81
    On my machine I do the following:

    Code:
    #include "TeensyStep.h"
    
    Stepper motor(48, 47);
    StepControl controller(5, 1000);
    
    int motor_steps_per_rev = 200;
    int motor_microstepping = 4;
    int pulley_teeth = 28;
    int pulley_pitch = 3;    // in mm
    int travel = 800;        // travel in mm
    int speed = 200;         // speed in mm per second
    int acceleration = 500;  // mm/s to be reached in 1 sec of acceleration starting from zero
    
    int steps_per_mm = motor_steps_per_rev * motor_microstepping / pulley_teeth / pulley_pitch;
    
    void setup() {
      motor
      .setMaxSpeed(speed * steps_per_mm)
      .setAcceleration(acceleration * steps_per_mm)
      .setTargetRel(travel * steps_per_mm);
    }
    
    void loop() {
      // move motor
    }
    Hope that helps...

  7. #82
    Junior Member
    Join Date
    Nov 2013
    Posts
    14
    @JPK, I got the calibration sorted thanks. My question is more related to getting the acceleration over a shorter time than what is achievable at the moment. I just included the setup information to make my case as clear as possible.

    The situation is this, if you give a move command that is 6000mm away the library move will accelerate to get to maximum speed at the 3000mm mark and then deccelarate to stop at 6000mm.
    What I need is to move to 6000mm but accelerate to max speed at 2000mm then travel at max speed until 4000mm and the decelerate to stop at 6000mm.

  8. #83
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    423
    I can give you a more detailed answer later today but I think all you need to do is calculate the acceleration you need for your movement.

    Standard kinematic formulas are (out of my head without verifying)

    v^2 = 2as, where a = acceleration, v = velocity and s = distance.

    This gives:
    a = v^2/2s

    Insert v=4000mm, s = 2000mm which gives you the required acceleration. Transform that from mm/s^2 to steps/s^2 and use the result as parameter for setAcceleration(). Then setting the target to 6000mm and start the movement should be all which is required. For the way back set the target to 0 and start the movement.

  9. #84
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    423
    This should do what you want:

    Code:
    #include "TeensyStep.h"
    
    // since you know how to transform from mm to steps we can as well 
    // assume that 1 step = 1mm
    
    int s = 6000;         // total distance
    int s_a = 2000;       // accleration distance 
    int v = 10000;        // target speed 
    int a = v*v/(2*s_a);  // acceleration
    
    StepControl controller; 
    Stepper motor(0,1);
    
    
    void setup()
    {
        motor
        .setMaxSpeed(v)
        .setAcceleration(a);
        
        motor.setTargetAbs(s);  // up
        controller.move(motor);
    
        motor.setTargetAbs(0);  // back
        controller.move(motor);
    }
    
    void loop()
    {
    }

  10. #85
    Junior Member
    Join Date
    Nov 2013
    Posts
    14
    Ah I see the picture a bit clearer now. My understanding of the acceleration function was a bit screwed. Thank a lot I will try this in the morning

Posting Permissions

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