Exemplo n.º 1
0
    def __init__(self, channel, shiftreg_nr, pulse_width_start, pulse_width_stop, init_angle, turnoff_timeout=0):
        """Define a new software controllable servo with adjustable speed control

        Keyword arguments:
        pulse_width_start -- The minimum pulse width defining the lowest angle
        pulse_width_stop -- The maximum pulse width defining the biggest angle
        init_angle -- Initial angle that the servo should take when it is powered on. Range is 0 to 180deg
        turnoff_timeout -- number of seconds after which the servo is turned off if no command is received. 0 = never turns off
        """

        self.pulse_width_start = pulse_width_start
        self.pulse_width_stop = pulse_width_stop
        self.turnoff_timeout = turnoff_timeout

        self.current_pulse_width = (init_angle*(self.pulse_width_stop-self.pulse_width_start)/180.0+self.pulse_width_start)
        self.last_pulse_width = self.current_pulse_width

        self.queue = JoinableQueue(1000)
        self.lastCommandTime = 0

        self.t = Thread(target=self._wait_for_event)
        self.t.daemon = True
        self.running = True
        self.t.start()

        self.pwm = PWM_pin(channel, 100, 0.1)

        # Set up the Shift register for enabling this servo
        ShiftRegister.make()
        self.shift_reg = ShiftRegister.registers[shiftreg_nr]
        self.set_enabled()
Exemplo n.º 2
0
  def __init__(self, step_pin, dir_pin, fault_key, dac_channel, shiftreg_nr, name):
    """ Init """
    self.dac_channel = dac_channel    # Which channel on the dac is connected to this stepper
    self.step_pin = step_pin
    self.dir_pin = dir_pin
    self.fault_key = fault_key
    self.name = name
    self.enabled = False
    self.in_use = False
    self.steps_pr_mm = 1
    self.microsteps = 1.0
    self.microstepping = 0
    self.direction = 1
    self.current_disabled = False

    # Set up the Shift register
    ShiftRegister.make(8)
    self.shift_reg = ShiftRegister.registers[shiftreg_nr]

    # Set up the GPIO pins - we just have to initialize them so the PRU can flip them
    # terrible hack to cover a bug in Adafruit
    dir_name = "EHRPWM2A" if dir_pin == "GPIO0_22" else dir_pin

    try:
      GPIO.setup(dir_name, GPIO.OUT)
      GPIO.setup(step_pin, GPIO.OUT)
    except ValueError:
      logging.warning("*** Stepper {} Pin {} initialization failure:".format(self.name, dir_name))

    # Add a key code to the key listener
    # Steppers have an nFAULT pin, so callback on falling
    Key_pin(name, fault_key, Key_pin.FALLING, self.fault_callback)
Exemplo n.º 3
0
    def __init__(self,
                 channel,
                 pulse_width_start,
                 pulse_width_stop,
                 init_angle,
                 turnoff_timeout=0):
        """Define a new software controllable servo with adjustable speed control

        Keyword arguments:
        pulse_width_start -- The minimum pulse width defining the lowest angle
        pulse_width_stop -- The maximum pulse width defining the biggest angle
        init_angle -- Initial angle that the servo should take when it is powered on. Range is 0 to 180deg
        turnoff_timeout -- number of seconds after which the servo is turned off if no command is received. 0 = never turns off
        """

        self.pulse_width_start = pulse_width_start
        self.pulse_width_stop = pulse_width_stop
        self.turnoff_timeout = turnoff_timeout

        self.current_pulse_width = init_angle * (
            self.pulse_width_stop -
            self.pulse_width_start) / 180.0 + self.pulse_width_start
        self.last_pulse_width = self.current_pulse_width

        self.queue = JoinableQueue(1000)
        self.lastCommandTime = 0

        self.t = Thread(target=self._wait_for_event)
        self.t.daemon = True
        self.running = True
        self.t.start()

        self.pwm = PWM_pin(channel, 100, self.current_pulse_width)

        # Set up the Shift register for enabling this servo
        if channel == "P9_14":
            shiftreg_nr = 3
        elif channel == "P9_16":
            shiftreg_nr = 2
        else:
            logging.warning(
                "Tried to assign servo to an unknown channel/pin: " +
                str(channel))
            return

        ShiftRegister.make()
        self.shift_reg = ShiftRegister.registers[shiftreg_nr]
        self.set_enabled()
