Beispiel #1
0
 def __init__(self, addr=0x60, freq=1600):
     self._i2caddr = addr  # default addr on HAT
     self._frequency = freq  # default @1600Hz PWM freq
     self.motors = [Raspi_DCMotor(self, m) for m in range(4)]
     self.steppers = [
         Raspi_StepperMotor(self, 1),
         Raspi_StepperMotor(self, 2)
     ]
     self._pwm = PWM(addr, debug=False)
     self._pwm.setPWMFreq(self._frequency)
Beispiel #2
0
    def __init__(self, addr=0x6f, deflect_90_in_ms=0.9):
        self._pwm = PWM(addr)
        pwm_freqeuncy = 60  # this sets the timebase for the motorhat
        self._pwm.setPWMFreq(pwm_freqeuncy)

        #Frequency is 1/period, but working in ms, we can use 1000
        period_in_ms = 1000.0 / pwm_freqeuncy
        #the chip has 4096 steps in each period.
        pulse_steps = 4096.0
        # mid point of the servo pulse length in milliseconds
        servo_mid_point_ms = 1.6
        # steps for every milisecond
        steps_per_ms = pulse_steps / period_in_ms
        # steps for a degree
        self.steps_per_degree = (deflect_90_in_ms * steps_per_ms) / 90.0
        # Mid point of the Servo in steps
        self.servo_mid_point_steps = servo_mid_point_ms * steps_per_ms
Beispiel #3
0
    def __init__(self, addr=0x6f, deflect_90_in_ms = 1.15):
        """addr: The i2c address of the PWM chip.
        deflect_90_in_ms: set this to calibrate the servo motors. It is what a deflection of 90 degrees is in turns of a pulse length in milliseconds.
        """
        # deflect_90_in_ms - set this to calibrate the servo motors.
        self._pwm = PWM(addr)
        pwm_frequency = 60
        self._pwm.setPWMFreq(pwm_frequency)

        period_in_ms = 1000 / pwm_frequency

        pulse_steps = 4096.0

        servo_mid_point_ms = 1.5

        # Steps for every millisecond
        steps_per_ms = pulse_steps / period_in_ms

        self.steps_per_degree = (deflect_90_in_ms * steps_per_ms) / 90.0

        # Mid  point of the servo in steps
        self.servo_mid_point_steps = servo_mid_point_ms * steps_per_ms
Beispiel #4
0
    def __init__(self, addr=0x6f, deflect_90_in_ms = 0.5):
        """addr: The i2c address of the PWM chip.
        deflect_90_in_ms: set this to calibrate the servo motors. 
                          it is what a deflection of 90 degrees is
                          in terms of a pulse length in milliseconds."""
        self._pwm = PWM(addr)
        # This sets the timebase for it all
        pwm_frequency = 100
        self._pwm.setPWMFreq(pwm_frequency)
        # Mid-point of the servo pulse length in milliseconds.
        servo_mid_point_ms = 1.5
        # Frequency is 1/period, but working ms, we can use 1000
        period_in_ms = 1000 / pwm_frequency
        # The chip has 4096 steps in each period.
        pulse_steps = 4096
        # Steps for every millisecond.
        steps_per_ms = pulse_steps / period_in_ms
        # Steps for a degree
        self.steps_per_degree = (deflect_90_in_ms * steps_per_ms) / 90
        # Mid-point of the servo in steps
        self.servo_mid_point_steps = servo_mid_point_ms * steps_per_ms

        # Map for channels
        self.channels = [0, 1, 14, 15]
from Raspi_MotorHAT.Raspi_PWM_Servo_Driver import PWM
import atexit

pwm = PWM(0x6f)
pwm_frequency = 60
pwm.setPWMFreq(pwm_frequency)

#Frequency is 1/period, but working ms, we can use 1000
period_in_ms = 1000 / pwm_frequency

# The chip has 4096 steps in each period
pulse_steps = 4096.0

# Mid point of the servo pulse length in milliseconds
servo_mid_point_ms = 1.5

# What a deflection of 90 degrees is in pulse length in milliseconds
deflect_90_in_ms = 1.15

# Steps for every millisecond
steps_per_ms = pulse_steps / period_in_ms

# Steps for a degree
steps_per_degree = (deflect_90_in_ms * steps_per_ms) / 90.0

# Mid  point of the servo in steps
servo_mid_point_steps = servo_mid_point_ms * steps_per_ms


def convert_degrees_to_pwm(position):
    return int(servo_mid_point_steps + (position * steps_per_degree))
#!/usr/bin/python
from __future__ import print_function, absolute_import
from Raspi_MotorHAT.Raspi_PWM_Servo_Driver import PWM
import time

# ===========================================================================
# Example Code
# ===========================================================================

# Initialise the PWM device using the default address
# bmp = PWM(0x40, debug=True)
pwm = PWM(0x6F)

servoMin = 150  # Min pulse length out of 4096
servoMax = 600  # Max pulse length out of 4096


def setServoPulse(channel, pulse):
    pulseLength = 1000000  # 1,000,000 us per second
    pulseLength //= 60  # 60 Hz
    print("%d us per period" % pulseLength)
    pulseLength //= 4096  # 12 bits of resolution
    print("%d us per bit" % pulseLength)
    pulse *= 1000
    pulse //= pulseLength
    pwm.setPWM(channel, 0, pulse)


pwm.setPWMFreq(60)  # Set frequency to 60 Hz
while (True):
    # Change speed of continuous servo on channel O