TeensyStep - How to switch from 1 speed to another

Status
Not open for further replies.
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() {}
 
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)

slow1.jpg

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)
slow2.jpg
 
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() {}
 
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.
 
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...
 
@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.
 
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.
 
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()
{
}
 
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
 
@Luni
This works very well thanks. Just to confirm that I have my calculations right please.
I have 2.5 step per mm so if I run at 11000 for speed it will be

11000 / 2.5 = 4400 mm/sec when at full speed.

4400 * 3600 = 15.84 km/h

Do I have this right?
 
Yes that looks OK.

Remark: When you are unsure it is always good to add the units to the calculation. You can then easily spot errors.
Code:
(11000 stp/sec) / (2.5 stp/mm) = 4400 mm/sec
(4400 mm/sec) / (1000 mm/m) = 4.4 m/sec
(4.4 m/sec) * (3600 sec/h) = 15'840 m/h = 15.84 km/h
 
I have a related application. I need to run 3 steppers continuously, but often need to change their speed.

I have an interrupt-driven routine that actually does this on a Mega, but it is overworked, to say the least. I do very basic acceleration ramps when I alter the stepper speeds. I would like to get a similar routine running on a Teensy using TeensyStep, if that is possible. (I have TeensyStep running on my bench on a 3.5 with three steppers.)

I muddle through, but my programming is a bit clunky and simplistic, but works. I noticed that you have modified TeensyStep to accommodation continuous rotation with on-the-fly adjustments to speed, but the code snippets you gave were a bit too complex for me to follow. For some reason, I could not get them to compile on my prototype benchtop system. :-(

My application is a DIY 3D filament extruder, based on the RecycleBot from Michigan Tech. I need to smoothly vary the speed of the "puller" stepper that draws the filament out of the extruder with rubber rollers. (This sets the filament diameter by pulling faster or slower. A feedback loop, using a digital dial indicator holds the diameter close to the desired diameter.) A second stepper rotates the spool that winds up the filament. The winder needs to slow down as the spool fills up, and also needs to modulate its speed based on the amount of "slack" sensed in the filament. The third stepper runs the arm that guides the filament on the spool. Its movement is roughly linked to the spool RPM and how full the spool is, but I would like it to be more exact. (Can't spare the CPU cycles on the Mega at the moment.)
 
Status
Not open for further replies.
Back
Top