Exemplo n.º 4
0
    def __init__(self, stepPin, dirPin, faultPin, dac_channel, shiftreg_nr, name, internalStepPin, internalDirPin):
        """ Init """
        self.dac_channel     = dac_channel  # Which channel on the dac is connected to this stepper
        self.stepPin         = stepPin
        self.dirPin          = dirPin
        self.faultPin        = faultPin
        self.name            = name
        self.enabled 	     = False	    
        self.in_use          = False        
        self.steps_pr_mm     = 1            
        self.microsteps      = 1.0          
        self.direction       = 1
        self.internalStepPin = (1 << internalStepPin)
        self.internalDirPin  = (1 << internalDirPin)

        # Set up the Shift register
        ShiftRegister.make()
        self.shift_reg = ShiftRegister.registers[shiftreg_nr]
Exemplo n.º 5
0
    def __init__(self, stepPin, dirPin, faultPin, dac_channel, shiftreg_nr,
                 name, internalStepPin, internalDirPin):
        """ Init """
        self.dac_channel = dac_channel  # Which channel on the dac is connected to this stepper
        self.stepPin = stepPin
        self.dirPin = dirPin
        self.faultPin = faultPin
        self.name = name
        self.enabled = False
        self.in_use = False
        self.steps_pr_mm = 1
        self.microsteps = 1.0
        self.direction = 1
        self.internalStepPin = (1 << internalStepPin)
        self.internalDirPin = (1 << internalDirPin)

        # Set up the Shift register
        ShiftRegister.make()
        self.shift_reg = ShiftRegister.registers[shiftreg_nr]
Exemplo n.º 6
0
    def __init__(self, step_pin, dir_pin, fault_key, dac_channel, shiftreg_nr, name):
        """ Init """
        self.dac_channel     = dac_channel  # Which channel on the dac is connected to this stepper
        self.step_pin        = step_pin
        self.dir_pin         = dir_pin
        self.fault_key       = fault_key
        self.name            = name
        self.enabled 	     = False	    
        self.in_use          = False        
        self.steps_pr_mm     = 1            
        self.microsteps      = 1.0     
        self.microstepping   = 0
        self.direction       = 1

        # Set up the Shift register
        ShiftRegister.make(8)
        self.shift_reg = ShiftRegister.registers[shiftreg_nr]

        # Add a key code to the key listener
        # Steppers have an nFAULT pin, so callback on falling
        Key_pin(name, fault_key, Key_pin.FALLING, self.fault_callback)
Exemplo n.º 7
0
    def __init__(self, step_pin, dir_pin, fault_key, dac_channel, shiftreg_nr,
                 name):
        """ Init """
        self.dac_channel = dac_channel  # Which channel on the dac is connected to this stepper
        self.step_pin = step_pin
        self.dir_pin = dir_pin
        self.fault_key = fault_key
        self.name = name
        self.enabled = False
        self.in_use = False
        self.steps_pr_mm = 1
        self.microsteps = 1.0
        self.microstepping = 0
        self.direction = 1

        # Set up the Shift register
        ShiftRegister.make(8)
        self.shift_reg = ShiftRegister.registers[shiftreg_nr]

        # Add a key code to the key listener
        # Steppers have an nFAULT pin, so callback on falling
        Key_pin(name, fault_key, Key_pin.FALLING, self.fault_callback)
