luni64 / TeensyStep4

MIT License
17 stars 15 forks source link

Is TeesyStep4 an update of TeensyStep or a whole different library? #4

Open christophepersoz opened 2 years ago

christophepersoz commented 2 years ago

Hello,

I'm trying to update a program I made using TeensyStep with this experimental lib version for Teensy4.x but methods and use seems totally different. Do you intend to update TeensyStep to make it somehow compatible with new Teensy board or not at all?

Thanks a lot! Christophe

luni64 commented 2 years ago

Yes, this is a totally different library. I therefore didn't include it in TeensyStep. Sorry, but I currently do not intend to make the old TeensyStep compatible to Teensy4.x (not enough time).

There is a port to STM processors in the repo: https://github.com/luni64/TeensyStep/tree/STM32 Maybe this helps in case you want to port it yourself? Basically all you need to adapt is the stuff in the src/timer folder. There already is a Teensy4 folder, don't use this, it is better to start from scratch. Take the STM32 and Teensy3 folders as template. If it works I'm more than willing to merge it...

christophepersoz commented 2 years ago

Hi,

Thanks for your quick reply. I'm not sure that my skills are enough to be able to port your lib to 4.x or STM, but I'll have a look on this. The fact is Teensy 3.x are barely all in shortage and hard to find. If I can progress in some ways I will share the result.

Thanks a lot!

vp8181 commented 2 years ago

Hello sir, @luni64 Is the final update yet to come as you said few days back that you almost done.

Thanks & Regards Vaibhav Pandey.

vp8181 commented 1 year ago

@luni64 Hello sir, Any updates? Still working on it ? Is this final Version? Very excited to use this for my 6DOF Robotic arm soon. Hope there is no issue. And Thanks for all your support and hardwork.

luni64 commented 1 year ago

I'm sorry to tell you that, due to a private project, I can't spend significant time on this library until at least early summer 2023. I can do small fixes (couple of hours) but won't find enough time for larger improvements.

Is this final Version?

No, definitely not

vp8181 commented 1 year ago

Alright sir @luni64 I will start using and hope for everything good . I will update you soon with the results.

vp8181 commented 1 year ago

Today while testing with only 1 motor i could see an issue G1 (s1,s2) group motors work fine but when i write s1.move the s2 also moves.(s2 motor was not there but i manualy switched the pins to check if the pulses are generated). Couldn't actually find the issue but i guess the s2 from G1 moves. To solve this issue I had to pass value again for S2 that will be abs(current position). Then only S1 moves. There is no function for constant speed . Can you please help with constant speed along a given path.( The path may contain many points but the speed along the whole path should be same ) . Eg. Welding path When acceleration is 0 there is some certain on which it rotate and does not exceed that speed even if max speed is more that that.

luni64 commented 1 year ago

1) can have a look at the group issue on the weekend.

2) Following a path is a completely different story and is not implemented currently. Usually you can not simply keep the speed constant on a path. E.g., if your path describes a sharp corner, say from a pure x movement to a pure y movement, the x motor needs to decelerate to zero and the y motor needs to accelerate from zero. If you want to keep the path speed constant you need to deviate from the given path. If you need to follow the path exactly, you necessarily need to slow down the speed around the corner. Probably you want to do something in between. All this is usually done by some sophisticated motion planners. TeensyStep is not able to do this. You might want to have a look at grbl which is specifically written for this kind of problems. See here https://github.com/grbl/grbl for the main repository with all the grbl info and here https://github.com/grblHAL/core for a fork with a Teensy 4x driver.

vp8181 commented 1 year ago

Thankyou for your support sir. Like the constant speed that we have in Accel stepper library and multi stepper library example. Max speed is defined and then all the motor speed will be calculated between the two points, if possible please have a look at that example . I have been using it and i am able to move at a constant speed between 2 points but speed , accel. and decel. was the issue. So here can we have something like set a speed for the group and then individual will be calculated without the Acceleration and deceleration. I guess we have it but the speed is very slow , when we keep acceleration 0. Edit-1: When the acceleration is kept 0 the motor runs at 60rpm at 200steps/rev. And if acceleration is not introduced then still there is some x acceleration.

vp8181 commented 1 year ago

@luni64 Sir if possible please look at the issue of maximum speed without Acceleration because that is some how limited. I think , if it is possible to rotate stepper motor in groups without Acceleration we will get constant speed through out the path ( point to point). Same thing happens in accelstepper and multi stepper(example).

https://forum.arduino.cc/t/moving-multiple-stepper-motors-using-accelstepper-and-multistepper-library/512789

In this thread same code has worked for me. Please let me know if you can help with this whenever you have time.

Once again thankyou so much for your kind support sir.

Edit - In the stepper.h file there is default vmax and acc,decel. Can that default vmax be user defined so that even at 0 accel we can set a constant speed ,maybe that can help i guess,I am not sure

vp8181 commented 1 year ago

Hello sir @luni64 Any plan of update this weekend? A gentle reminder of update on grouping issue and setting constant speed

vp8181 commented 1 year ago

Sir had a doubt , Can Teensy 4.1 run 6 stepper motors at 50khz each and handle interrupt from 6 encoders at 50khz each . Will it be to much or it can just do it easily.

luni64 commented 1 year ago

Sorry for answering slowly. Currently I'm very busy with a private project which eats up more or less all my available time.

6 Motors at 50kHz should be OK. I'd simply try it (look at the step pulses with a logic analyzer to make sure).
What do you mean by reading 6 encoders at 50kHz? The important parameter is the count frequency of those Encoders. Is each Encoder generating counts at 50kHz? To answer the question I'd need either the count frequency or information about maximal motor rpm and how many counts per revolution your encoder has.

