Heinz Schmid

Dr. techn.
Suchen Schließen

Hexapod Steuerungsprogramm

#!/usr/bin/python
# von Heinz Schmid (h.schmid@gmx.info)  März.2018
import RPi.GPIO as GPIO
import pigpio
import time
import sys
import os
import signal
from Tkinter import *

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
mitte_=18
rechts_=4
links_=17
cam1=23
cam2=24
pi=pigpio.pi()

def vorwaerts():
    i=0
    while i<5:
        pi.set_servo_pulsewidth(mitte_,1944)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(rechts_,1944)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(links_,1944)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(mitte_,1944)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(mitte_,1055)
        time.sleep(0.115)
        pi.set_servo_pulsewidth(rechts_,1055)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(links_,1055)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(mitte_,1055)
        time.sleep(0.15)
        i=i+1
    pi.set_servo_pulsewidth(mitte_,1500)
    time.sleep(0.5)
    pi.set_servo_pulsewidth(rechts_,1500)
    time.sleep(0.5)
    pi.set_servo_pulsewidth(links_,1500)
    time.sleep(0.5)
    

def neutral():
    pi.set_servo_pulsewidth(cam1,1500)
    time.sleep(0.5)
    pi.set_servo_pulsewidth(cam2,1500)
    time.sleep(0.5)
    
def nicken():
    i=0
    x=1500
    while i<5:
        x=x-50
        pi.set_servo_pulsewidth(cam1,x)
        time.sleep(1)
        i=i+1
    pi.set_servo_pulsewidth(cam1,1500)
 
def drehen():
    i=0
    y=1500
    while i<5:
        y=y-50
        pi.set_servo_pulsewidth(cam2,y)
        time.sleep(1)
        i=i+1
    pi.set_servo_pulsewidth(cam2,1500) 
 
def zurueck():
    i=0
    while i<5:
        pi.set_servo_pulsewidth(mitte_,1944)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(rechts_,1055)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(links_,1055)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(mitte_,1944)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(mitte_,1055)
        time.sleep(0.115)
        pi.set_servo_pulsewidth(rechts_,1944)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(links_,1944)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(mitte_,1055)
        time.sleep(0.15)
        i=i+1
    pi.set_servo_pulsewidth(mitte_,1500)
    time.sleep(0.5)
    pi.set_servo_pulsewidth(rechts_,1500)
    time.sleep(0.5)
    pi.set_servo_pulsewidth(links_,1500)
    time.sleep(0.5)
    
    
def rechts():
    i=0
    while i<2:
        pi.set_servo_pulsewidth(mitte_,1944)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(rechts_,1055)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(links_,1944)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(mitte_,1944)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(mitte_,1055)
        time.sleep(0.115)
        pi.set_servo_pulsewidth(rechts_,1944)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(links_,1055)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(mitte_,1055)
        time.sleep(0.15)
        i=i+1
    pi.set_servo_pulsewidth(mitte_,1500)
    time.sleep(0.5)
    pi.set_servo_pulsewidth(rechts_,1500)
    time.sleep(0.5)
    pi.set_servo_pulsewidth(links_,1500)
    time.sleep(0.5)
def links():
    i=0
    while i<2:
        pi.set_servo_pulsewidth(mitte_,1944)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(rechts_,1944)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(links_,1055)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(mitte_,1944)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(mitte_,1055)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(rechts_,1055)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(links_,1944)
        time.sleep(0.15)
        pi.set_servo_pulsewidth(mitte_,1055)
        time.sleep(0.15)
        i=i+1
    pi.set_servo_pulsewidth(mitte_,1500)
    time.sleep(0.5)
    pi.set_servo_pulsewidth(rechts_,1500)
    time.sleep(0.5)
    pi.set_servo_pulsewidth(links_,1500)
    time.sleep(0.5)


fenster=Tk()

button1=Button(master=fenster,text='Gerade',command=vorwaerts)
button2=Button(master=fenster,text='Neutral-Cam',command=neutral)
buttonx=Button(master=fenster,text='Nicken-Cam',command=nicken)
buttony=Button(master=fenster,text='Drehen-Cam',command=drehen)
button3=Button(master=fenster,text='Links',command=links)
button4=Button(master=fenster,text='Rechts',command=rechts)
button5=Button(master=fenster,text='Rueckwaerts',command=zurueck)


button1.pack()
button2.pack()
buttonx.pack()
buttony.pack()
button3.pack()
button4.pack()
button5.pack()

fenster.mainloop()