Exemplo n.º 8
0
    def __init__(self,
                 channel,
                 pulse_width_min,
                 pulse_width_max,
                 angle_min,
                 angle_max,
                 init_angle,
                 turnoff_timeout=0):
        """Define a new software controllable servo with adjustable speed control

        Keyword arguments:
        pulse_width_min -- The minimum pulse width defining the lowest angle
        pulse_width_max -- The maximum pulse width defining the biggest angle
        init_angle -- Initial angle that the servo should take when it is powered on. Range is 0 to 180deg
        turnoff_timeout -- number of seconds after which the servo is turned off if no command is received. 0 = never turns off
        """

        self.angle_min = angle_min
        self.angle_max = angle_max
        self.angle_total = angle_max - angle_min
        self.pulse_width_min = pulse_width_min
        self.pulse_width_max = pulse_width_max
        self.pulse_width_total = pulse_width_max - pulse_width_min

        self.turnoff_timeout = turnoff_timeout

        self.current_pulse_width = self.angle_to_pulse_width(init_angle)
        self.last_pulse_width = self.current_pulse_width

        self.last_angle = init_angle

        self.pulse_length = 20.0 * 10.0**-3.0  # 20 ms

        logging.debug("Angle min: {} deg".format(self.angle_min))
        logging.debug("Angle max: {} deg".format(self.angle_max))
        logging.debug("Angle tot: {} deg".format(self.angle_total))
        logging.debug("Pulse min: {} ms".format(self.pulse_width_min * 1000.0))
        logging.debug("Pulse max: {} ms".format(self.pulse_width_max * 1000.0))
        logging.debug("Pulse tot: {} ms".format(self.pulse_width_total *
                                                1000.0))

        self.queue = JoinableQueue(1000)
        self.lastCommandTime = 0

        self.t = Thread(target=self._wait_for_event, name="Servo")
        self.t.daemon = True
        self.running = True
        self.t.start()

        # Branch based on channel type.

        if type(channel) == int:  # Revision A
            self.pwm = PWM(channel, 50, self.current_pulse_width)
        else:  # Revision B
            # Set up the Shift register for enabling this servo
            if channel == "P9_14":
                shiftreg_nr = 1
                self.pwm = PWM_pin(channel, 50, self.current_pulse_width)
            elif channel == "P9_16":
                shiftreg_nr = 2
                self.pwm = PWM_pin(channel, 50, self.current_pulse_width)
            else:
                logging.warning(
                    "Tried to assign servo to an unknown channel/pin: " +
                    str(channel))
                return

            ShiftRegister.make(5)
            self.shift_reg = ShiftRegister.registers[shiftreg_nr]
        self.set_enabled()
        self.pwm.set_value(
            self.angle_to_pulse_width(init_angle) / self.pulse_length)
Exemplo n.º 9
0
    def __init__(self, channel, pulse_width_min, pulse_width_max, angle_min, angle_max, init_angle, turnoff_timeout=0):
        """Define a new software controllable servo with adjustable speed control

        Keyword arguments:
        pulse_width_min -- The minimum pulse width defining the lowest angle
        pulse_width_max -- The maximum pulse width defining the biggest angle
        init_angle -- Initial angle that the servo should take when it is powered on. Range is 0 to 180deg
        turnoff_timeout -- number of seconds after which the servo is turned off if no command is received. 0 = never turns off
        """

        self.angle_min = angle_min
        self.angle_max = angle_max
        self.angle_total = angle_max-angle_min
        self.pulse_width_min = pulse_width_min
        self.pulse_width_max = pulse_width_max
        self.pulse_width_total = pulse_width_max-pulse_width_min
        
        self.turnoff_timeout = turnoff_timeout

        self.current_pulse_width = self.angle_to_pulse_width(init_angle)
        self.last_pulse_width = self.current_pulse_width

        self.last_angle = init_angle

        self.pulse_length = 20.0*10.0**-3.0 # 20 ms

        logging.debug("Angle min: {} deg".format(self.angle_min))
        logging.debug("Angle max: {} deg".format(self.angle_max))
        logging.debug("Angle tot: {} deg".format(self.angle_total))
        logging.debug("Pulse min: {} ms".format(self.pulse_width_min*1000.0))
        logging.debug("Pulse max: {} ms".format(self.pulse_width_max*1000.0))
        logging.debug("Pulse tot: {} ms".format(self.pulse_width_total*1000.0))

        self.queue = JoinableQueue(1000)
        self.lastCommandTime = 0

        self.t = Thread(target=self._wait_for_event)
        self.t.daemon = True
        self.running = True
        self.t.start()

        # Branch based on channel type.

        if type(channel) == int: # Revision A
            self.pwm = PWM(channel, 50, self.current_pulse_width)
        else: # Revision B
            # Set up the Shift register for enabling this servo
            if channel == "P9_14":
                shiftreg_nr = 1
                self.pwm = PWM_pin(channel, 50, self.current_pulse_width)
            elif channel == "P9_16":
                shiftreg_nr = 2
                self.pwm = PWM_pin(channel, 50, self.current_pulse_width)
            else:
                logging.warning("Tried to assign servo to an unknown channel/pin: "+str(channel))
                return        

            ShiftRegister.make(5)
            self.shift_reg = ShiftRegister.registers[shiftreg_nr]
        self.set_enabled()
        self.pwm.set_value(self.angle_to_pulse_width(init_angle)/self.pulse_length)