예제 #1
0
#Author: [email protected]
#control feeder servo, if you are using a stepper motor this script is easy to modify
# the commands are 'full' - 90 deg open, 'half' - 45 deg open, 'quick' - short delay time , 'close' and 'quit'
import RPi.GPIO as GPIO
from RpiMotorLib import rpiservolib
import time
servoPin = 17
servoStart = 1
movePull = 7
holdTime = 0.4
servoDelay = 0.3
feeder_servo = rpiservolib.SG90servo("feeder")
feeder_servo.servo_move(servoPin, servoStart)

move = ''
while True:
    move = input()
    if move == 'full':
        feeder_servo.servo_move(servoPin, movePull, servoDelay)
        time.sleep(holdTime)
        feeder_servo.servo_move(servoPin, servoStart, servoDelay)
    elif move == 'half':
        feeder_servo.servo_move(servoPin, 3.6, servoDelay)
        time.sleep(holdTime)
        feeder_servo.servo_move(servoPin, servoStart, servoDelay)
    elif move == 'quick':
        feeder_servo.servo_move(servoPin, movePull, servoDelay)
        feeder_servo.servo_move(servoPin, servoStart, servoDelay)
    elif move == 'open':
        feeder_servo.servo_move(servoPin, movePull, servoDelay)
예제 #2
0
def testmove(degr):
    myservotest = rpiservolib.SG90servo("servoone")
    #motor = SG90servo.__init__("servoone")
    #dutycycle = myservotest.convert_from_degree(myservotest, degr)
    myservotest.servo_move(myservotest, 12, myservotest.convert_from_degree(myservotest, degr)) # using pin 12
예제 #3
0
def main():
    """main function loop"""

    # ===== Tests for servo  ==========

    #  initialize (name, freq, y_one, y_two)
    myservotest  = rpiservolib.SG90servo("servoone", 50, 3, 11)
    
    # Comment in To Test servo stop 
    # GPIO.add_event_detect(17, GPIO.RISING, callback=button_callback)
    
    # == Test 1 test method servo_move_step  ==

    # (servo_pin, start, end, stepdelay,stepsize, initdelay, verbose)
    print("Test 1: test method servo_move_step")
    input("Press <Enter> to continue Test 1a")
    myservotest.servo_move_step(26, 10, 180, .1, 5, 1, True)
    time.sleep(1)
    input("Press <Enter> to continue Test 1b")
    myservotest.servo_move_step(26, 170, 10, .5, 20, 1, True)
    time.sleep(1)
    input("Press <Enter> to continue Test 1c")
    myservotest.servo_move_step(26, 10, 50, 1, 1, 1, True)
    time.sleep(1)

    # == Test 2 convert function ==
    
    print("Test 2: test method covert degree to duty cycle function")
    input("Press <Enter> to continue Test2")
    testdegree = float(input("What degree do you want?\t"))
    print("duty cycle percent = {} ".format(myservotest.convert_from_degree(testdegree)))

    # == Test 3  test method servo_sweep ==

    # (servo_pin, center, minduty, maxduty, delay, verbose, initdelay, sweeplen)
    print("Test 3: test method servo_sweep")
    input("Press <Enter> to continue Test 3a")
    time.sleep(1)
    myservotest.servo_sweep(26, 7.5, 3, 11, .5, True, .05, 10)
    # sweep from center to max
    input("Press <Enter> to continue Test 3b")
    time.sleep(1)
    myservotest.servo_sweep(26, 7.5, 7.5, 11, .5, True, 2, 20)
    # sweep from center to min
    input("Press <Enter> to continue Test 3c")
    time.sleep(1)
    myservotest.servo_sweep(26, 7.5, 7.5, 3, .5, True, .05)

    # == Test 3  test method servo_move ==

    # servo_pin, position, delay, verbose, initdelay):
    print("test 4 test method servo_move")
    input("Press <Enter> to continue Test4a")
    time.sleep(1)
    myservotest.servo_move(26, 12, .5, True, 0)
    input("Press <Enter> to continue Test4b")
    time.sleep(1)
    myservotest.servo_move(26, 2, .5, True, 0)
    input("Press <Enter> to continue Test4c")
    time.sleep(1)
    myservotest.servo_move(26, 7.5, .5, True, 0)

    time.sleep(1)
