Git Product home page Git Product logo

teensystep's Introduction

PlatformIO Registry arduino-library-badge

TeensyStep Fast Stepper Library for PJRC Teensy boards

Please note: This is version 2 of the library. This version has a new user interface. The version 1 is still available in the branch Version-1.

Detailed Documentation can be found here https://luni64.github.io/TeensyStep/

Purpose of the Library

TeensyStep is an efficient Arduino library compatible with Teensy 3.0, 3.1, 3.2, 3.5, 3.6 and STM32F4. The library is able to handle synchronous and independent movement and continuous rotation of steppers with pulse rates of up to 300'000 steps per second. The following table shows a summary of the TeensyStep specification:

Description Specification Default
Motor speed / pulse rate 1 - 300'000 stp/s 800 stp/s
Acceleration 0 - 500'000 stp/s^2 2500 stp/s^2
Pull in speed 50-10'000 stp/s 100 stp/s
Synchronous movement of motors up to 10 -
Independent movement of motors 4 groups of 1 to 10 motors -
Settable step pulse polarity Active HIGH or LOW Active HIGH
Settable step pulse width 1-100µs 5µs
Settable direction signal polarity cw / ccw cw

Here a quick demonstration video showing two motors running in sync with 160'000 steps/sec

IMAGE ALT TEXT HERE

teensystep's People

Contributors

alustig3 avatar bimac avatar luni64 avatar lunoptics avatar ramboerik avatar rcp1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

teensystep's Issues

How to reset counter?

Hi - I'm looking for a way to reset the position counter to zero after homing, similar to AccelStepper command setCurrentPosition(). Is it possible?

I'm using the TMC2130 SilentStepStick for sensorless homing. When the motor hits a physical end stop it sets a pin, which should generate an interrupt on the Teensy, and do an emergency (or very fast) stop. Then I need to set that as the zero position.

Thanks...

Limit Switch Stopping

I'm trying to figure out a way to handle stopping at limit switches. I have a minimum limit switch and a maximum limit switch for each motor. It appears that the emergency stop function cannot be called for a particular motor. Since I will have multiple motors (up to 13 motors) moving at one time various ones can hit either limits.

A few scenarios would be:

When turning on the machine and wanting to "home" where we go to min fairly slowly and stop when it hits the limit switch. Then goes forward until it is off the limit switch and then zeros the counter. This way all counters will start at the exact point when the motor comes off the limit switch. It is possible that when the machine turns on the position is already on the min limit. In that case we would want to have it move forward until it comes just off the limit and set the count to zero.

When multiple motors are moving and one of them hits a limit. That motor needs to stop right away while others can happily go to their position. Various motors could hit limits at different times while others need to continue.

I believe I should have the limit switches trigger ISR's when they hit the limit. In the case of hitting the min limit the ISR could include the move forward to get just off the limit.

What are your suggestions?

4 controllers

Just adding two controllers to the RoseFunctionFollower example makes the steppers run very slowly. I'm working on merging the RoseFunctionFollower code into existing rose engine code which uses two StepControl controllers, so I do need four controllers.

typo in readme

motor_1.setPostion(pos); // set a new value of the step counter

setPosition

threw me off a bit :)

STM32duino port

Hi, I have been working for a little while on a stepper project based on one of the STM32 arduino cores. I have had a look at porting your library to STM32 though with the current structure it is very tightly coupled to the Teensy platform so I have had to hack it up quite a bit.

Would you be interested in working with me to support both platforms in the same library? Or at least decoupling the stepper algorithm from the timer and gpio parts so I could more easily keep an STM32 version in sync with yours?

EDIT:
I have been working with master so I haven't had a good look at your current work in the newRotate branch. It looks like the structure has changed a bit so you may already have addressed some of the issues I've been having.

stm32

Very happy to fond your project ,can you give some suggestions on how to port it on stm32f4 platform

Can this library run in speed near or even below 1Hz ?

Hello.
Can this library run motor in about 1Hz (1 step per second) or even less?

I need it to move axis in lapping machine. Old driver died and with 1/4 step division I need to run it at about 1.5 steps per second. But slower speeds would be nice too. Like 1 step per 2 seconds.

I would like to use library as I also need fast movements without loosing track of steps.

STM32 arduino port

Hi,

I'm currently working on a project that is about to migrate from the teensy platform to ESP32 and would like to continue using TeensyStep. Do you know if anybody else has attempted to port TeensyStep to ESP32?

