A quick photo of the RA stepper motor and CW / CCW buttons being tested. |
Like I have said before, I really don't know much about this C++ malarkey, so I am sure someone will be poking holes in it, please feel free to improve on it if you wish - My end game is to have a downloadable Arduino library and build plan so others can make a cheap motorised telescope mount, any assistance would be welcomed.
/*-----( Import needed libraries )-----*/ #include <Stepper.h> #include <Wire.h> #include <Button.h> unsigned long start, finished, elapsed; // Unsigned long for Sidereal day calculation /*-----( Declare Constants, Pin Numbers )-----*/ //---( Number of steps per revolution of INTERNAL motor in 4-step mode )--- #define STEPS_PER_MOTOR_REVOLUTION 32 //---( Steps per OUTPUT SHAFT of gear reduction )--- #define STEPS_PER_OUTPUT_REVOLUTION 32 * 64 //2048 /*-----( Declare objects )-----*/ // create an instance of the stepper class, specifying // the number of steps of the motor and the pins it's // attached to //The pin connections need to be 4 pins connected // to Motor Driver In1, In2, In3, In4 and then the pins entered // here in the sequence 1-3-2-4 for proper sequencing Stepper RA_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11); Stepper DEC_stepper(STEPS_PER_MOTOR_REVOLUTION, 12, 14, 13, 15); Stepper FOC_stepper(STEPS_PER_MOTOR_REVOLUTION, 16, 18, 17, 19); /* Create Button Objects */ Button RAscCW = Button(A0,PULLUP); //create a Button object for the Right Ascension Clockwise switch @ pin A0 Button RAscCCW = Button(A1,PULLUP); //create a Button object for Right Ascension Anti-Clockwise switch @ pin A1 Button DECCW = Button(A2,PULLUP); //create a Button object for the Declination Clockwise switch @ pin A2 Button DECCCW = Button(A3,PULLUP); //create a Button object for the Declination Anti-Clockwise switch @ pin A3 Button HNudgeBut = Button(A4,PULLUP); //create a Button object for the Hour Plus Nudge switch @ pin A4 Button MNudgeBut = Button(A5,PULLUP); //create a Button object for the Minute Plus Nudge Anti-Clockwise switch @ pin A5 Button FOCUSin = Button(A6,PULLUP); //create a Button object for the Telescope Focus IN switch @ pin A6 Button FOCUSout = Button(A7,PULLUP); //create a Button object for the Telescope Focus OUT switch @ pin A7 int Stepcount = 0; // creates a zero value for the stepcounter int Hnudge = 0; // Nudge Hour + 1 int Mnudge = 0; // Nudge Minute + 1 float D,LSTH,LSTM,LSTS,ms; // sidereal count millis float ihr; // create float for output of initial convertion float stepdegrees; // output from stepper motor in degrees void setup() /*----( SETUP: RUNS ONCE )----*/ { Serial.begin(9600); // will have LCD here on final version. } void loop() /*----( LOOP: RUNS CONSTANTLY )----*/ { if(HNudgeBut.isPressed()) // Hour Nudge Button + 1 { Hnudge++; } if(MNudgeBut.isPressed()) // Hour Nudge Button + 1 { Mnudge++; } if(RAscCCW.isPressed()) // Right Ascension Clockwise Slew { RA_stepper.setSpeed(900); // speed RA_stepper.step(-50); // step value per cycle - too high == lack of sensitivity / too low == poor slew rate/stutter Stepcount -=50; // stepcount must equal step value per cycle. } if(RAscCW.isPressed()) { RA_stepper.setSpeed(900); // speed RA_stepper.step(50); // step value per cycle - too high == lack of sensitivity / too low == poor slew rate/stutter Stepcount +=50; // stepcount must equal step value per cycle. } else { RA_stepper.setSpeed(300); // Adjust to equal 0.2507 Degrees of Right Ascension per minute RA_stepper.step(1); // step value per cycle, 1 is OK for low speeds, may need to change once fitted to mount and tested Stepcount ++; // stepcount must equal step value per cycle. } int Hnudge; // Nudge Hour + 1 int Mnudge; // Nudge Minute + 1 float ihr; // create float for output of initial convertion float stepdegrees; // output from stepper motor in degrees stepdegrees = ((Stepcount/5.68)/10)+37.954; // when the Arduino is "reset" @ polar alignment the count will start at pos; 37.954541 degrees *location of polaris* Hnudge = 0; // Sidereal clock set Hour nudge Mnudge = 0; // Sidereal clock set Minute nudge ihr = ((stepdegrees/15)); // divides total degrees into number of hours in an sidereal day (15 degrees per hour) float D,LSTH,LSTM,LSTS,ms; // Local Sidereal time calculator, with nudge control for setting the clock. unsigned long over; elapsed=(((ihr*3600000)+(Hnudge*3600000)+(Mnudge*60000))+start); // elapsed is the ajustable hour angle in milliseconds = Right Ascension + Hour set + Minute Set + Elapsed Time D=int(elapsed/86164091); // = 23 hrs 56 mins 4 seconds = Sidereal day over=elapsed%86164091; // +1 Sidereal day LSTH=int(elapsed/3600000); // = 60 minutes over=elapsed%3600000; // + 1 hour LSTM=int(over/60000); // = 60 seconds over=over%60000; // + 1 Minute LSTS=int(over/1000); // = 1000 ms ms=over%1000; Serial.print("H = " ); Serial.print(LSTH); Serial.print("\t M= "); Serial.print(LSTM); Serial.print("\t S= "); Serial.print(LSTS); } /* --(end main loop )-- */ /* ( THE END ) */
So, the bulk of this has been covered in my post on calculating the Hour Angle, however this also incorporates the Right Ascension motor control, with a temporary output to a Serial.print so I can see if it is working without hooking up an LCD display.
I am using an additional library which you will need if you want to use or modify my work:
Alexander Brevig's excellent Button.h library; http://playground.arduino.cc/Code/Button makes writing button/switch etc. dependant functions really simple and clear, he also has some good additional latching features which I have recently used in other little projects I am working on.
So, as mentioned the additional code is for controlling the Right Ascension stepper motor, currently in 3 distinct ways - Following a comment on my Stargazer Lounge Thread for this project I am also looking at allowing variable speed on the slew function, but for now this is where I am:
Button RAscCW = Button(A0,PULLUP); //create a Button object for the Right Ascension Clockwise switch @ pin A0 Button RAscCCW = Button(A1,PULLUP); //create a Button object for Right Ascension Anti-Clockwise switch @ pin A1
if(RAscCW.isPressed()) // Right Ascension Clockwise Slew { RA_stepper.setSpeed(900); // speed RA_stepper.step(50); // step value per cycle - too high == lack of sensitivity / too low == poor slew rate/stutter Stepcount +=50; // stepcount must equal step value per cycle. }
Where if the clockwise Button is pressed the stepper motor will rotate clockwise at 900 steps per second (faster than previously cited, I have been fiddling). Although the rate is 900 steps per second it will only move 50 steps at a time as denoted by "RA_stepper.step (50), this means that if you let go of the button the motor will stop after 50 steps, if this is higher the motor will continue to move long after releasing the button.
if(RAscCCW.isPressed()) { RA_stepper.setSpeed(900); // speed RA_stepper.step(-50); // step value per cycle - too high == lack of sensitivity / too low == poor slew rate/stutter Stepcount -=50; // stepcount must equal step value per cycle. }
This is the next "if" function, basically the same slewing motion but anti-clockwise.
else { RA_stepper.setSpeed(300); // Adjust to equal 0.2507 Degrees of Right Ascension per minute RA_stepper.step(1); // step value per cycle - too high == lack of sensitivity / too low == poor slew rate/stutter Stepcount ++; // stepcount must equal step value per cycle. }
Here we see an "else" statement, whereby if neither slew button is pressed the system will automatically track on the right ascension.
You may have noticed each of the above functions has "Stepcount xxxx" this an incrementing function which is equal to the number of steps made per function cycle. This is how the program knows the number of steps taken and therefore the position of the mount, more detail of that is explained in my first programming post.
No comments:
Post a Comment