예제 #4
0
def main():
    """main function loop"""

    # ===== tests for servo SG90 ==========
    # initialize
    #  name="SG90servoX", freq=50, y_one=2, y_two=12
    myservotest = rpiservolib.SG90servo("servoone", 50, 3, 11)

    # section 1
    # servo_pin, start=10, end=170, stepdelay=1,
    # stepsize=1, initdelay=1, verbose=False
    print("test 1 test method servo_move_step")
    input("Press <Enter> to continue Test1a")
    myservotest.servo_move_step(26, 10, 180, .1, 5, 1, True)
    time.sleep(1)
    input("Press <Enter> to continue Test1b")
    myservotest.servo_move_step(26, 170, 10, .5, 20, 1, True)
    time.sleep(1)
    input("Press <Enter> to continue Test1b")
    myservotest.servo_move_step(26, 10, 50, 1, 1, 1, True)
    time.sleep(1)

    # section 2
    # test convert function
    print("Test 2: test method covert degree to duty cycle function")
    input("Press <Enter> to continue Test2")
    testdegree = float(input("What degree do you want?\t"))
    print("duty cycle percent = {} ".format(
        myservotest.convert_from_degree(testdegree)))

    # section 3
    # servo_pin=7, center=7.5, minduty=3,
    # maxduty=11, delay=0.5, verbose=False, initdelay=.05, sweeplen=1000000
    print("test 3 test method servo_sweep")
    input("Press <Enter> to continue Test3a1")
    time.sleep(1)
    myservotest.servo_sweep(26, 7.5, 3, 11, .5, True, .05, 10)
    # sweep from center to max
    input("Press <Enter> to continue Test3a2")
    time.sleep(1)
    myservotest.servo_sweep(26, 7.5, 7.5, 11, .5, True, 2, 20)
    # sweep from center to min
    input("Press <Enter> to continue Test3a3")
    time.sleep(1)
    myservotest.servo_sweep(26, 7.5, 7.5, 3, .5, True, .05)

    # section 4
    # servo_pin, start=10, end=170, stepdelay=1,
    # stepsize=1, initdelay=1, verbose=False
    print("test 4 test method servo_move")
    input("Press <Enter> to continue Test4b1")
    time.sleep(1)
    myservotest.servo_move(26, 12, .5, True)
    input("Press <Enter> to continue Test4b2")
    time.sleep(1)
    myservotest.servo_move(26, 2, .5, True)
    input("Press <Enter> to continue Test4b3")
    time.sleep(1)
    myservotest.servo_move(26, 7.5, .5, True)

    time.sleep(1)
예제 #5
0
def catch_exceptions(cancel_on_failure=False):
  def catch_exceptions_decorator(job_func):
    @functools.wraps(job_func)
    def wrapper(*args, **kwargs):
      try:
        return job_func(*args, **kwargs)
      except:
        import traceback
        print(traceback.format_exc())
        if cancel_on_failure:
          return schedule.CancelJob
    return wrapper
  return catch_exceptions_decorator

# https://github.com/gavinlyonsrepo/RpiMotorLib/blob/master/Documentation/Servo_RPI_GPIO.md
myservotest  = rpiservolib.SG90servo("servoone", 50, 3, 11)
servoPIN = 17
servoStartDegrees = 10
degrees = 10
#logfile = "/var/log/flomlog.txt"

# Calculate with 110degrees as middle flood (440 M3s),
# The 50 years flood is then at 175 degree (691 M3s)
# Define the job:

@catch_exceptions(cancel_on_failure=True)
def job():
  global servoStartDegrees
  global degrees
  r = re.compile("verdi=\s*")
  response = urlopen('https://www2.nve.no/h/hd/plotreal/Q/0208.00003.000/')