There seems to be a timer implementation for steppers in the ESP32 port of grbl CNC in https://github.com/bdring/Grbl_Esp32/blob/master/Grbl_Esp32/stepper.cpp. It is however deeply integrated with the grbl code but can maybe be used as a starting point.

If I'm about to give it a try, do you have any general advises?

changing target location on the fly

something weird is going on,
if i change the target to a smaller value than the previous one, it works ok.
if i change the target to a bigger value than the previous one, it only reaches the first value.

if i change direction on the fly, it will do emergency brake, then go back to starting position, stops, after that it will start moving to the new location.

also changing max speed on the fly acting weird (step controller)

HOWTO: Coordinate non-linear movement with waypoints in a multi-motor system?

I am controlling an X/Y axis machine (similar to 2DOF CNC) with two stepper motors, and would like to be able to support a circular or arc-like movement (think GCode G02 or G03), by setting a series of "Segment" X/Y coordinates (in the form of step values, as the Controller expects them), and having the stepper motors move through them in a coordinated fashion.

However, I don't want the controller to accelerate / decelerate between waypoints. I only want that acceleration / deceleration at the beginning of the series, and the end. What would be the best way to go about doing something like this using TeensyStep?

stutter motion during continuous updates

I'm not sure if this is an issue with the library or with how I'm trying to use it.

I have a desktop program streams absolute motor positions for six motors from a timeline-based curve editor over serial to a Teensy. When each serial line arrives, I call moveAsync on all six motors at once. The motors obey, but they stutter.

I maxed out the configured velocity, pull-in acceleration, and acceleration because the curves I'm sending from the desktop already limit the max velocity and acceleration.

My coworkers insist that maxing out these values constants means I'm doing something very wrong. Are they right?

Issue with Teensy 3.2

Hi Luni64, I am currently trying to implement your TeesnyStep Library on a Teensy 3.2 with 2 X Steppers driven by DRV8825 boards. I am trying to run the simple example & keep getting lots of errors. I am not too experienced with Arduino etc. so pls forgive my ignorance if I am making a silly mistake. Can you help. Many thanks, John

new 1.txt

Start motion after stopasync

Hi,

Is there a functionality to continue motion after using stop or stopasync?
How to do this?

Thanks in advance.
Krzysztof

On teensy, pin A9 cannot be usable when I load teensyStepV1

If I create this main on my teensy, I cannot use A9 pin. Can you say me why?

int main(void) {
                Stepper motor(2, 3);
                    StepControl<> controller;
                    //motor.setTargetRel(1000);
                    //controller.move(motor);

                    int pos = 0;
                    uint8_t testAttach = myservo.attach(A9); // Pin 23
                    Serial.print("testAttach : ");
                    Serial.println(testAttach);
                    uint8_t testAttached = myservo.attached();
                    Serial.print("testAttached : ");
                    Serial.println(testAttached);
                    for(pos = 0; pos < 180; pos += 1) { // goes from 0 degrees to 180 degrees, 1 degree steps
                        myservo.write(pos);              // tell servo to go to position in variable 'pos'
                        delay(15);                       // waits 15ms for the servo to reach the position
                    }
                    for(pos = 180; pos>=1; pos-=1) {   // goes from 180 degrees to 0 degrees
                        myservo.write(pos);              // tell servo to go to position in variable 'pos'
                        delay(15);                       // waits 15ms for the servo to reach the position
                    }
                    delay(2000);
}

But if I delete StepControl<> controller; I can.

Thanks for your help !

dynamically change setTargetAbs() while motor is moving

I want to use the motor in a way that it constantly receives new target data and that it simply tries to follow the target position. When using the StepControl class I have an easy way to move to an absolute position, but it doesn't allow for a graceful response when giving a new position while it is in the process of going somewhere. RotateControl does allow for dynamic shifts in direction with overrideSpeed(), though then I have to rebuilt the libraries ability to keep track of where it is on my side. Is there any way I could still use StepControl but allow for dynamically changing the absolute target?

This is my current test sketch, it works, but I have the feeling this could be done in a better way.

#include "Arduino.h"
#include "TeensyStep.h"

constexpr unsigned motorStpPerRev = 200 * 16;            // e.g. fullstep/rev * microstepping
constexpr unsigned motorAcceleration = 15000;

float targetMotorSpeed, oldMotorSpeed;

int motorTargetPosition = 0;
int motorTargetDirection = 2; // 0 == up 1 == down 2 == none
int prevMotorPosition = 0;

constexpr unsigned maxSpeed = 1000;

RotateControl controller;

Stepper motor(4, 5);

