Go Down

Topic: One stepper bresenham question (Read 170 times) previous topic - next topic

Floduino

Hello, I´m about to build an sidereal tracker for astro photography.

Problem in front: I can set my steps variable via the Keypad shield but the main steps are 3.714 steps/second.

I know there is a way to use the bresenham algorythm to solve this problem with the missing 0.286 steps, but I dont know how, when I´m changing the "speed", cause the difference is changing with it...

My settings are:
-LCD Keypad shield
-Arduino Uno
-Nema 11 (1.8°) with 100:1  gearbox
-A4988 in 1/16 step mode

The calculation:

200 Steps x 100 x 16 = 320000 steps/round

a sidereal day has 86160 seconds.

320000 steps/86160 seconds= 3,714 steps/second


Actuall sketch:
Code: [Select]


#include <AccelStepper.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int adc_key_val[5] ={50, 195, 380, 555, 790 };




int NUM_KEYS = 5;
int adc_key_in;
int key=-1;
int isRun;
double speeds = -241.6;
int maxspeed = 1200;

AccelStepper stepper1(1, 16, 15);

void setup() {                    // void means dont expect any return from this command
  lcd.clear();                    // clear the lcd
  lcd.begin(16, 2);               // set up the LCD's number of columns and rows:
  lcd.setCursor(0,0);
  lcd.print("    Stopped     ");  // display stopped on the LCD
  lcd.setCursor(0,1);
  lcd.print("Speed ");            // display the value of speed
  lcd.print(speeds);              // display the value of speeds
  lcd.print("   ");
  isRun = 0;

  stepper1.setMaxSpeed(maxspeed); //1245
  stepper1.setSpeed(speeds);      //
}

void loop() {
  adc_key_in = analogRead(0);    // read the value from the sensor
  key = get_key(adc_key_in);     // convert into key press
 
  if (key >= 0)                  // if keypress is detected
   {
      if (key == 1) {
         speeds += 0.1;
         delay(100);
      }
      if (key == 2 && speeds > 0) {
         speeds -= 0.1;
         delay(100);
      }
      if (key == 0) {
         speeds += 10;
         delay(100);
      }
      if (key == 3) {
         speeds -= 10;
         delay(100);
      }
      if (speeds>maxspeed) {
         speeds = maxspeed;
      }
      if (speeds<-maxspeed) {
         speeds = -maxspeed;
      }
      if (key == 4) {
        isRun = 1 - isRun;
        lcd.setCursor(0,0);
        if (isRun == 1) {
          lcd.print("+++ Running +++ ");
        } else {
          lcd.print("    Stopped     ");
        }
        delay(250);
      }
      lcd.setCursor(0, 1);
      lcd.print("Speed ");
      lcd.print(speeds);
      lcd.print("       ");
      stepper1.setSpeed(speeds);
      delay(50);
  }
  if (isRun == 1) {
    stepper1.runSpeed();
  }
}

int get_key(unsigned int input)
{
    int k;
    for (k = 0; k < NUM_KEYS; k++)
    {
      if (input < adc_key_val[k])
            return k;
    }
   
    if (k >= NUM_KEYS)
      k = -1;  // No valid key pressed
    return k;
}



Hopefully somebody can help me :)

Thank you!



jremington

#1
Apr 17, 2018, 12:04 am Last Edit: Apr 17, 2018, 02:49 am by jremington
Additional details are needed, and you many need to rethink the motor drive.

The 100:1 drive leads to 0.018 degrees of shaft rotation per full step or 0.009 degrees per half step. How will the shaft rotation be used to drive the camera platform? Is there an additional gear ratio to consider?

One major consideration is that microstepping does not produce accurate fractions of a step. Instead, microstepping is intended to help avoid motor vibrations and resonance effects at certain speeds.

Microstepping also dramatically reduces the torque increment per step, so unless your mechanism is very carefully constructed, the drive may skip steps.

You claim to need 3.714 steps per second, but there is no reason to move the platform every second. Choose a different time step that leads to an integral number of motor steps.

Floduino

Hey, thank you for your anwer!

