示例#1
0
    def api_softpwm(self, pin, command, option, req_method, req_args):
        resp = copy.deepcopy(self.CHIP_INFO)
        resp["connected"] = True

        # Figure out our command
        if command == "start" and req_method == 'GET':
            # Get the arguments
            duty_cycle = req_args.get('duty_cycle', 25.0)
            frequency = req_args.get('frequency', 35.0)
            polarity = req_args.get('polarity', 0)
            # Start the SoftPWM
            SPWM.start(pin, duty_cycle, frequency, polarity)
            resp[
                "message"] = "Setting {0} to duty cycle: {1}, frequency: {2}, and polarity {3}".format(
                    pin, duty_cycle, frequency, polarity)
        elif command == "stop" and req_method == 'GET':
            SPWM.stop(pin)
            resp["message"] = "Stopping {0}".format(pin)
        elif command == "cleanup" and req_method == 'GET':
            SPWM.cleanup(pin)
            resp["message"] = "Cleaning up {0}".format(pin)
        elif command == "duty_cycle" and req_method in ['GET', 'PUT', 'POST']:
            SPWM.set_duty_cycle(pin, float(option))
            resp["message"] = "Changing duty cycle on {0} to {1}".format(
                pin, option)
        elif command == "frequency" and req_method in ['GET', 'PUT', 'POST']:
            SPWM.set_frequency(pin, float(option))
            resp["message"] = "Changing duty cycle on {0} to {1}".format(
                pin, option)
        return jsonify(resp)
示例#2
0
def setup():
	#PWM.start(channel, duty, freq=2000, polarity=0)
	#duty values are valid 0 (off) to 100 (on)
	GPIO.setup(pin_forward, GPIO.OUT)
	GPIO.setup(pin_back, GPIO.OUT)
	PWM.start(pin_pwm, 0, 800, 0)
	motorStop()
示例#3
0
 def test_start_pwm(self):
     PWM.start("XIO-P7", 50, 10)
     base = GPIO.get_gpio_base() + 7
     gfile = '/sys/class/gpio/gpio%d' % base
     assert os.path.exists(gfile)
     direction = open(gfile + '/direction').read()
     assert(direction == 'out\n')
     PWM.cleanup()
示例#4
0
 def __init__(self, pin, freq=500, duty_min=49.0, duty_max=90.0, stop_on_zero=False):
     self.pin = pin
     self.freq = freq
     self.duty_min = duty_min
     self.duty_max = duty_max
     self.stop_on_zero = stop_on_zero
     sleep(0.1)
     PWM.start(pin, 0, 500)
 def test_start_pwm(self):
     PWM.start("XIO-P7", 50, 10)
     base = GPIO.get_gpio_base() + 7
     gfile = '/sys/class/gpio/gpio%d' % base
     assert os.path.exists(gfile)
     direction = open(gfile + '/direction').read()
     assert(direction == 'out\n')
     PWM.cleanup()
示例#6
0
 def __init__(self,
              pin,
              freq=50,
              duty_min=5,
              duty_max=10,
              stop_on_zero=False):
     self.pin = pin
     self.freq = freq
     self.duty_min = duty_min
     self.duty_max = duty_max
     self.stop_on_zero = stop_on_zero
     sleep(0.1)
     PWM.start(pin, 0, freq)
示例#7
0
    def setup(self):
        if not self.initialized:
            # reset gpio
            GPIO.cleanup(self.led)

            # init gpio
            pwm.start(self.led, 0, self.freq)
            self.currenta_angle = 0

            self.delta = self.max_value - self.min_value
            self.angle_increment = (self.update_delay *
                                    180) / (self.sweep_time * 60)

            self.initialized = True
示例#8
0
    def setup(self):
        if not self.initialized:
            # reset gpio
            GPIO.cleanup(self.red)
            GPIO.cleanup(self.yellow)

            # init gpio
            pwm.start(self.red, 0, self.freq)
            pwm.start(self.yellow, 0, self.freq)

            self.initialized = True

            # init variables
            self.red_sweeping = False
            self.red_sweep_increment = 0
            self.red_duty = 0
            self.red_target = 0

            self.yellow_ud_percent = 0
            self.yellow_cooldown = 0
示例#9
0
def steer_left():
    SPWM.start("CSID0", 50)
    SPWM.set_duty_cycle("CSID0", 0)
    SPWM.set_frequency("CSID0", freq)

    SPWM.start("CSID1", 50)
    SPWM.set_duty_cycle("CSID1", duty * 0.75)
    SPWM.set_frequency("CSID1", freq)

    SPWM.start("CSID2", 50)
    SPWM.set_duty_cycle("CSID2", 0)
    SPWM.set_frequency("CSID2", freq)

    SPWM.start("CSID3", 50)
    SPWM.set_duty_cycle("CSID3", duty)
    SPWM.set_frequency("CSID3", freq)