void setup() {
  Serial.begin(9600);
  while(!Serial) {
    ;
  }
  motor.setMaxSpeed(1);   // -> parameter of overrideSpeed equals real speed
  motor.setAcceleration(motorAcceleration);
  
  // startup controller
  controller.rotateAsync(motor);
  controller.overrideSpeed(0.0f);

//  setMotorTarget(-4000);
  
}

void setMotorTarget(int t) {
  motorTargetPosition = t;
  if(t > motor.getPosition()) {
    motorTargetDirection = 0;
  } else if(t < motor.getPosition()){
    motorTargetDirection = 1;
  } else {
    motorTargetDirection = 2; //none
  }
}

void loop() {
  int p = motor.getPosition();
  int pp = prevMotorPosition;
  int t = motorTargetPosition;

  if(motorTargetDirection == 0) {
    // we go up
    setMotorSpeed(maxSpeed);//up
    if(p > t) motorTargetDirection = 2;
  } else if(motorTargetDirection == 1){
    // we go down
    setMotorSpeed(-maxSpeed);//down
    if(p < t) motorTargetDirection = 2;  
 } else {
    // nowhere
    setMotorSpeed(0);
  }

  prevMotorPosition = p;
  updateSpeeds();

  int sinT = sin(millis()*0.0001)*9000; // send it a changing target (sine wave for testing)
  setMotorTarget(sinT);
  
}

void setMotorSpeed(float rpm)
{
    targetMotorSpeed = rpm / 60.0f * motorStpPerRev;
}

void updateSpeeds()
{   
    if(targetMotorSpeed != oldMotorSpeed)  // if target speed changed -> update all
    {
        oldMotorSpeed = targetMotorSpeed;
        controller.overrideSpeed(targetMotorSpeed);
    }
}

inline int getCurMotorSpeed() { return controller.isRunning() ? controller.getCurrentSpeed() : 0; }

Slow Speed direction changes

Reported by @jpk73: https://forum.pjrc.com/threads/54529-TeensyStep-How-to-switch-from-1-speed-to-another?p=205792#post205792

The following code does not work in the current devTimer branch

#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() {}
  1. ...And finally: this moves the motor, but pullin does not override the acceleration (again dev-timer):
#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() {}

Compiler error in StepControl.h

When compiling the code it produces the following error:

TeensyStep/src/StepControl.h:267:52: error: no matching function for call to 'min(double, float&)'

It is related to the constants 0.0/1.0 being translated by default to double while relSpeed is of type float. The template for min/max cannot resolve a function with different data types as parameters and fails.

By explicitly specify that the constants should be of type float everything works:

change:
relSpeed = std::max(0.0, std::min(1.0, relSpeed)); // limit relative speed to [0..1]

into:
relSpeed = std::max(0.0F, std::min(1.0F, relSpeed)); // limit relative speed to [0..1]

gcc version: 5.4.1
Compiled with c++14 support.

Beta Version of new StepControl

I updated a beta version of an improved controller. (Branch develop_newRotate)

Changes:

  1. Move and moveAsync commands now take up to MaxMotors (i.e. 10) motors instead of 3
  2. Improved acceleration efficiency. For a Teensy 3.1 the acceleration update is done about 30% faster than the old one.
  3. Removed the rotation commands. They will go in a separate controller for efficiency reasons
  4. API for acceleration plugin slightly changed.

Any test very welcome

Unable to get 3 and 4 controllers working

I'm trying to get multiple controllers moving motors at the same time. I have no problems until I get to the 3rd controller, then the Teensy hangs. In fact, any time I try to use the 3rd controller, even synchronously, it hangs. I've attached a sample project that illustrates what I'm trying to do (had to use a txt extension for upload).

I'm using a Teensy 3.2.

Teensy-Stepper.txt

movement planner.. small stepping (turn off acceleration or deacelleration)

Hi,

I would like to use teensy to move 5 dof robotic arm. Actually I'm already using it with some success.
The problem is moving the arm in straight line in inverse kinematics... It is moving point to point so the end position is reached properly but the movement on track is "bending".

I would like to do many small steps to move in straight line in real world kinematics. So I would calculate inverse kinematics for each step but the problem is that every small step has accelleration and deacceleration so it can't run smoothly.
It would be helpfull to have a posibility to moveAsync but with some simple motion planning..

What do you think?

BR,
Krzysztof

Closed Loop Steppers controlled by teensy

