0

i want to control exactly how mush my servo rotate through DMA like pigpio with raspberry pi so i need to create exact number of pulses for servo . is there anyway to create exact number of pulses with DMA like pigpio or servoblaser ? by the way i am using a Delta Servo motor with its driver

closed as too broad by techraf, Aurora0001, Steve Robillard, Jacobm001 Feb 26 '18 at 2:56

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

0

You can use pigpio wave chains to send pulses a precise number of times.

However this is of no use for servos (unless yours has a special interface).

Hobby servos work in one of two ways.

  1. pulses are sent at 50Hz. The length of each pulse in microseconds (generally in the range 1000-2000) determine the servo horns target angle.
  2. pulses are sent at 50Hz. The length of each pulse in microseconds (generally in the range 1000-2000) determine the servo horns rotational speed.

The number of pulses sent in total is not relevant.


The following script shows how to use wave chains with Python.

#!/usr/bin/env python

import time
import pigpio

def tx_pulses(pi, GPIO, hertz, num, pulse_len=1):
   assert hertz < 500000
   length_us = int(1000000/hertz)
   assert int(pulse_len) < length_us
   assert num < 65536

   num_low = num % 256
   num_high = num // 256

   wf = []

   wf.append(pigpio.pulse(1<<GPIO, 0, pulse_len))
   wf.append(pigpio.pulse(0, 1<<GPIO, length_us - pulse_len))

   pi.wave_add_generic(wf)

   wid = pi.wave_create()

   if wid >= 0:
      pi.wave_chain([255, 0, wid, 255, 1, num_low, num_high])
      while pi.wave_tx_busy():
         time.sleep(0.01)
      pi.wave_delete(wid)

pi = pigpio.pi()
if not pi.connected:
   exit()

GPIO=19

pi.set_mode(GPIO, pigpio.OUTPUT)

tx_pulses(pi, GPIO, 100, 25) # 25 pulses @ 100 Hz

tx_pulses(pi, GPIO, 1000, 250) # 250 pulses @ 1000 Hz

tx_pulses(pi, GPIO, 5000, 2391, pulse_len=50) # 2391 pulses @ 5000 Hz

pi.stop()
  • 1
    thanks but i am using Delta Servo Motor an industrial servo . not Hobby servos .. for example i used your HP command line pigs commands throw terminal, and i see when i increase frequency i get more speed .. so it means more pulses : more speed . these servos have an driver .. and driver determine how much for a pulse servo rotate. – pooya Feb 14 '18 at 12:06
  • and by the way is there any example of using your wave chains function ? i couldn't understand how actually create one ... – pooya Feb 14 '18 at 12:09
  • 1
    Each of the C, pdif2, and Python documentation for the wave chain call contain an example. There may be other examples in abyz.me.uk/rpi/pigpio/examples.html but I'm not sure. – joan Feb 14 '18 at 12:45
  • I would look into the driver and see what it expects, usually they are driven with PWM (as explained in the answer), not number of pulses. Now if it is a stepper motor that moves a small fraction of a rotation with every pulse then more pulses would = more rotation/speed – Chad G Feb 14 '18 at 16:35
  • thanks Johan and Chad, (deltaww.com/Products/… ) this is link to know better what driver i am using. it actually respond to rising edge of electrical pulse . so i need exact number of pulse . in the driver we set driver setting . for example if i set in driver when 100 rising edge occurred then servo rotate 1 degree.. so i need exact number of pulses. if i have more frequency then servo rotates more quickly. – pooya Feb 14 '18 at 17:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.