示例#10
0
def reverse():
    SPWM.start("CSID0", 50)
    SPWM.set_duty_cycle("CSID0", 0)
    SPWM.set_frequency("CSID0", freq)

    SPWM.start("CSID1", 50)
    SPWM.set_duty_cycle("CSID1", duty)
    SPWM.set_frequency("CSID1", freq)

    SPWM.start("CSID2", 50)
    SPWM.set_duty_cycle("CSID2", 0)
    SPWM.set_frequency("CSID2", freq)

    SPWM.start("CSID3", 50)
    SPWM.set_duty_cycle("CSID3", duty)
    SPWM.set_frequency("CSID3", freq)
示例#11
0
    def __init__(self):
        green = 'XIO-P0'
        blue = 'XIO-P1'
        red = 'XIO-P2'
        frequency = 100

        self.green = green
        self.red = red
        self.blue = blue

        GPIO.cleanup(red)
        GPIO.cleanup(green)
        GPIO.cleanup(blue)

        SPWM.start(red, 0)
        SPWM.set_frequency(red, frequency)
        SPWM.start(green, 0)
        SPWM.set_frequency(green, frequency)
        SPWM.start(blue, 0)
        SPWM.set_frequency(blue, frequency)
示例#12
0
 def test_pwm_start_invalid_frequency_negative(self):
     with pytest.raises(ValueError):
         PWM.start("XIO-P7", 0, -1)
示例#13
0
#!/usr/bin/python3

import sys, os, math, time
import CHIP_IO.SOFTPWM as PWM

i = 0
tsleep = 0.05
ttotal = 5
PWM.start("XIO-P4", 50, 100, 0)


def MachAnders(x):
    #print(x)
    PWM.set_duty_cycle("XIO-P4", x / 4)


if __name__ == "__main__":  # Programmstart
    try:
        while True:
            i = i + 1
            x = ttotal / tsleep
            x = ((math.sin(2 * math.pi * i / x) + 1) / 2) * 100
            if x == 0:
                x = 0.01
            #print(x)
            MachAnders(x)
            if i > (ttotal / tsleep):
                i = 0
            time.sleep(tsleep)

# Beim Abbruch durch STRG+C resetten
示例#14
0
 def test_pwm_duty_cycle_invalid_value_string(self):
     PWM.start("XIO-P7", 0)
     with pytest.raises(TypeError):
         PWM.set_duty_cycle("XIO-P7", "a")
         PWM.cleanup()
示例#15
0
 def test_pwm_start_invalid_polarity_type(self):
     with pytest.raises(TypeError):
         PWM.start("XIO-P7", 0, 100, "1")
示例#16
0
    SPWMGPIO = "XIO-P7"
    RECEIVERGPIO = "CSID0"
    COUNT = 200
    SLEEPTIME = 0.01

    # CLEANUP THE GPIO
    GPIO.cleanup()
    SPWM.cleanup()

    # ISSUE #16 VERIFICATION
    try:
        print(
            "VERIFYING FIX FOR ISSUE #16, GPIO CONFIGURED THAT SPWM WANTS TO USE"
        )
        GPIO.setup(SPWMGPIO, GPIO.OUT)
        SPWM.start(SPWMGPIO, 50, 1)
    except Exception as e:
        print("EXCEPTION: {}".format(e))
        print("GPIO CLEANUP")
        GPIO.cleanup()

    # SETUP SOFTPWM
    print("STARTING SOFTPWM TEST")
    SPWM.start(SPWMGPIO, 50, 1)
    SPWM.set_frequency(SPWMGPIO, 2)

    # SETUP SOFTPWM RECEIVER
    rcvr = SPWMReceiver(GPIO, RECEIVERGPIO, COUNT, SLEEPTIME)
    rcvr.start()

    time.sleep(COUNT * SLEEPTIME + 1)
示例#17
0
 def test_pwm_start_invalid_duty_cycle_negative(self):
     with pytest.raises(ValueError):
         PWM.start("XIO-P7", -1)
示例#18
0
# Set which GPIO pins the drive outputs are connected to
drive_0 = "GPIO6"
drive_1 = "GPIO4"
drive_2 = "GPIO2"
drive_3 = "XIO-P1"
PWM_0 = "LCD-VSYNC"
PWM_1 = "LCD-HSYNC"