hi luni64!
Congratulations on the amazing work you have done. I have been using the teensy step library for some time to drive a boring machine with multiple drills (4). The selected drill lowers down with pneumatic valve and moves in three dimensions (XYZ) with nema 34 stepper motors (2 for X and 1 for each Y and Z). All these are guided by a teensy 3.5 plugged on a pcb board of my own design (5vTTL and optical isolated switches and relays) .

To have high precision in movements I only use 1.8 degree steps and I have set the drivers at 800 steps per round for smooth movement. So I use steps multiple of 4 to drive the motors (the same for home position). The problem is that I have a very low resolution on X and Y axes. With 31 teeth module1 pinion the resolution is 31 * 3,1415 / 200 = 0.48 mm for each step. An analysis of 0.1mm per step would be completely satisfactory and for this I'm thinking of using microstepping and closed loop motors controlled by teensy.

Do you think that tennsy can drive 3 motors simultaneously and read the 3 encoders at the same time? A second thought is to use 2 teensy, one for driving and one for reading, which will communicate once the drill reaches its target so that it can check if the coordinates (X and Y) are correct before z movement.

deceleration confused

Hello,

I noticed a strange behaviour while deceleration. It seems the speed was reduced until zero, not until pull in speed. Also there seems to be a jump from constant speed to a lower value at the beginning of deceleration.
I changed the end of line 124 in StepControl.h
from “… = F_BUS / (sqrt_2a * sqrtf(motorList[0]->target - pos - 1) + 0 * vMin / 2);”
into “… = F_BUS / (sqrt_2a * sqrtf(motorList[0]->target - pos - 1) + vMin);”
Was you playing around with this piece of code and did you forget to change it back to original? There is a difference in older versions of this file.

Can go higher than 65 k steps/s

Hi,
Thanks for this library, which seems very promising.
I'm doing tests to see if I can indeed reach the maximum speed of 300 000 steps/s on an T3.6 @240 MHz, with this simple code :

`#include "TeensyStep.h"

Stepper motor(10,9); // STEP pin: 2, DIR pin: 3
StepControl controller(1); // Use default settings

void setup()
{
motor.setMaxSpeed(300000);
motor.setAcceleration(500000);
}

void loop()
{
motor.setTargetRel(10000); // Set target position to 10000 steps from current position
controller.move(motor); // Do the move
delay(500);
}`

However it seems the pulse frequency never go beyond 65 000 steps/s (I'm using a logic analyser which grabs signals at 500 Mhz). Also when it reaches this rate, it suddenly goes down to 8 Khz.
Is it a bug or am I doing something wrong ?

Constant movement without a target

Is there a way of moving indefinitely without a target? Right now I used setTargetRel(LONG_MAX) from the limits.h library but I don't know if it's going to stop eventually. Great work on the library, thank you!

relSpeed in doMove

Hi, first of all thanks for this great library, great coding here.

I have some questions / suggestions.
I noticed an undocumented option when looking at the library > relSpeed.
I assume an intended use is for speed compensation when using 2 steppers in a Cartesian X/Y configuration, more precisely to achieve a constant speed on diagonal moves.

for a diagonal 45deg move, motors need to run at 0.707106... times the speed of a straight move.
This can also be done by just using setMaxSpeed on the 2 motors.
Which makes relSpeed kind of redundant.

Since you properly implemented the Bresenham algorithm, in which either 1 or 2 motors move simultaneously, the integral sum of both moves(steps) as C is exactly the same as the hypotenuse from a (X) b(Y). ( both as steps) > c = √(a² + b²)
( as opposed to the implementation where either motor moves separately and the hypotenuse becomes a + b ... in theory :-) > funny math but true ... )

My point is that in this instance (cartesian 2D kinematics) relSpeed should always either be 1.0 ( when 1 motor steps ) or 0.707106 when both step ... ( on every doMove ).

directly computed onto the StepTimer reload values.
This would free up quite a lot of resources since one doesn't need to calculate either relSpeed. or setMaxSpeed. to get a constant absolute speed like one has to do now..

A Stepcontrol.setMaxSpeed function for the controller, that overrides the individual Stepper.setMaxSpeed function can then be used to control the actual absolute speed.

Yet another suggestion would be to implement a callback function on (!Stepcontrol.isRunning())
Now you have to constantly poll this function which makes your elegant code in practice a bit crude.
Even better would be an option to define a shared ring buffer, which can be handy for next suggestion.

I'm assuming you'll want people to actually use this in for example their own gcode interpreter ...

Last suggestion.
Acceleration / deceleration always goes from 0 > max > 0.
An option to define a min acceleration would be great.
I know one can effectively disable acceleration by setting setPullInSpeed to vMaxMax, but my suggestion is not the same...

