Jump to content

NLCbanner2024.jpg.2478be509670e60c2d6efd04834b8b47.jpg

Juju

New Members
  • Posts

    3
  • Joined

  • Last visited

Posts posted by Juju

  1. 9 minutes ago, vlaiv said:

    That code style is not the best for what you are trying to achieve.

    Don't use pauses that you don't precisely control - use active loop for good precision (this will drain more power but you want as "real time" as possible).

    Here is pseudo code for something like this:

    while not done:
      if current_time>=time_of_next_event:
        perform_next_event // like make step forward or step backward
        time_of_next_event = calculate_time_of_next_event(current_time, time_of_next_event)
      else:
        // here you can do microsleep if you want to save power or just do nothing and resume next step in iteration

    As for timing - it is simple.

    Sidereal rate is 15.043"/s

    You need to calculate how many micro steps you have per revolution.

    For example - let's say that your worm gear is 180:1 and that you are using standard stepper with 1.8 degrees step (200 steps per revolution) and you have 32 micro steps.

    One full revolution will have in that case 180 * 200 * 32 = 1152000 steps

    One full revolution, on the other hand has 360 * 60 * 60 = 1296000 arc seconds.

    If you divide these two numbers - you will get arc seconds per step 1296000/1152000 = 1.125 arc seconds per step

    Now we have 15.043"/s and 1.125"/step we can then divide those two to give us timing information

    15.043 / 1.125 = 13.371555.... steps per second or

    1.125 / 15.043 = ~0.0747856s per step or 74.7856 milliseconds per step or 74785.6 microseconds per step

    In above pseudo code you would then put

    time_of_next_event = time_of_this_event + 0.0747856s

    I am a complete beginner in python, to further learn on the style of coding you mentioned i would just need to research active loops? and thank you for explaining the calculation

  2. As this is my first post I'm not sure how exactly to word this.

    I started a project where i am trying to create a DIY RA Drive instead of buying a commercial one, I have successfully created a bracket and my wiring is all completed and works fine, however this may seem ridicule but I don't know how to match the rotation of the stepper to the earths rotation, in other words I am not sure on how to calculate the delay in which I need to send a signal for pulses.

    Below is the code i am using.

    i have up to 32 micro steps and am using python on a raspberry pi 3+.

    I have seen many people complete this project but all guides have been using Arduinos.

    Below is my code, could someone be so kind as to explain how i would go about the above problem? many thanks

    As said above the code and hardware works fine it is just the steps and how to match earths rotation i do not understand.

     

    from time import sleep
    import RPi.GPIO as GPIO
    from tkinter import *
    from tkinter import messagebox
    #
    PUL = 17  # Stepper Drive Pulses
    DIR = 27  # Controller Direction Bit (High for Controller default / LOW to Force a Direction Change).
    ENA = 22  # Controller Enable Bit (High to Enable / LOW to Disable).
    channel = 2 #Relay GPIO is set as channel
    GPIO.setmode(GPIO.BCM)
    #
    GPIO.setup(PUL, GPIO.OUT)
    GPIO.setup(DIR, GPIO.OUT)
    GPIO.setup(ENA, GPIO.OUT)
    GPIO.setup(channel, GPIO.OUT) #Relay GPIO Set up

    durationFwd = 1000
    delay = 0.05 # This is actualy a delay between PUL pulses - effectively sets the mtor rotation speed.
    print('Speed set to ' + str(delay))

    def Relay_on():
        GPIO.output(2, GPIO.LOW)  # Turn motor on

    def Relay_off():
        GPIO.output(2, GPIO.HIGH)  # Turn motor off

    def Exit():
        GPIO.cleanup()
        exit()
       
    def forward():
        GPIO.output(ENA, GPIO.HIGH)
       
        print('ENA set to HIGH - Controller Enabled')
        #
        sleep(.1) # pause due to a possible change direction
        GPIO.output(DIR, GPIO.LOW)
       
        print('DIR set to LOW - Moving Forward at ' + str(delay))
        print('Controller PUL being driven.')
        for x in range(durationFwd):
            GPIO.output(PUL, GPIO.HIGH)
            sleep(delay)
            GPIO.output(PUL, GPIO.LOW)
            sleep(delay)
        GPIO.output(ENA, GPIO.LOW)
        return
       
    tk = Tk()
    tk.geometry("400x300")
    b1 = Button(tk, text="Relay On", command=Relay_on).place(x=100, y=50)
    b2 = Button(tk, text="Relay Off", command=Relay_off).place(x=100, y=100)
    b3 = Button(tk, text="Exit", command=Exit).place(x=100, y=200)
    b4 = Button(tk, text="Forward", command=forward).place(x=100, y=150)
    tk.mainloop()

    GPIO.cleanup()
    #

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.