# Set all of the drive pins as output pins
GPIO.setup(drive_0, GPIO.OUT)
GPIO.setup(drive_1, GPIO.OUT)
GPIO.setup(drive_2, GPIO.OUT)
GPIO.setup(drive_3, GPIO.OUT)

# SoftPWM setup
SPWM.start(PWM_0, 50)
SPWM.start(PWM_1, 50)

# Settings
leftdrive = drive_0  # drive number for left motor
rightdrive = drive_3  # drive number for right motor
leftback = drive_1  # drive number for left motor, backwards
rightback = drive_2  # drive number for right motor, backwards
axisleftmotor = 1  # Joystick axis to read for up / down position
axisleftmotorinverted = True  # Set this to True if up and down appear to be swapped
axisrightmotor = 3  # Joystick axis to read for left / right position
axisrightmotorinverted = True  # Set this to True if left and right appear to be swapped
interval = 0.05  # Time between keyboard updates in seconds, smaller responds faster but uses more processor time

drive0 = rightdrive
drive1 = leftdrive
示例#19
0
 def test_pwm_frequency_invalid_value_negative(self):
     PWM.start("XIO-P7", 0)
     with pytest.raises(ValueError):
         PWM.set_frequency("XIO-P7", -1)
         PWM.cleanup()
示例#20
0
 def test_pwm_duty_cycle_invalid_value_negative(self):
     PWM.start("XIO-P7", 0)
     with pytest.raises(ValueError):
         PWM.set_duty_cycle("XIO-P7", -1)
         PWM.cleanup()
示例#21
0
 def test_pwm_start_invalid_positive_polarity(self):
     with pytest.raises(ValueError):
         PWM.start("XIO-P7", 0, 100, 2)
示例#22
0
 def test_pwm_start_invalid_frequency_string(self):
     with pytest.raises(TypeError):
         PWM.start("XIO-P7", 0, "1")
示例#23
0
import CHIP_IO.SOFTPWM as SPWM
import CHIP_IO.GPIO as GPIO

#GPIO.toggle_debug()
#SPWM.toggle_debug()

# Defining PocketCHIP IO pins
left = "XIO-P6"
right = "XIO-P7"
en_l_fw = "LCD-D3"
en_l_bw = "LCD-D4"
en_r_fw = "LCD-D5"
en_r_bw = "LCD-D6"

# # Initializing IO pins
SPWM.start(left, 0)
SPWM.start(right, 0)
GPIO.setup(en_l_fw, GPIO.OUT)
GPIO.setup(en_l_bw, GPIO.OUT)
GPIO.setup(en_r_fw, GPIO.OUT)
GPIO.setup(en_r_bw, GPIO.OUT)

# #Used for calculating
L_mag = 0
R_mag = 0


# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
    print("Connected with result code " + str(rc))
示例#24
0
def init_pins():
    SPWM.start("CSID0", 0, 100)
    SPWM.start("CSID1", 0, 100)
    SPWM.start("CSID2", 0, 100)
    SPWM.start("CSID3", 0, 100)
    SPWM.start("CSID4", 0, 100)
    SPWM.start("CSID5", 0, 100)
 def test_start_pwm(self):
     PWM.start("XIO-P7", 50, 10)
     assert os.path.exists('/sys/class/gpio/gpio415')
     direction = open('/sys/class/gpio/gpio415/direction').read()
     assert direction == 'out\n'
     PWM.cleanup()
示例#26
0
 def test_pwm_start_negative_polarity(self):
     with pytest.raises(ValueError):
         PWM.start("XIO-P7", 0, 100, -1)
示例#27
0
文件: pwm_test.py 项目: m-long/chip
import CHIP_IO.GPIO as GPIO
import CHIP_IO.SOFTPWM as SPWM
import time

# Setup the pins
GPIO.setup("XIO-P0", GPIO.OUT)
GPIO.setup("XIO-P1", GPIO.OUT)
SPWM.start("XIO-P7", 100, 100, 0)

# Run the test
try:
    GPIO.output("XIO-P0", GPIO.HIGH)
    GPIO.output("XIO-P1", GPIO.LOW)

    print("Testing duty cycle...")

    # Test duty cycle
    #    for x in range(0,100):
    #        SPWM.set_duty_cycle("XIO-P7", x)
    #        print(x)
    #        time.sleep(.1)

    # Test frequency
    SPWM.set_duty_cycle("XIO-P7", 50)
    print("Testing frequency at 50% duty")
    for f in range(100, 5000, 100):
        SPWM.set_frequency("XIO-P7", f)
        print(f)
        time.sleep(.1)

    # Hold at high 50%