One could then use said ring buffer to predict how much acceleration / deceleration is actually needed for the next move, depending on the difference in angle.
For example a 90 deg angle difference would result in 0.0 > 1.0 for X / 1.0 > 0.0 for Y. (acceleration/deceleration for X/Y)
A 10 deg > angle would then need 0.984... > 1.0 for X / 1.0 > 0.984... for Y.
Easy math ...

I might have a go at it myself later on.. I'm just curious what you think of these ideas.
Your programming skills are better then mine....

Lastly.
I'm not sure why people haven't picked this up...
A very easy way to get high speed pulses.

Up to now I always used shift registers connected to SPI to create high speed pulses.
For example 2 * 74hct595 daisy chained ) connected to a 16MHz SPI gives you 500Khz on/off on 15 pins ), use the msb bit to auto latch the chips, you'll lose 1 bit but don't need an SS pin then ( and it's latency)
DMA transfers makes this very lightweight ( you do need a reset pin at startup ).
Do a begin transaction once in setup, and just transfer....

use HCT if you need 3.3 > 5V voltage translation ( HIGH starts at max 2V typ 1.6V input pins)
use HC for 3.3V ( works from 2V - 7V ) both up to 100MHz ..

TeensyStep and TMC2130 SST

Hi,
I don't know if i'm in the good place to post this issue, that is my first message on github. I ll move/delete the message if the place is not approprieted.
I 'm trying to move nema17 stepper with tmc2130 and TeensyStep, with teensy 3.2.
Recently, i had no problem with the classic AccelStepper lib, but it's not powerful enough for my application.
This is my sketch:

#define EN_PIN    4  
#define DIR_PIN   3  
#define STEP_PIN  2
#define CS_PIN    10  

int pos;

#include <TMC2130Stepper.h>
#include <StepControl.h>
TMC2130Stepper driver = TMC2130Stepper(EN_PIN, DIR_PIN, STEP_PIN, CS_PIN);
Stepper motor(2, 3);
StepControl<>controller;



void setup() {
  motor.setMaxSpeed(30000);
  motor.setAcceleration(100000);
  
  SPI.begin();
  Serial.begin(250000);
  while (!Serial);
  Serial.println("Start...");
  pinMode(CS_PIN, OUTPUT);
  pinMode(EN_PIN,OUTPUT);
  digitalWrite(CS_PIN, HIGH);
  driver.begin();             // Initiate pins and registeries
  //driver.rms_current(2000);    // Set stepper current to 600mA. The command is the same as command TMC2130.setCurrent(600, 0.11, 0.5);
  driver.run_current(20);
  driver.hold_current(5);
  driver.hold_delay(2);
  driver.stealthChop(1);      // Enable extremely quiet stepping
  driver.stealth_autoscale(1);
  driver.microsteps(32);

  //digitalWrite(EN_PIN,HIGH);
  
}

void loop() {
    pos = motor.getPosition();
    pos=pos+1000;
    Serial.println(pos);
    motor.setPosition(pos);
    controller.move(motor);    // Do the move
    delay(2000);
}

Right now, motor is not moving.
I was looking on problem concerning EN_PIN, but even by commenting/uncommenting

digitalWrite(EN_PIN,HIGH);
//or
digitalWrite(EN_PIN,LOW);

Nothing is happening.
I double check code/wiring, but i may make a mistake.
Can someone have an idea about this issue?
Thanks in advance.
Regards.

Speed not 0 after emergency stop

Hey, I think the getCurrentSpeed() should return 0 after an emergency stop. I think right now it returns the last speed before the stop was called.

Homing motors using limit switches?

This is basically the same question as in #6 , where it didn't really receive an answer.

At the startup of my system (6DOF robot arm, with 6 steppers), I Would like to "home" the system by moving motors slowly until limit switches are hit for each joint, then moving forward until the limit switch is no longer engaged, at which point I would set the zero position for the motor.

When the limit switch is hit, I want to stop the motor immediately (ie: no deceleration, no waiting, etc). But I want to do this independently for each of the six motors, and there doesn't seem to be a way to do that with the StepControl class (emergencyStop(), stop() and stopAsync() affect all motors).

What is the best way to e-Stop (or even just regular stop) a single motor? Do I need to instantiate multiple controllers (one for each motor)?

Not an issue but more a question

Hello!

Is it possible to control 6 motors in sync. so if they have different steps to move they arrive at target at the same time?

the move command can handle up to 3 motors.

Thank you!

Converting from old library to new library

Hey
I downloaded your library about 7 months ago and I used it for a project.
About 2 weeks ago, my Ubuntu OS got wiped (attempting to install Arch was a bad idea).
I recloned your repository, and I have now realized you have made some huge changes to the library. I figured this out because the library importing

#include <StepControl.h>

in my project totally crashes.
I have looked through your tags and found that you still have the original code, which is great. Now I am trying to figure out, why did you create a new version of the library? What are the differences between versions? What is so special about the update?
I do not want to say that this library is bad... It has been super useful. I just don't see a migration chart explaining the differences between libraries.

Limit on number of controllers

Hi. I've been writing an app to control 4 or more steppers using random independent graph curves. This is a bit like a cnc application but quite the same. I have struck a problem with the apparent limit on 4 controllers. I need to use a separate rotatecontroller for each motor because of the independent but coordinated movement of these axes. I also need to run atleast one steppercontroller which is used for positioning of the individual axes when not running them via the rotatecontroller. This effectively limits me to 3 axes. Without going into too much detail and alternatives, my question is if it is possible to increase the number of timers so that more than 4 controllers can be used simultaneously? Thanks

Setting Steps with Button Input

Hi,
I am using a Teensy 3.6 to control 2x Nema 34 Stepper motors through two drivers. I have the STEP and DIR pins connected to the Teensy along with a UP and Down Button.

I would like the motors to move up while holding the UP button and the motors to move down while holding the down button.
I am having issues writing the correct code for this, as it results in the motor going very slow & the motor is jumping/skipping.

Thanks

Synchronous Movement with more than 3 motors

Hi, this looks like a really great library with a neat interface.

I'm trying to move 4 motors at the same time. As the readme states "the controller accepts up to 10 motors in its move and moveAsync command. All motors which are passed to the commands will be moved synchronously."

So when I try to compile my code, I get the following error:

controller.move(M1,M2,M3,M4);    // Do the move
                            ^
no matching function for call to 'StepControl<>::move(Stepper&, Stepper&, Stepper&, Stepper&)'

Same with

controller.moveAsync(M1,M2,M3,M4);    // Do the move
                                ^
no matching function for call to 'StepControl<>::moveAsync(Stepper&, Stepper&, Stepper&, Stepper&)'

With 3 Motor objects the code runs flawlessly.

So before I modify anything in StepControl.h in the template definitions, I decided to ask here ;)
I checked out the latest git version.

