def test_pwm_duty_modified(self):
        PWM.start("P9_14", 0)

        files = os.listdir('/sys/devices')
        ocp = '/sys/devices/'+[s for s in files if s.startswith('ocp')][0]
        files = os.listdir(ocp)
        pwm_test = ocp+'/'+[s for s in files if s.startswith('pwm_test_P9_14')][0]

        assert os.path.exists(pwm_test)
        duty = open(pwm_test + '/duty').read()
        period = open(pwm_test + '/period').read()
        assert int(duty) == 0
        assert int(period) == 500000

        PWM.set_duty_cycle("P9_14", 100)
        duty = open(pwm_test + '/duty').read()
        period = open(pwm_test + '/period').read()
        assert int(duty) == 500000
        assert int(period) == 500000        
        PWM.cleanup()
Пример #2
0
def convert(s):
    global last
    values = map(ord, s)
    output = ''
    #send servo commands to Arduino based on command string
    for x in range(1, 6):
        if values[8] == 250:
            output = 'FAILSAFE MODE!!!!!!!!!!!!!!!!!!!!!!!'
        elif values[8] == 125:
            arm_motors()
        else:
            if values[x] != last[x]:
                mapped = map_val(values[x], 0, 250, 5.0, 10.0)
                PWM.set_duty_cycle(pins[x], float(mapped))
                if x < 4:                      
                    output += ' | ' + str(mapped) + ','
                else:
                    output += ' | ' + str(mapped)
        output += str(values[x]) + ' | '
    print output
    last = s
 def test_pwm_duty_cycle_invalid_value_negative(self):
     PWM.start("P9_14", 0)
     with pytest.raises(ValueError):
         PWM.set_duty_cycle("P9_14", -1)
         PWM.cleanup()            
 def test_pwm_duty_cycle_invalid_key(self):
     with pytest.raises(ValueError):
         PWM.set_duty_cycle("P9_15", 100)
         PWM.cleanup()                  
 def test_pwm_duty_cycle_non_setup_key(self):
     with pytest.raises(RuntimeError):
         PWM.set_duty_cycle("P9_14", 100)
         PWM.cleanup()    
 def test_pwm_duty_cycle_invalid_value_string(self):
     PWM.start("P9_14", 0)
     with pytest.raises(TypeError):
         PWM.set_duty_cycle("P9_14", "a")
         PWM.cleanup()               
Пример #7
0
def arm_motors():
    PWM.set_duty_cycle(pins[1], 5)
    PWM.set_duty_cycle(pins[2], 10)
    PWM.set_duty_cycle(pins[3], 5)
    PWM.set_duty_cycle(pins[4], 10)