0

I am having a bit of trouble using the PIGPIO wavechain function. I am using wavechain to accelerate and decelerate the stepper motor(NEMA 17 ,A4988 driver).Is it possible to avoid executing the pulse and wavechain calculation loops everytime the wavechain is tranmitted. The acceleration/deccelration ramp signals are constant. So if its possible to store the wavechain values then the delay could be cutshort significantly.`

I have added the code here. Is it possible to return the chain from the generate_ramp function,so that it can be used with pi.wave_chain and other parts of the code whenever required

import time
import pigpio

def generate_ramp(GPIO, ramp):
   l = len(ramp)
   wid=[-1] * l
   pi.set_mode(GPIO, pigpio.OUTPUT)

   # generate a wave per frequency

   for i in range(l):
      f = ramp[i][0]
      micros = int(500000/f)
      wf=[]
      wf.append(pigpio.pulse(1<<GPIO, 0,       micros))
      wf.append(pigpio.pulse(0,       1<<GPIO, micros))
      pi.wave_add_generic(wf)
      wid[i] = pi.wave_create()

   # generate a chain of waves

   chain = []

   for i in range(l):
      steps = ramp[i][1]
      x = steps & 255
      y = steps >> 8
      chain += [255, 0, wid[i], 255, 1, x, y]

   print(chain)

   pi.wave_chain(chain) # Transmit chain.

   while pi.wave_tx_busy(): # While transmitting.
      time.sleep(0.1)

   # delete all waves
   for i in range(l):
      pi.wave_delete(wid[i])

pi = pigpio.pi()

if not pi.connected:
   exit(0)

generate_ramp(4, [[5000, 1000], [10000, 2000], [20000, 20000], [1000,13], [500,3]])

pi.stop()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.