Cheers

Current Speed?

Hi,
Thanks for providing the library!
Looking to use it for continuous rotation, with a pot controlling speed (lots of overrides...). I would like to be have the current speed display on an LCD screen eventually, but for now it would be useful just to test my code. I saw from an update you had posted somewhere that this is possible, but cannot find how?
Thanks for your time!

Continuous Rotation - cant change direction

Great job on this library! I'm having a problem though.. changing motor.setMaxSpeed to negative or positive is not changing the direction of the motor.

Here's the code I'm converting from AccelStepper to TeensyStep..

I've only programmed the Blue and Yellow buttons so far.. pressing Blue spins the motor CCW.. then pressing Yellow also spins the motor CCW..

`#include <Adafruit_GFX.h> // Include core graphics library for the display
#include <Adafruit_SSD1306.h> // Include Adafruit_SSD1306 library to drive the display
#include <Wire.h>
#include <ResponsiveAnalogRead.h>
#include <AnalogMultiButton.h>
#include <StepControl.h>

//===============================
//button setup
//===============================

const int BUTTONS_PIN = A0; // define the analog pin for buttons
const int BUTTONS_TOTAL = 4; // button count
const int BUTTONS_VALUES[BUTTONS_TOTAL] = {12, 344, 512,614}; // assign button codes
// assign button names
const int BUTTON_BLUE = 0;
const int BUTTON_YELLOW = 1;
const int BUTTON_GREEN = 2;
const int BUTTON_RED = 3;
AnalogMultiButton buttons(BUTTONS_PIN, BUTTONS_TOTAL, BUTTONS_VALUES);

//===============================
//Pot setup
//===============================

const int knob = A9;
ResponsiveAnalogRead analog(knob,true);
int potval = 0;

Adafruit_SSD1306 display; // Create display

// Define stepper & pins.
Stepper stepper(4,3); // Define stepper & pins: motorName(step pin, direction pin)
StepControl<> controller; // Construct Controller object

int led = 13; // Built-in LED pin
int val = 0;
int StepSize = 500;
int MaxSpeed = 30000;
int MaxAccel = 200000;
int long SliderPosIn = stepper.getPosition();
int long SliderPosOut = stepper.getPosition();
int long SliderPosHome = stepper.getPosition();
int long MotorPos = stepper.getPosition();

void setup()
{
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Initialize display with the I2C address of 0x3C
Wire.setClock(1000000); // Teensy Steroid injection for the OLED
display.clearDisplay(); // Clear the buffer
display.setTextColor(WHITE); // Set color of the text
display.setRotation(0); // Set orientation. Goes from 0, 1, 2 or 3
display.setTextWrap(false); // By default, long lines of text are set to automatically “wrap” back to the leftmost column.
display.dim(0); //Set brightness (0 is maximun and 1 is a little dim)
pinMode(led, OUTPUT);
stepper.setMaxSpeed(MaxSpeed);
stepper.setAcceleration(MaxAccel);
//Serial.begin(9600);
}

void loop()
{
analog.update();
buttons.update();
potval = analog.getValue(); // Pull Analog value

if(buttons.isPressedAfter(BUTTON_BLUE,500))    // Hold Down to move
{
  stepper.setMaxSpeed(-30000);
  controller.rotateAsync(stepper);
  while (controller.isRunning() && analogRead(BUTTONS_PIN)!=1023)
  {
  display.clearDisplay();
  display.setFont();
  display.setCursor(1,5);
  display.println("Moving LEFT");
  MotorPos=stepper.getPosition();
  display.println(MotorPos);
  display.display();
  }
  controller.stopAsync();
}


if(buttons.onReleaseBefore(BUTTON_BLUE,500))    // Quick click set LEFT 
{
   SliderPosIn = MotorPos;
   display.clearDisplay();
   display.setFont();
   display.setCursor(1,5);
   display.println("IN Point Set");
   display.println(SliderPosIn);
   display.display();
   FlashLed(1);

}

//
if(buttons.isPressedAfter(BUTTON_YELLOW,500)) // Hold Down to move
{
stepper.setMaxSpeed(30000);
controller.rotateAsync(stepper);
while (controller.isRunning() && analogRead(BUTTONS_PIN)!=1023)
{
display.clearDisplay();
display.setFont();
display.setCursor(1,5);
display.println("Moving RIGHT");
MotorPos=stepper.getPosition();
display.println(MotorPos);
display.display();
}
controller.stopAsync(); }
//
// if(buttons.onReleaseBefore(BUTTON_YELLOW,500)) // Quick click to set
// {
// SliderPosOut = MotorPos;
// Serial.println("Right Point Set");
// FlashLed(1);
// }
//
// if(buttons.isPressed(BUTTON_RED)) // Home Motor
// {
// Serial.println("Homing");
// stepper.runToNewPosition(SliderPosHome);
// MotorPos=SliderPosHome;
// }
//
// if(buttons.onRelease(BUTTON_YELLOW)) // Run Motor IN to OUT
// {
// Serial.print("Running IN to OUT");
// stepper.runToNewPosition(SliderPosIn);
// delay(500);
// stepper.setMaxSpeed(10000);
// stepper.setAcceleration(5000);
// FlashLed(2);
// stepper.runToNewPosition(SliderPosOut);
// Serial.println("....Done");
// stepper.setMaxSpeed(MaxSpeed);
// stepper.setAcceleration(MaxAccel);
// MotorPos=SliderPosHome;
// FlashLed(3);
//
//
// }

// if(analog.hasChanged())
// {
// StepSize = map(potval,2,999,5,1000); // remap pot to StepSize
//// stepper.runToNewPosition(MotorPos);
// FlashLed(1);
// }

}

void FlashLed(int blinks)
{
digitalWrite(led,LOW);
for (int x = 1; x<= blinks; x++) {
digitalWrite(led,HIGH);
delay(100);
digitalWrite(led,LOW);
delay(100);
}

}
`