示例#28
0
 def test_pwm_start_invalid_polarity_type(self):
     with pytest.raises(TypeError):
         PWM.start("XIO-P7", 0, 100, "1")
示例#29
0
 def test_pwm_frequency_invalid_value_string(self):
     PWM.start("XIO-P7", 0)
     with pytest.raises(TypeError):
         PWM.set_frequency("XIO-P7", "11")
         PWM.cleanup()
示例#30
0
 def test_pwm_duty_cycle_invalid_value_string(self):
     PWM.start("XIO-P7", 0)
     with pytest.raises(TypeError):
         PWM.set_duty_cycle("XIO-P7", "a")
         PWM.cleanup()
示例#31
0
 def test_pwm_start_invalid_duty_cycle_high(self):
     with pytest.raises(ValueError):
         PWM.start("XIO-P7", 101)
示例#32
0
 def test_pwm_frequency_invalid_value_string(self):
     PWM.start("XIO-P7", 0)
     with pytest.raises(TypeError):
         PWM.set_frequency("XIO-P7", "11")
         PWM.cleanup()
示例#33
0
 def test_pwm_start_invalid_frequency_negative(self):
     with pytest.raises(ValueError):
         PWM.start("XIO-P7", 0, -1)
示例#34
0
 def test_pwm_start_invalid_pwm_key(self):
     with pytest.raises(ValueError):
         PWM.start("P8_25", -1)
示例#35
0
 def test_pwm_start_negative_polarity(self):
     with pytest.raises(ValueError):
         PWM.start("XIO-P7", 0, 100, -1)
示例#36
0
 def test_pwm_start_valid_duty_cycle_max(self):
     # testing an exception isn't thrown
     PWM.start("XIO-P7", 100)
     PWM.cleanup()
示例#37
0
import datetime

if __name__ == "__main__":
    # SETUP VARIABLES
    PWMGPIO = "XIO-P7"
    #PWMGPIO = "LCD-D4"
    COUNT = 150
    SLEEPTIME = 0.01

    time.sleep(1)

    # SETUP PWM
    try:
        print("PWM START")
        #PWM.toggle_debug()
        PWM.start(PWMGPIO, 50, 45, 1)

        # UNCOMMENT FOR CRASH
        print("PWM SET FREQUENCY")
        PWM.set_frequency(PWMGPIO, 10)

        # UNCOMMENT FOR CRASH
        print("PWM SET DUTY CYCLE")
        PWM.set_duty_cycle(PWMGPIO, 25)

        #time.sleep(COUNT*SLEEPTIME + 1)
        raw_input("PRESS ENTER WHEN DONE")

    except:
        raise
    finally:
示例#38
0
 def test_pwm_start_invalid_duty_cycle_string(self):
     with pytest.raises(TypeError):
         PWM.start("XIO-P7", "1")
示例#39
0
 def test_pwm_start_invalid_pwm_key(self):
     with pytest.raises(ValueError):
         PWM.start("P8_25", -1)
示例#40
0
 def test_pwm_start_invalid_frequency_string(self):
     with pytest.raises(TypeError):
         PWM.start("XIO-P7", 0, "1")
示例#41
0
 def test_pwm_start_invalid_duty_cycle_negative(self):
     with pytest.raises(ValueError):
         PWM.start("XIO-P7", -1)
示例#42
0
 def test_pwm_start_invalid_positive_polarity(self):
     with pytest.raises(ValueError):
         PWM.start("XIO-P7", 0, 100, 2)
示例#43
0
 def test_pwm_start_valid_duty_cycle_max(self):
     # testing an exception isn't thrown
     PWM.start("XIO-P7", 100)
     PWM.cleanup()
示例#44
0
 def test_pwm_duty_cycle_invalid_value_negative(self):
     PWM.start("XIO-P7", 0)
     with pytest.raises(ValueError):
         PWM.set_duty_cycle("XIO-P7", -1)
         PWM.cleanup()
示例#45
0
 def test_pwm_start_invalid_duty_cycle_high(self):
     with pytest.raises(ValueError):
         PWM.start("XIO-P7", 101)
示例#46
0
 def test_pwm_frequency_invalid_value_negative(self):
     PWM.start("XIO-P7", 0)
     with pytest.raises(ValueError):
         PWM.set_frequency("XIO-P7", -1)
         PWM.cleanup()
示例#47
0
 def test_pwm_start_invalid_duty_cycle_string(self):
     with pytest.raises(TypeError):
         PWM.start("XIO-P7", "1")