Example #1
1
import time

from api import Api
from motors import Servo, Motor
from remote import Remote

servo = Servo(port=1, min_pulse=750, max_pulse=2250, min_position=0.30, max_position=0.7)
motor = Motor(port=1, duty_cycle=0)

def wave(min=0.0, max=1.0, n=1, pause=0.4):
    for x in range(n):
        servo.set(min)
        time.sleep(pause)
        servo.set(max)
        time.sleep(pause)
        servo.set(0.5)

api = Api()
api.demonize()
remote = Remote()

while True:
    # api events
    for event, kwargs in api.events:
        if event == "wave":
            wave(**kwargs)
        if event == "set":
            servo.set(0.75-float(kwargs["position"])*0.5)
        if event == "set_speed":
            motor.duty_cycle = kwargs['position']
    api.events = []
def __main__():
    #Setup MQTT and Instantiate the Servo Motor
    mqttc = mqtt.Client()
    servoMotor = Servo(0, 500, 2500)

    ## Define the MQTT Callbacks
    # The callback for when the client receives a response from the Server
    def on_connect(client, userdata, flags, rc):
        print("Connected with result code " + str(rc))
        mqttc.subscribe("servoControl")

    # Subscribe to the MQTT Topic
    def on_subscribe(client, userdata, mid, granted_qos):
        print("Subscribed: " + str(mid) + " " + str(granted_qos))

    # The callback when a publish message is received from the Server
    def on_message(client, userdata, msg):
        if msg.payload:
            print(msg.topic + ":: payload is " + str(msg.payload))
            servoMotor.setAngle(int(msg.payload))

    # The callback to disconnect and update the user
    def on_disconnect(client, userdata, rc):
        print("Disconnect From Server")

    #Assign the callbacks
    mqttc.on_message = on_message
    mqttc.on_connect = on_connect
    mqttc.on_subscribe = on_subscribe
    mqttc.on_disconnect = on_disconnect
    #Connects directly to the Omega
    mqttc.connect('127.0.0.1')
    # Continue the network infinite loop
    mqttc.loop_forever()
Example #3
0
def main():
    # instantiate objects for the two servos
    standardServo = Servo(0, 500, 2400)
    microServo = Servo(1, 500, 2400)

    # set both servos to the neutral position
    standardServo.setAngle(90.0)
    microServo.setAngle(90.0)
    time.sleep(2)

    # Turn servos to the 0 angle position
    #standardServo.setAngle(0.0)
    #microServo.setAngle(0.0)
    #time.sleep(2)
    # Turn servos to the neutral positiostandardServo.setAngle(90.0)
    microServo.setAngle(90.0)
    time.sleep(2)
Example #4
0
def main():
    # instantiate objects for the two servos
    standardServo = Servo(0, 500, 2400)
    microServo = Servo(1, 500, 2400)

    # set both servos to the neutral position
    standardServo.setAngle(90.0)
    microServo.setAngle(90.0)
    time.sleep(2)

    # infinite loop
    while (True):
        # Turn servos to the 0 angle position
        standardServo.setAngle(0.0)
        microServo.setAngle(0.0)
        time.sleep(2)
        # Turn servos to the neutral position
        standardServo.setAngle(90.0)
        microServo.setAngle(90.0)
        time.sleep(2)
        # Turn servos to the 180 angle position
        standardServo.setAngle(180.0)
        microServo.setAngle(180.0)
        time.sleep(2)
Example #5
0
from motors import Servo
import onionGpio
import time
import subprocess

sleepTime = 2

gpio0 = onionGpio.OnionGpio(0)
gpio0.setOutputDirection(0)


microServo = Servo(1, 500, 2400)
microServo.setAngle(0.0)
gpio0.setValue(0)
while 1:
        cmd = "nfc-list | grep UID | sed -e 's/ //g' -e 's/^.*://'"
        uid = subprocess.check_output(cmd,shell=True).rstrip('\n')
        if(uid  != ""):
                gpio0.setValue(1)
                microServo.setAngle(180.0)
                time.sleep(sleepTime)
                gpio0.setValue(0)
                microServo.setAngle(0.0)
                time.sleep(sleepTime)