vp8181 commented 1 year ago

Yes the encoders are 600ppr and at quadrature 2400pulses and at 1500rpm so it's exactly 60khz each and total 360khz interrupt. So the teensy handles the encoder very easily but will the teensy also able to handle the movement of 6 motors (teensystep4) library. I plan to rotate stepper motors at 1600 steps and 1500 rpm with (acc-deaccl), so 40khz per motor and 240khz overall. As the motors will move and encoders will generate the pulses at the same time will it get overloaded or it should do it easily. Also waiting eagerly for your support with this library. Till then i am working on other section of the robotic arm. Thankyou for your support sir @luni64

luni64 commented 1 year ago

I'd recommend to not use an interrupt based quad decoder. These are generally problematic, especially for those high frequencies. I'd give the EncoderTool (https://github.com/luni64/EncoderTool) a try and use the polled version. Polling is best done in a timer interrupt at say 100kHz.

Here a very simple example:

#include "Arduino.h"
#include "EncoderTool.h"

using namespace EncoderTool;

PolledEncoder e1, e2, e3, e4, e5, e6;
IntervalTimer tickTimer;

void tick()
{
    e1.tick();
    e2.tick();
    e3.tick();
    //...
}

void setup()
{
    e1.begin(0, 1, CountMode::full);
    e2.begin(2, 3, CountMode::full);

    tickTimer.begin(tick, 10); // call tick every 10us
}

void loop()
{
    if (e1.valueChanged()) Serial.printf("e1: %d\n", e1.getValue());
    if (e2.valueChanged()) Serial.printf("e2: %d\n", e2.getValue());
    //...
}
vp8181 commented 1 year ago

I have gone through the library, it's really amazing and easy to use . But as i have done lot of work with my code, i would like to stick with it . Thankyou for the help sir @luni64

And also any tentative date for resuming work on this library.

vp8181 commented 1 year ago

Hello Sir @luni64 , i want to stop motor when an interrupt high is seen on x pin. So i use this code to ``

include "Arduino.h"

include "teensystep4.h"

using namespace TS4;

Stepper s1(26,27);

int ms=40000; //max speed int a=1600000; // acc void setup() { pinMode(3,INPUT); digitalWrite(3, LOW); attachInterrupt(3,ALERT,HIGH);

pinMode(32,OUTPUT); digitalWrite(32,HIGH);//normally high to enable and low to disable stepper

TS4::begin(); Serial.begin(9600);

s1.setMaxSpeed(ms); s1.setAcceleration(a); } void ALERT() { s1.stop(); // want to stop Serial.println("STOP");
}

void loop() { s1.moveRel(16000); s1.moveRel(-16000); digitalWrite(32,LOW); delay(5000); digitalWrite(32,HIGH); } `` But this code dosent work. There is also some problem with uploading the code and motor does not even rotate . I want to stop 6 stepper motors working in sync when pin goes high .Even if motor got some steps to go , they will not move and stop (Like an emergency stop).No work until future commands. How can I do that.

vp8181 commented 1 year ago

@luni64 Hello sir, Any assistance with above problem. I got no solutions. Any other way to execute stop when needed based on external interrupt.

Sorry to ask again but the tentative date to start working again on this library.

cbradburne commented 1 year ago

@vp8181 if you're still having problems, try this potential fix LINK

In testing, it worked for me and correctly stopped a "moveRel" with an interrupt pin on a Teensy 4.0.

cbradburne commented 1 year ago

Here's a plot of using an interrupt with 'stop()' with the new code. stop-fix

#include "Arduino.h"
#include "teensystep4.h"

using namespace TS4;

Stepper s1(19, 18);

int ms = 4000;  //max speed
int a = 1600;   // acc
bool running = true;
bool doOnce = true;

elapsedMillis stopwatch;

IntervalTimer t1;
void onTimer() {
  Serial.printf("%6d\n", s1.getPosition());
}

void setup() {
  pinMode(23, INPUT);
  digitalWrite(23, LOW);
  attachInterrupt(23, ALERT, HIGH);

  pinMode(32, OUTPUT);
  digitalWrite(32, HIGH);  //normally high to enable and low to disable stepper

  Serial.begin(9600);
  TS4::begin();
  while (!Serial)
    ;
  t1.begin(onTimer, 50'000);  // print out motor positions
  stopwatch = 0;

  s1.setMaxSpeed(ms);
  s1.setAcceleration(a);
}
void ALERT() {
  if (doOnce) {
    doOnce = false;
    running = false;
    s1.stop();  // want to stop
    Serial.println("STOP");
  }
}

void loop() {
  if (running) {
    s1.moveRel(16000);
  }
  if (running) {
    s1.moveRel(-16000);
  }
  digitalWrite(32, LOW);
  delay(5000);
  digitalWrite(32, HIGH);

  running = true;
  doOnce = true;
}
cbradburne commented 1 year ago

@vp8181 I've just noticed you needed and emergency stop rather than a gradual stop. There is already an emergency stop, just call s1.emergencyStop();

vp8181 commented 1 year ago

@vp8181 I've just noticed you needed and emergency stop rather than a gradual stop. There is already an emergency stop, just call s1.emergencyStop();

Hello @cbradburne I will need emergency stop and gradual both. Emergency for instant stop when user presses button . Gradual for avoiding collision using sensor detected obstacle at certain distance. Will above stop commands work for Grouped Stepper motor moving absolute positions.