# NAME: Thomas De Witte # Version: 1.1 # Library Import from gpiozero import DigitalOutputDevice # DIGITALOUTPUTDEVICE is for RELAIS from gpiozero import Button from gpiozero.pins.pigpio import PiGPIOFactory import time # IPADRES CHANGE THE GREEN TEXT TO CHANGE IP ADRES factory = PiGPIOFactory('192.168.0.112') # Setup Outputs # Relais CH1 = DigitalOutputDevice(17, True, False, pin_factory=factory) CH2 = DigitalOutputDevice(22, True, False, pin_factory=factory) CH3 = DigitalOutputDevice(27, True, False, pin_factory=factory) CH4 = DigitalOutputDevice(10, True, False, pin_factory=factory) CH = [CH1, CH2, CH3, CH4] # LED's LED1 = DigitalOutputDevice(26, pin_factory=factory) LED2 = DigitalOutputDevice(19, pin_factory=factory) LED3 = DigitalOutputDevice(6, pin_factory=factory) LED4 = DigitalOutputDevice(11, pin_factory=factory) LED = [LED1, LED2, LED3, LED4] # Setup Inputs # Buttons BTN1 = Button(pin=14, pull_up=False, bounce_time=0.25, pin_factory=factory) BTN2 = Button(pin=15, pull_up=False, bounce_time=0.25, pin_factory=factory) BTN3 = Button(pin=23, pull_up=False, bounce_time=0.25, pin_factory=factory) BTN4 = Button(pin=12, pull_up=False, bounce_time=0.25, pin_factory=factory)
from gpiozero.pins.pigpio import PiGPIOFactory from gpiozero import AngularServo import tkinter from time import sleep pin_factory = PiGPIOFactory(host='192.168.1.216') servo = AngularServo(18, pin_factory=pin_factory, min_angle=0, max_angle=100) servo.max() sleep(5) def set_servo_angle(val): print("Servo angle: ", servo.angle, "Val:", val) servo.angle = int(val) root = tkinter.Tk() scale = tkinter.Scale(orient='horizontal', from_=servo.min_angle, to=servo.max_angle, command=set_servo_angle) scale.pack() root.mainloop()
Built and tested with Python 3.7 on Raspberry Pi 4 Model B """ import signal import requests import logging from gpiozero import Device, Button from gpiozero.pins.pigpio import PiGPIOFactory # Initialize Logging logging.basicConfig(level=logging.WARNING) logger = logging.getLogger('main') logger.setLevel(logging.INFO) # Initialise GPIOZero Device.pin_factory = PiGPIOFactory() BUTTON_GPIO_PIN = 23 button = None LED_STATES = ['off', 'on', 'blink'] current_led_state = 0 # off # Make sure thing_name matches the "dweet_led thing" you want to control. thing_name = '747a1500' URL = 'https://dweet.io' def init_button(): """Setup button""" global button button = Button(BUTTON_GPIO_PIN, pull_up=True, bounce_time=0.1)
""" from gpiozero import LED #to use LED from gpiozero from gpiozero import Button #to use Button from gpiozero import multiprocessing #to use multiprocessing from gpiozero.pins.pigpio import PiGPIOFactory #to use the remote GPIO pins import time #to use time in the code __author__ = "Senne De Winter" __email__ = "*****@*****.**" __status__ = "Development" IP = PiGPIOFactory(host='192.168.1.39') #to set the Raspberry Pi IP adress to '....', to use the GPIO pins on this IP LED_1= LED(16, pin_factory=IP) #to set LED_1 to remote GPIO pin 16 LED_2= LED(20, pin_factory=IP) #to set LED_2 to remote GPIO pin 20 BUTTON_1= Button(26,pin_factory=IP) #to set BUTTON_1 to remote GPIO pin 26 BUTTON_2 = Button(19, pin_factory=IP) #to set BUTTON_2 to remote GPIO pin 19 def set_leds_on_off(): #to turn the leds turn on or off while True: #to repeat this function untill program is stopped if BUTTON_1.is_pressed: #to do something if BUTTON_1 is pressed time.sleep(0.5) #to wait half a second, to debounce the button LED_1.toggle() LED_2.toggle()
from gpiozero import LED from gpiozero.pins.pigpio import PiGPIOFactory from signal import pause factory = PiGPIOFactory(host='192.168.1.3') button = Button(2) led = LED(17, pin_factory=factory) led.source = button.values pause()
#!/usr/bin/env python """ Maak een teller. Je hebt een drukknop die optelt en één die naar beneden telt. """ from gpiozero.pins.pigpio import PiGPIOFactory from gpiozero import Button import time __author__ = "Myrthe Diepeveen" __email__ = "*****@*****.**" __status__ = "Development" remote_factory = PiGPIOFactory(host='192.168.1.31') Button1 = Button(pin=17, pin_factory=remote_factory) Button2 = Button(pin=22, pin_factory=remote_factory) Button3 = Button(pin=23, pin_factory=remote_factory) def main(): counter = 0 while True: if Button1.is_pressed: time.sleep(1) counter = counter + 1 print(counter) if Button2.is_pressed: time.sleep(1) counter = counter - 1 print(counter)
#! /usr/bin/env python3 # -*- coding: utf-8 -*- # vim:fenc=utf-8 # # Distributed under terms of the MIT license. """ GPIO module """ import asyncio import logging import gpiozero from gpiozero.pins.pigpio import PiGPIOFactory gpiozero.Device.pin_factory = PiGPIOFactory() class GPIOController: def __init__(self, gpiomap, queue, debounce_time, loop): self.gpiomap = gpiomap self.queue = queue self.debounce_time = debounce_time self.btnstrmap = {} self._setup_gpios() self.loop = loop def _setup_gpios(self): self.btnmap = {} for i in self.gpiomap: btn_name = self.gpiomap[i].lower() if not btn_name.startswith("none"): self.btnmap[btn_name] = gpiozero.Button(
""" A house installation of a raspberry pi that controls 2 relays """ from gpiozero.pins.pigpio import PiGPIOFactory from guizero import App, PushButton from gpiozero import OutputDevice import sys __author__ = "Jens Vansteenvoort" __email__ = "*****@*****.**" __status__ = "Development" relay1_pin = 17 relay2_pin = 22 IP = PiGPIOFactory(host='192.168.0.242') relay1 = OutputDevice(relay1_pin, pin_factory=IP) relay2 = OutputDevice(relay2_pin, pin_factory=IP) #code to close program def exitApp(): sys.exit() #code to toggle relay1 def toggle_relay1(): relay1.toggle() if relay1.is_lit: relay1Button.text = "RELAY OFF" else:
class Motor: motors = PiGPIOFactory(host='192.168.1.21') #Create Factory TRACK_STEP = PWMLED(2) TRACK_DIR = PWMLED(3) ROTATE_STEP = PWMLED(12) ROTATE_DIR = PWMLED(16) TILT_STEP = PWMLED(20) TILT_DIR = PWMLED(21) delay = .005 def __init__(self, name): self.data = [] self.name = name #RIGHT def right(self, speed, length): motors = self.motors if self.name == "track": dir = self.TRACK_DIR step = self.TRACK_STEP for x in range(length): print(self.name) dir.value = 0 step.value = .5 sleep(speed) step.value = 0 if self.name == "tilt": dir = self.TILT_DIR step = self.TILT_STEP for x in range(length): print(self.name) dir.value = 0 step.value = .5 sleep(speed) step.value = 0 if self.name == "rotate": dir = self.TILT_DIR step = self.TILT_STEP for x in range(length): print(self.name) dir.value = 0 step.value = .5 sleep(speed) step.value = 0 #LEFT def leftt(self, speed, length): motors = self.motors if self.name == "track": dir = self.TRACK_DIR step = self.TRACK_STEP for x in range(length): print(self.name) dir.value = 1 step.value = .5 sleep(speed) step.value = 0 if self.name == "tilt": dir = self.TILT_DIR step = self.TILT_STEP for x in range(length): print(self.name) dir.value = 1 step.value = .5 sleep(speed) step.value = 0 if self.name == "rotate": dir = self.TILT_DIR step = self.TILT_STEP for x in range(length): print(self.name) dir.value = 1 step.value = .5 sleep(speed) step.value = 0 #STEP LEFT def stepleft(self, steps): motors = self.motors if self.name == "track" and self.name != "chk": dir = self.CAR_DIR step = self.CAR_STEP print(self.name, "<", steps) for x in range(steps): dir.value = 1 step.on() sleep(self.delay) step.off() sleep(self.delay) if self.name == "chk" and self.name != "track": dir = self.CHK_DIR step = self.CHK_STEP print(self.name, "<", steps) for x in range(steps): dir.value = 1 step.on() sleep(self.delay) step.off() sleep(self.delay) #STEP RIGHT def stepright(self, steps): motors = self.motors if self.name == "track" and self.name != "chk": dir = self.CAR_DIR step = self.CAR_STEP print(self.name, steps, ">") for x in range(steps): dir.value = 0 step.on() sleep(self.delay) step.off() sleep(self.delay) if self.name == "chk" and self.name != "track": dir = self.CHK_DIR step = self.CHK_STEP print(self.name, steps, ">") for x in range(steps): dir.value = 0 step.on() sleep(self.delay) step.off() sleep(self.delay)
import logging import signal import sys import json from time import sleep from gpiozero import Device, PWMLED from gpiozero.pins.pigpio import PiGPIOFactory import paho.mqtt.client as mqtt # (1) # Initialize Logging logging.basicConfig(level=logging.WARNING) # Global logging configuration logger = logging.getLogger("main") # Logger for this module logger.setLevel(logging.INFO) # Debugging for this file. # Initialize GPIO Device.pin_factory = PiGPIOFactory() # Set GPIOZero to use PiGPIO by default. # Global Variables LED_GPIO_PIN = 21 BROKER_HOST = "localhost" # (2) BROKER_PORT = 1883 CLIENT_ID = "LEDClient" # (3) TOPIC = "led" # (4) client = None # MQTT client instance. See init_mqtt() # (5) led = None # PWMLED Instance. See init_led() """ GPIO Related Functions """ def init_led():
""" info about project here """ import multiprocessing import time from gpiozero import Button, LED from gpiozero.pins.pigpio import PiGPIOFactory ... __author__ = "Johannes Coolen" __email__ = "*****@*****.**" __status__ = "development" IP = PiGPIOFactory(host='192.168.0.196') # instellen ip rpi BUTTON1 = Button(pin=4, pin_factory=IP, pull_up=True, bounce_time=0.3) # knoppen instellen BUTTON2 = Button(pin=5, pin_factory=IP, pull_up=True, bounce_time=0.3) BUTTON3 = Button(pin=6, pin_factory=IP, pull_up=True, bounce_time=0.3) LED1 = LED(pin=17, pin_factory=IP) # leds instellen LED2 = LED(pin=18, pin_factory=IP) LED3 = LED(pin=19, pin_factory=IP) def toggle_Led1(): while True: if BUTTON1.is_pressed: LED1.toggle() time.sleep(1)
file_handler.setFormatter(file_formatter) # create logger logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) # add the handlers to the logger logger.addHandler(console_handler) logger.addHandler(except_handler) logger.addHandler(file_handler) # log initial message logger.info('Start of the log of {}'.format(conf.name)) # in case the pin number is None (null in json), a dummy object is assigned hatch = (gpiozero.Servo( conf.hatch_pin, conf.hatch_closed, pin_factory=PiGPIOFactory()) if conf.hatch_pin else dummy.Output('hatch')) buzzer = (BeepingTonalBuzzer(conf.buzzer_pin, octaves=4) if conf.buzzer_pin else dummy.Output('buzzer')) status_LED = (gpiozero.RGBLED(*conf.status_LED_pins, pwm=True) if all(conf.status_LED_pins) else dummy.Output('status_LED')) arm_switch = (gpiozero.Button(conf.arm_switch_pin) if conf.arm_switch_pin else dummy.Input('arm_switch')) breakwire = (gpiozero.Button(conf.breakwire_pin) if conf.breakwire_pin else dummy.Input('breakwire')) gpiobjects = [hatch, buzzer, status_LED, arm_switch] imu = altimu10v5.IMU() # automatic dummy assignment if the sensors are not present, to allow for easier testing if sensors_present(): baro = Sensor('baro', conf.sensor_intervals['baro'],
from gpiozero.pins.pigpio import PiGPIOFactory from gpiozero import AngularServo, Button, RotaryEncoder from signal import pause from time import sleep import threading from pythonosc import udp_client client = udp_client.SimpleUDPClient("192.168.205.40", "12000") IS_AV_MODE = False # create a custom pin-factory to fix servo jitter # more info heere: https://gpiozero.readthedocs.io/en/stable/api_output.html#servo # and here: https://gpiozero.readthedocs.io/en/stable/api_pins.html pigpio_factory = PiGPIOFactory() servo = AngularServo(22, min_angle=-90, max_angle=90, pin_factory=pigpio_factory) ENCODER = RotaryEncoder(17, 18, max_steps=0) # Rotary encoder ENC_SRV_RATIO = 2 # How many encoder steps is one servo angle # Create a limit switch senseor which detects system misalignment button = Button(27) def servo_control(delay, servo_step): # global IS_AV_MODE while IS_AV_MODE: if servo.angle + servo_step > servo.min_angle and servo.angle + servo_step < servo.max_angle: servo.angle += servo_step sleep(delay) else:
from os import system from time import sleep from gpiozero import Buzzer from gpiozero.pins.pigpio import PiGPIOFactory factory = PiGPIOFactory('192.168.0.123') buzzer = Buzzer(22, pin_factory=factory) def element(tfrom, tto): buzzer.on() sleep(tfrom) buzzer.off() sleep(tto) def dot(): element(0.1, 0.2) def dash(): element(0.3, 0.1) def letterSpace(): sleep(0.2) def wordSpace(): sleep(0.6)
def liftToCrack(location): factory = PiGPIOFactory(host='169.254.232.97') # Purpose: Pick up phone from drop box # Place it on crack platform # Assume: Arm starts in home orientation # LA starts at home # Vacuum pump off # Phone dropped and in drop box # Location found in C# # End: Arm in home orientation # LA at home # Vacuum pump off # Phone placed on crack platform (either side face up) # Pneumatics raised # Inputs: location = [x, y, z, a, b] # Outputs: True if successful (done command) # False if unsuccessful (kill command) # Arm movements list moveHome = ['xh', 'yh', 'zh', 'ah', 'bh'] moveCrack0 = ['x0', 'y0', 'z0', 'a0', 'b0'] moveCrack1 = ['x1', 'y1', 'z1', 'a1', 'b1'] # Move LA out to position if LAMove(location, factory) == False: return False # Move arm to above the phone dornaMove(location) # Turn on vacuum vpump(True, factory) # Lower pneumatics raiseLower(False, factory) # Slowly lower effector until arm transducer reads vacuum if slowApproachArm(factory) == False: return False # Raise pneumatics raiseLower(True, factory) # Check phone hasn't been released if ArmTrans(factory) == False: return False # Align arm with bottom of crack platform ## dornaMove(moveCrack0) # Slide phone onto platform if LAHome(factory) == False: return False # Check phone hasn't been accidentally released if ArmTrans(factory) == False: return False # Release vacuum vpump(False, factory) # Check phone has been released if ArmTrans(factory) == True: return False # Move arm out of the way ## dornaMove(moveCrack1) # Move arm to its home orientation ## dornaMove(moveHome) return True
from flask import Flask, render_template, request, json from gpiozero.pins.pigpio import PiGPIOFactory from gpiozero import OutputDevice, AngularServo, LED, PWMOutputDevice import logging app = Flask(__name__) #Define the factories factory = PiGPIOFactory(host='192.168.0.22') factory2 = PiGPIOFactory(host='192.168.0.21') # Define both robots en_1 = PWMOutputDevice(12, pin_factory=factory) en_2 = PWMOutputDevice(26, pin_factory=factory) motor_in1 = OutputDevice(13, pin_factory = factory) motor_in2 = OutputDevice(21, pin_factory = factory) motor_in3 = OutputDevice(17, pin_factory = factory) motor_in4 = OutputDevice(27, pin_factory = factory) pin1 = OutputDevice(7, pin_factory = factory2) pin2 = OutputDevice(8, pin_factory = factory2) pin3 = OutputDevice(9, pin_factory = factory2) pin4 = OutputDevice(10, pin_factory = factory2) #Define the eye linus_eye = LED(16, pin_factory=factory) # Define the servo angular_servo = AngularServo(22, min_angle=-90, max_angle=90, pin_factory=factory) angular_servo2 = AngularServo(23, min_angle=-90, max_angle=90, pin_factory=factory)
def flipStart(): factory = PiGPIOFactory(host='169.254.232.97') # Purpose: Raise pneumatics at start of sequence # Flip phone over on crack platform # Assume: Arm starts in home orientation # LA starts at home # Vacuum pump off # Phone placed on crack platform (either side face up) # End: Arm in home orientation # LA at home # Vacuum pump off # Phone flipped over # Pneumatics raised # Inputs: None # Outputs: True if successful (done command) # False if unsuccessful (kill command) # Arm movements list moveHome = ['xh', 'yh', 'zh', 'ah', 'bh'] moveFlipC = ['xc', 'yc', 'zc', 'ac', 'bc'] moveFlip0 = ['x0', 'y0', 'z0', 'a0', 'b0'] moveFlip1 = ['x1', 'y1', 'z1', 'a1', 'b1'] moveFlip2 = ['x2', 'y2', 'z2', 'a2', 'b2'] # Raise pneumatics raiseLower(True, factory) # Center LA ## if LAMove(moveFlipC, factory) == False: ## return False # Home Arm robot.home("j1") robot.home("j2") robot.home("j3") print(robot.homed()) # Move arm to its home orientation ## dornaMove(moveHome) # Send LA to its home position if LAHome(factory) == False: return False # Turn on vacuum vpump(True, factory) # Move arm to top of crack platform ## dornaMove(moveFlip0) # Slowly lower effector until arm transducer reads vacuum if slowApproachArm(factory) == False: return False # Slide phone off of platform ## if LAMove(moveFlip0, factory) == False: ## return False # Flip phone over and ## dornaMove(moveFlip1) # Check phone hasn't been accidentally released if ArmTrans(factory) == False: return False # Slide phone onto platform if LAHome(factory) == False: return False # Release vacuum vpump(False, factory) # Check phone has been released if ArmTrans(factory) == True: return False # Move arm out of the way ## dornaMove(moveFlip2) # Move arm to its home orientation ## dornaMove(moveHome) return True
from gpiozero import LED from gpiozero.pins.pigpio import PiGPIOFactory factory = PiGPIOFactory(host='172.29.30.168') led = LED(20, pin_factory=factory) led.off()
from gpiozero import LEDBoard, MotionSensor from gpiozero.pins.pigpio import PiGPIOFactory from signal import pause ips = ['192.168.1.3', '192.168.1.4', '192.168.1.5', '192.168.1.6'] remotes = [PiGPIOFactory(host=ip) for ip in ips] leds = LEDBoard(2, 3, 4, 5) # leds on this pi sensors = [MotionSensor(17, pin_factory=r) for r in remotes] # remote sensors for led, sensor in zip(leds, sensors): led.source = sensor pause()
# NAME: Thomas De Witte # VERSION: 2.0 # LIBRARIES from gpiozero import DigitalOutputDevice # DIGITALOUTPUTDEVICE is for RELAIS from gpiozero import Button from gpiozero.pins.pigpio import PiGPIOFactory import time import timeit # CONFIG IP_ADRESS = PiGPIOFactory( '192.168.0.112') # IPADRES CHANGE THE GREEN TEXT TO CHANGE IP ADRES BOUNCE_TIME = 0.01 # CONFIG THE BOUNCE TIME HERE TRESHOLD_LONG_PUSH = 1 # CONFIG HERE THE TIME TO HAVE A LONG PUSH TRESHOLD_TIME_TO_PRESS = 1.5 # SETUP # Relais AMOUNT_CHANNELS = 4 # AMOUNT OF CHANNELS YOU WANT TO USE -- MAX 8!! CH_PIN = [17, 22, 27, 10, 26, 19, 6, 11] # THESE ARE THE PINS YOU CAN USE FOR RELAIS -- MAX 8 RELAIS!! # Buttons AMOUNT_BUTTONS = 4 # AMOUNT OF BUTTONS YOU WANT TO USE -- MAX 4!! BTN_PIN = [14, 15, 23, 12] # THESE ARE THE PINS YOU CAN USE FOR BUTTONS -- MAX 4 BUTTONS!! # VARIABLEs ch = [] btn = []
# GPIOZERO_PIN_FACTORY=pigpio PIGPIO_ADDR=192.168.4.158 from gpiozero import PWMLED, Button from time import sleep from signal import pause from gpiozero.pins.pigpio import PiGPIOFactory pi_host = '192.168.4.158' factory = PiGPIOFactory(host=pi_host) green = PWMLED(17, pin_factory=factory) button = Button(2, pin_factory=factory) pwm_value = 0 pwm_type = 0 while True: if pwm_type == 0: if button.is_active: pwm_value += 0.1 if pwm_value >= 0.9: pwm_type = 1 elif pwm_type == 1: if button.is_active: pwm_value -= 0.1 if pwm_value <= 0.1: pwm_type = 0 print(pwm_value) green.value = pwm_value
from gpiozero import Button, LED from gpiozero.pins.pigpio import PiGPIOFactory from gpiozero.tools import all_values from signal import pause factory3 = PiGPIOFactory(host='192.168.1.3') factory4 = PiGPIOFactory(host='192.168.1.4') led = LED(17) button_1 = Button(17, pin_factory=factory3) button_2 = Button(17, pin_factory=factory4) led.source = all_values(button_1, button_2) pause()
# Global Variables and Components # Author: Raheel Junaid # Date Started: 1/24/21 from gpiozero import Servo, Buzzer, RGBLED, DigitalOutputDevice, LED from dotenv import load_dotenv from gpiozero.pins.pigpio import PiGPIOFactory import os from rpi_lcd import LCD load_dotenv() try: remote_factory = PiGPIOFactory(host=os.environ['REMOTEPI']) except: print(f'Could not connect to Raspberry Pi at {os.environ["REMOTEPI"]}') camLED = LED(24) servo = Servo(18, 1, pin_factory=remote_factory) RGBLed = RGBLED(27, 23, 25) screen = LCD() systems = { 'fan': "T", 'servo': "T", 'keypad': "T", 'camera': "T", 'sensor': "T", } buzzer = Buzzer(4)
def single_factory_connector(ip): """ :return: returns the connection object for remote GPIO """ return PiGPIOFactory(host=str(ip))
#!/usr/bin/env __author__ = "Zino Henderickx" __version__ = "1.0" # LIBRARIES from gpiozero import LED from gpiozero import Button from gpiozero.pins.pigpio import PiGPIOFactory import time IP = PiGPIOFactory('192.168.0.207') # LED's LED1 = LED(17, pin_factory=IP) LED2 = LED(27, pin_factory=IP) LED3 = LED(22, pin_factory=IP) LED4 = LED(10, pin_factory=IP) # BUTTONS BUTTON1 = Button(5, pin_factory=IP) BUTTON2 = Button(6, pin_factory=IP) BUTTON3 = Button(13, pin_factory=IP) BUTTON4 = Button(19, pin_factory=IP) # LISTS led = [10, 17, 22, 27] button = [5, 6, 13, 19] # FUNCTIONS
# Library Import from gpiozero import DigitalOutputDevice # DIGITALOUTPUTDEVICE is for RELAIS from gpiozero import Button from gpiozero.pins.pigpio import PiGPIOFactory import time import timeit # IPADRES CHANGE THE GREEN TEXT TO CHANGE IP ADRES IP_ADRESS = PiGPIOFactory('192.168.1.55') # Setup Outputs # Relais AMOUNT_CHANNELS = 4 # AMOUNT OF CHANNELS YOU WANT TO USE -- MAX 8!! CH_PIN = [14, 15, 18, 23] # THESE ARE THE PINS YOU CAN USE FOR RELAIS -- MAX 8 RELAIS!!! # Buttons AMOUNT_BUTTONS = 4 # AMOUNT OF BUTTONS YOU WANT TO USE -- MAX 4!! BTN_PIN = [2, 3, 17, 27 ] # THESE ARE THE PINS YOU CAN USE FOR BUTTONS -- MAX 4 BUTTONS!!! # Variables ch = [] btn = [] # Functions def ch_setup(): for j in range(AMOUNT_CHANNELS): ch.append(
# import libraries from guizero import App, PushButton, Slider, Text, Window from gpiozero import Robot, CamJamKitRobot, AngularServo from gpiozero.pins.pigpio import PiGPIOFactory #Define the app and window for the servo sliders app = App("Dual Robot Control", layout='grid') servo_window = Window(app, "Servo Movement") servo_window.bg = (51, 165, 255) app.bg = (51, 246, 255) #Define the factories # insert IP addresses of both robots here factory = PiGPIOFactory(host='') # Define both robots linus = Robot(left=(13, 21), right=(17, 27), pin_factory=factory) torvalds = CamJamKitRobot() # Define the servos servo = AngularServo(22, min_angle=-90, max_angle=90, pin_factory=factory) servo_two = AngularServo(23, min_angle=-90, max_angle=90, pin_factory=factory) # Define the functions def direction_one(): linus.forward() def direction_two(): linus.backward()
def toCarriage(sequence): factory = PiGPIOFactory(host='169.254.232.97') # Purpose: Lift phone from either top or bottom of crack platform # Move phone to carriage # Attach to carriage and release phone # Move out of the way and trigger drop # Assume: Arm starts in home orientation # LA starts at home # Vacuum pump off # Phone placed on crack platform (either side face up) # Sequence pregenerated in C# # End: Arm in home orientation # LA at home # Vacuum pump off # Phone dropped and in drop box # Pneumatics raised # Inputs: sequence = [x, y, z, a, b, ud] # Outputs: True if successful (done command) # False if unsuccessful (kill command) # Arm movements list moveHome = ['xh', 'yh', 'zh', 'ah', 'bh'] moveCarrU = ['xu', 'yu', 'zu', 'au', 'bu'] moveCarrD = ['xd', 'yd', 'zd', 'ad', 'bd'] moveCarr0 = ['x0', 'y0', 'z0', 'a0', 'b0'] moveCarr1 = ['x1', 'y1', 'z1', 'a1', 'b1'] # Check whether to grab top of phone or bottom if ud == 1: # Move arm above phone ## dornaMove(moveCarrU) # Turn on vacuum vpump(True, factory) # Slow approach until vacuum if slowApproachArm(factory) == False: return False else: # Move arm to underside of phone ## dornaMove(moveCarrD) # Turn on vacuum vpump(True, factory) # Check phone has been grabbed if ArmTrans(factory) == False: return False # Slide phone off of platform if LAMove(sequence, factory) == False: return False # Move arm up to carriage ## dornaMove(moveCarr0) ## dornaMove(moveCarr1) dornaMove(sequence) # Check phone hasn't been accidentally released if ArmTrans(factory) == False: return False # Slow approach at different angles until carriage vacuum achieved ## if sequence[3] == "aBottom": ## slowApproachCar("up", factory) ## else if sequence[3] == "aSide": ## slowApproachCar("away", factory) ## else if sequence[3] == "a45": ## slowApproachCar("45", factory) # Check phone is still on arm if ArmTrans(factory) == False: return False # Release vacuum vpump(False, factory) # Check phone has been released if ArmTrans(factory) == True: return False # Move arm to home position dornaMove(moveHome) # Move LA home and out of the way of carriage if LAHome(factory) == False: return False # Trigger drop drop(factory) sleep(5) return True
from gpiozero import Robot, Button, LED from gpiozero.pins.pigpio import PiGPIOFactory from signal import pause import time piozero.Device.pin_factory = PiGPIOFactory(host='192.168.7.96') factory = PiGPIOFactory(host='192.168.7.59') led = LED(18, pin_factory=factory) led.on() time.sleep(1) led.off() factory2 = PiGPIOFactory(host='192.168.7.96') robby = Robot(left=(7, 8), right=(9, 10), pin_factory=factory2) robby.forward() time.sleep(0.5) robby.stop() pause()
char_released(key.char) elif key == Key.space: char_to_motor["w"].unboost() def disconnect(): stop_ud() stop_lr() # any code you want to run during loss of connection with the controller or keyboard interrupt pass _stop_flag = object() if (run_on_remote): print("connecting with remote ... ") remote_factory = PiGPIOFactory(host=remote_host) left = PWMLED(27, pin_factory=remote_factory) right = PWMLED(22, pin_factory=remote_factory) vor = PWMLED(13, pin_factory=remote_factory) back = PWMLED(19, pin_factory=remote_factory) control_led = LED(17, pin_factory=remote_factory) control_led.on() sleep(1) control_led.off() print("connected") else: left = PWMLED(27) right = PWMLED(22) vor = PWMLED(13) back = PWMLED(19)