I´ll drive the camera "directly" without additional gear ratio from the shaft.
For this I´ll mill an mount.

Because of using a 300mm lens, I don´t want the motor to stop and cause any vibrations or backlash.
In my thoughts it would step often enough for a smooth following of the earth rotation.
 
Thats the reason for the 1/16 stepping.

There are versions with additional worm gears, but I don´t have the machines to build an accurate one, so I first wanted to try my own thoughts.


Tell me if I have anything wrong.

Thank you!

outsider

#3
Apr 17, 2018, 12:47 pm Last Edit: Apr 17, 2018, 12:55 pm by outsider
AccelStepper lets you set speed as a floating point number of steps per second, like:
Code: [Select]
stepper1.setSpeed(3.71402);
Which would = 361.002744 degrees per 24 hours. I think.   :smiley-confuse:
Of course the Arduino's time base oscillator is not accurate enough for long term timing, you need a real time clock (RTC) for that.


Floduino

#4
Apr 17, 2018, 03:09 pm Last Edit: Apr 17, 2018, 03:11 pm by Floduino
Thank you!

I have some RTCs at home, the longest exposure would be around 5-10 minutes I think.

Does the accelstepper library round the steps up? Or how does it floating steps?

yeah its cause one "real" day has (around) 23h 56min and 4seconds
 

outsider

#5
Apr 17, 2018, 05:19 pm Last Edit: Apr 17, 2018, 05:28 pm by outsider
Quote
Does the accelstepper library round the steps up? Or how does it floating steps?
Not sure, I think it takes the steps per second that you enter, takes the reciprocal (1 / x) and multiplies that by 1 million to get the step interval in microSeconds. 1 / 3.71402 * 1000000 = 269250 microSeconds or 1 step every 0.269250 seconds. Keep in mind, Arduino uses float (32 bit) NOT double for FP math, so 6 significant digits (like 3.71402 or 37140.2) is all you get.

jremington

#6
Apr 17, 2018, 05:28 pm Last Edit: Apr 17, 2018, 06:29 pm by jremington
Build the mount first, then test whether 1/16th microstepping actually works. You simply cannot assume that it will.

Note that microstepping requires very careful adjustment of the current limit, and a motor that is compatible with the A4988.

outsider

#7
Apr 17, 2018, 05:30 pm Last Edit: Apr 17, 2018, 05:44 pm by outsider
Good tip, JR. Motor may not hold steady at 13/16 of a step for 0.269250 seconds.
Microstepping is good for smooth motion but not for holding position between full steps.

Floduino

Thanks for you help!

I think I'll just test it out.
(the motor is on the way from China)

But some questions:
The motor doesn't stand still for a 'long' time or? Are 0.269250 seconds per step such a long time for holding the motor to lose steps?


About the current I maybe have to say something about my plans on powering it:

The Arduino will be powered directly from my power bank. From there I connected an DC/DC step up (5 to 12V) for the motor.

I connected an 7.5 degree motor for testing and the motor was turning. So I hope the Nema will work also :)

I'll let you know when I finished the mount for testing!


jremington

#9
Apr 17, 2018, 11:23 pm Last Edit: Apr 17, 2018, 11:23 pm by jremington
Quote
Are 0.269250 seconds per step such a long time for holding the motor to lose steps?
Yes. Microstepping is intended for smooth, continuous rotation.

However, more important is that there is very little torque to drive from one stationary microstep to the next. This is part of the reason why the microsteps are not accurate fractions of a full step.

Floduino

Ah now I understand!

And if I set it to 1/8 steps? Would this be more precisely?

The thing is, as I wrote, I don't want to do one step per second cause of the vibrations and backlash of the gears.

jremington

Quote
And if I set it to 1/8 steps? Would this be more precisely?
Possibly, but not guaranteed.

Better to use a larger gear ratio on your reducer, if required.

MarkT

Good tip, JR. Motor may not hold steady at 13/16 of a step for 0.269250 seconds.
Microstepping is good for smooth motion but not for holding position between full steps.
I strongly disagree, microstepping is superior, use it and avoid most of the vibration / resonance
issues with no penalty in holding force.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up