setPullInSpeed() not recognised in library

I'm trying to use the function motor.setPullInspeed(800); as on the site example. but it doesn't recognize it when i compile. I'm using a teensy 3.5. I tried looking in the library and can't find it anywhere.

Motion doesn't stop with some combination of speed/acceleration

Hi
First of all thank you for this high performance library, loving it from release 1

I'm having trouble with some motion settings, it happens that with some combinations of speed and acceleration motion doesn't stop and the motor keep running indefinitely

The behavior is that the motor keep slowing down normally while approaching the target position until the speed reach a plateau and it keep going at that speed overshooting the target and never stopping

This behavior happen mostly setting high acceleration and slow motion speed, both using moveAsync and/or stopAsync

I'm using TeensyStep V2 with the default interpolation and pulselength values on a Teensy3.6

Any idea why?

Thank

Support for teensy 4.0

high im not sure where to post this but i would like to know if your library supports teensy 4.0 or will in the future?

Program stalls when creating more than two StepControl objects

I ran into an error when I tried to run three stepper motors using three different StepControl objects; the whole program would freeze when I tried to call any move commands. However, it worked perfectly fine with two motors in the same configuration. Do you know why this occurred?

how to change the step pulseWidth

Hello,

The driver I use needs a longer pulseWidth (optocoupler), I changed the value in StepControl.h, but is there a function call to change it and leaving the library unchanged?