Example #6
0
def main():
    # instantiate objects for all servos
    servoA  = Servo(0, 500, 2400)
    servoB  = Servo(1, 500, 2400)
    servoQa = Servo(2, 500, 2400)
    servoA1 = Servo(3, 500, 2400)
    servoB1 = Servo(4, 500, 2400)
    servoQb = Servo(5, 500, 2400)
    servoQ  = Servo(6, 500, 2400)
    
    # set all servos to the neutral position
    servoA.setAngle(90.0)
    servoB.setAngle(90.0)
    servoQa.setAngle(90.0)
    servoA1.setAngle(90.0)
    servoB1.setAngle(90.0)
    servoQb.setAngle(90.0)
    servoQ.setAngle(90.0)
    
    
    print('Enter Input 1 (0 or 1):')
    a = int(input())
    print('Enter Input 2 (0 or 1):')
    b = int(input())
    print('Enter Input 3 (0 or 1):')
    a1 = int(input())
    print('Enter Input 4 (0 or 1):')
    b1 = int(input())

    
    
    #standard setup: 1 AND, 2 OR, 3 NAND
    operator1 = int(1)
    operator2 = int(2)
    operator3 = int(3)

    #logic gate Qa evaluate
    Qa = logic(operator1, a, b)
    
    #logic gate Qb evaluate
    Qb = logic(operator2, a1, b1)
    
    #logic gate Q evaluate
    Q = logic(operator3, Qa, Qb)
    
    #open input gates
    if(a == 1):
        servoCTRL(servoA, 0, 500, 2400)
    if(b == 1):
        servoCTRL(servoB, 1, 500, 2400)
    if(a1 == 1):
        servoCTRL(servoA1, 3, 500, 2400)
    if(b1 == 1):
        servoCTRL(servoB1, 4, 500, 2400)
    
    time.sleep(2)
    #open output gates
    if(Qa == 1):
        servoCTRL(servoQa, 2, 500, 2400)
    if(Qb == 1):
        servoCTRL(servoQb, 5, 500, 2400)
    
    time.sleep(2)    
    #open final gate
    if(Q == 1):
        servoCTRL(servoQ, 6, 500, 2400)
Example #7
0
def servoCTRL(servo, channel, minPulse, maxPulse):
    servo = Servo(channel, minPulse, maxPulse)
    servo.setAngle(180.0)
    time.sleep(0.1)
    servo.setAngle(90.0)
Example #8
0
    def __init__(self):

        self.pi = pigpio.pi()

        self.c = 0
        self.drawingMode = False

        # pen input
        self.pi.set_mode(Typer.PEN_INPUT, pigpio.INPUT)
        self.pi.set_pull_up_down(Typer.PEN_INPUT, pigpio.PUD_UP)

        self.pi.callback(Typer.PEN_INPUT, pigpio.FALLING_EDGE, self.cbf)

        # x and y mins
        self.pi.set_mode(Typer.X_MIN, pigpio.INPUT)
        self.pi.set_pull_up_down(Typer.PEN_INPUT, pigpio.PUD_UP)

        self.pi.set_mode(Typer.Y_MIN, pigpio.INPUT)
        self.pi.set_pull_up_down(Typer.PEN_INPUT, pigpio.PUD_UP)

        self.pi.callback(Typer.Y_MIN, pigpio.RISING_EDGE, self.yMinDown)

        self.pi.callback(Typer.X_MIN, pigpio.RISING_EDGE, self.xMinDown)

        self.xMin = False
        self.yMin = False

        self.goingHome = False
        self.sleeping = False

        #---

        try:

            keyboard.on_press(self.onKeyDown)

        except AttributeError:

            print("no keyboard detected")

        self.keyPositions = {'k7': (112.0, 78.0), 'k3': (35.0, 78.0), 'k46': (80.0, 19.0), 'k45': (60.0, 17.0), 'k38': (184.0, 48.0), 'k23': (160.0, 60.0), 'k25': (200.0, 65.0), 'k48': (117.0, 24.0), 'k6': (95.0, 78.0), 'k20': (100.0, 57.0), 'k8': (132.0, 78.0), 'k51': (175.0, 25.0), 'k31': (50.0, 40.0), 'k9': (152.0, 78.0), 'k52': (195.0, 25.0), 'k28': (250.0, 47.0), 'k36': (145.0, 41.0), 'k37': (165.0, 45.0), 'k10': (170.0, 78.0), 'k15': (
            1.0, 52.0), 'k4': (55.0, 78.0), 'k33': (90.0, 40.0), 'k29': (0.0, 1.0), 'k2': (15.0, 75.0), 'k42': (10.0, 17.0), 'k16': (25.0, 55.0), 'k17': (45.0, 60.0), 'k30': (30.0, 40.0), 'k50': (157.0, 21.0), 'k32': (70.0, 40.0), 'k18': (65.0, 65.0), 'k19': (80.0, 60.0), 'k34': (107.0, 40.0), 'k49': (137.0, 21.0), 'k24': (179.0, 60.0), 'k35': (127.0, 43.0), 'k22': (140.0, 60.0), 'k11': (186.0, 79.0), 'k5': (75.0, 78.0), 'k57': (100.0, 1.0), 'k58': (0.0, 35.0)}

        self.pos = Vec(0, 0)
        self.lastPos = self.pos

        self.up = True
        self.seq = Queue()
        self.lastTick = 0

        self.motion = Motion(self.pi, self)

        self.motionWorker = MotionDataProcessThread(2, Queue(), self.motion)
        self.motionWorker.start()

        Motors = collections.namedtuple("Motors", "steppers, servos")

        self.motors = Motors(
            steppers=(
                Stepper(self.pi, 200, 1 / 2, 20, 21, 12, 16),
                Stepper(self.pi, 200, 1 / 2, 7, 24, 25, 8)
            ),
            servos=(Servo(self.pi),)

        )

        self.goHome()