btw Thanks for the great library, I've tested a 4.567khz step freq, and the result on my freq counter was 4.566khz!

Emile

Does this library work for Arduino?

Hi. This might be a silly question but I've never used Teensy before. I tried to use this library for my Arduino Mega but got plenty of built errors (missing libraries). Is there a way o use this library on ARDUINO?

Weird behavior with 3 and 4 controller objects

@conkerts Does this work by now for you?

Hi, I seem to have weird behavior with 3 and 4 controller objects as well.
I just recently cloned the repo (when I wrote my first question here), and I checked I have the version=0.98 .

Basically I've got 4 Motor objects and 4 controllers (and each controller moveAsync a motor, so pretty straight forward). It first works for some commands, then I get weird motor movements, even I send commands to a completely different controller & motor. After reset of the Teensy it works again for some commands ...
(Teensy 3.5 btw , with all current Arduino versions)

Should I post my details here, or create a new, separate issue ?
And how can I debug this issue most effectively ? .

Check for NULL in doRotate?

I'm trying to use this library with an array of 16 steppers. I need to have some subset (up to 16) of the motors rotate continuously but I don't know which motors until run-time. The motors that need to rotate are specified via a command to the Teensy. I've already increased MaxMotors.

So, the method I've written doesn't know beforehand how many motors will be rotating, so it declares an array of sixteen Stepper pointers initialized to NULL, then fills in as many as necessary for the given the command. It then passes this array to rotateAsync.

If I'm reading the library code correctly, this entire array (16 elements, some of which are NULL) is copied to motorList and doRotate is called with N=16. In the loop in that method there is no check against NULL before calling the setTargetRel method on each motor. That seems bad for my use case.

Should there be a NULL check before making that call? Or can you suggest a different way of doing what I need?

Also, sort of related to this, the templated rotateAsync method has a line: motorList[N] = nullptr; But the motorList is only initialized to have MaxMotors elements, which in my case is 16. Doesn't that line overwrite the memory beyond the end of the array for N=16? Should motorList actually have MaxMotors +1 elements? Or should the line be removed?

moveAsync for an array of steppers

Hello! The readme says that a controller can control up to ten motors but I'm confused about the usage of the function. I thought, if motors is an array of stepper pointers, the way to call the function would be controller.moveAsync(motors); but that causes the Teensy to crash. What's the correct way to do this?
Thanks!

Problem with Blocking of Serial Send

Hi Lutz. I am back to my little project.

For various reasons I am trying to use a combination of global and local controllers, because I need to switch between controller types for different functions. I could have just stuck to 4 global controllers if there was a type that did everything I need. But the problem in my case is that the rotatecontrol can't be used for moving to a specific position - so I need to use a local stepcontrol if I wish to perform that operation. But - the problem I am finding is that the local control will not allow me to monitor the motor position and return it by serial to my external program, while it is carrying out it's business.

Here is a simplified sample of the way I am doing this...

if (letter0 == "G0")   {
    StepControl localSC0;  //declare a local control
    moveto = receivedint0;  
    Mtr_0.setTargetAbs(moveto);  //set the target position for the move
    localSC0.moveAsync(Mtr_0);  //start moving the motor
    while(Mtr_0.getPosition()!=moveto){
    Serial.printf("P0%i\n", Mtr_0.getPosition());  //send feedback on where it is 
}

To explain a little more. I first tried to use "localSC0.move(Mtr_))" which ran the motor to the required position, but completely blocked any other activity while it was moving the motor. Hence the above code using "moveAsync" with the while loop which keeps it "alive" - otherwise the function doesn't work at all. Now inside that loop I want to send the serial data to update my external control program so it knows where the motor is... But it doesn't work. The serial command does not work in that loop.

Any idea why - or if there is another way to achieve what I need? Thanks G

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.