1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
# -- IMPORTATION --
#import Tkinter as tk
import tkinter as tk
import serial
#ser = serial.Serial('/dev/ttyUSB0', 9600)
# -- VARIABLES --
serialConnection = 0
locations=['/dev/ttyUSB0', '/dev/ttyUSB1', '/dev/ttyUSB2', '/dev/ttyUSB3', '/dev/ttyS0', '/dev/ttyS1', '/dev/ttyS2', '/dev/ttyS3']
for device in locations:
try:
print("Tentative de connecion sur...",device)
ser = serial.Serial(device, 9600)
serialConnection = 1
break
except:
print("Connection échoué sur",device)
# -- CLASSE FRAME GAUCHE --
class Pan1(tk.Frame):
def __init__(self, parent):
self.parent = parent
tk.Frame.__init__(self, self.parent)
self.lFControleDirection = tk.LabelFrame(self, text="Tourner sur place", padx=20, pady=20)
self.btRG1 = tk.Button(self.lFControleDirection, text="Tourner : gauche", state=tk.DISABLED, command=tournerGaucheSurPlace)
self.btSP = tk.Button(self.lFControleDirection, text="Roues : Sur Place", state=tk.NORMAL, command=rouesSurPlace)
self.btRD1 = tk.Button(self.lFControleDirection, text="Tourner : droite", state=tk.DISABLED, command=tournerDroiteSurPlace)
self.btRC1 = tk.Button(self.lFControleDirection, text="Roues : Centre", state=tk.DISABLED, command=rouesCentre)
#Positionnement dans la grille
self.lFControleDirection.grid(column=0, row=0)
self.btRG1.grid(column=0, row=0)
self.btSP.grid(column=1, row=0)
self.btRD1.grid(column=2, row=0)
self.btRC1.grid(column=1, row=1)
# -- CLASSE FRAME CENTRALE --
class Pan2(tk.Frame):
def __init__(self, parent):
self.parent = parent
tk.Frame.__init__(self, self.parent)
self.lFSpeed = tk.LabelFrame(self, text="Vitesse", padx=20, pady=20)
self.lFSpeed.grid(column=0, row=0, sticky='NS')
self.sliderSpeed = tk.Scale(self.lFSpeed, from_=100, to=50, tickinterval=2)
self.sliderSpeed.grid(column=0, row=0)
# -- CLASSE FRAME DROITE --
class Pan3(tk.Frame):
def __init__(self, parent):
self.parent = parent
tk.Frame.__init__(self, self.parent)
self.lFControleDirect = tk.LabelFrame(self, text="Controle", padx=20, pady=20)
#if btnsDroite == 0 :
self.btAV = tk.Button(self.lFControleDirect, text="Avancer", state=tk.NORMAL, command=avancer)
self.btRG2 = tk.Button(self.lFControleDirect, text="Roues : Gauche", state=tk.NORMAL, command=rouesGauche)
self.btRC2 = tk.Button(self.lFControleDirect, text="Roue : Centre", state=tk.NORMAL, command=rouesCentre)
self.btRD2 = tk.Button(self.lFControleDirect, text="Roues : Droite", state=tk.NORMAL, command=rouesDroite)
self.btAR = tk.Button(self.lFControleDirect, text="Reculer", state=tk.NORMAL, command=reculer)
self.btDG1 = tk.Button(self.lFControleDirect, text="Reculer", state=tk.NORMAL, command=rouesDiagonaleGauche)
self.btDD1 = tk.Button(self.lFControleDirect, text="Reculer", state=tk.NORMAL, command=rouesDiagonaleDroite)
self.btDG1 = tk.Button(self.lFControleDirect, text="Roues : Diagonale à gauche", state=tk.NORMAL, command=rouesDiagonaleGauche)
self.btDD1 = tk.Button(self.lFControleDirect, text="Roues : Diagonale à droite", state=tk.NORMAL, command=rouesDiagonaleDroite)
#Positionnement dans la grille
self.lFControleDirect.grid(column=1, row=0, sticky='NS')
self.btAV.grid(column=1, row=0)
self.btRG2.grid(column=0, row=1)
self.btRC2.grid(column=1, row=1)
self.btRD2.grid(column=2, row=1)
self.btAR.grid(column=1, row=2)
self.btDG1.grid(column=0, row=3)
self.btDD1.grid(column=2, row=3)
# -- CLASSE FRAME DESSOUS (LOG) --
class Pan4(tk.Frame):
def __init__(self, parent):
self.parent = parent
tk.Frame.__init__(self, self.parent)
self.log = tk.Text(self, height=10, width=100, wrap = tk.WORD)
self.log.grid(column=0, row=0)
self.log.insert('1.0', 'Log du programme')
# -- FONCTION TOURNER A GAUCHE SUR PLACE --
def tournerGaucheSurPlace():
print("Tourner a gauche sur place")
if serialConnection == 1:
ser.write("!,1,0,100,1,100,0,100,1,100,*")
# -- FONCTION ROUES SUR PLACE --
def rouesSurPlace():
if self.btRG1["state"] == "normal":
self.btRG1.configure(state = tk.DISABLED)
else:
self.btRG1.configure(state = tk.NORMAL)
print("Roues sur place")
# -- FONCTION TOURNER A DROITE SUR PLACE --
def tournerDroiteSurPlace():
print("Tourner a droite sur place")
# -- FONCTION ROUES AU CENTRE --
def rouesCentre():
print("Roues au centre")
# -- FONCTION AVANCER --
def avancer():
print("Avancer")
# -- FONCTION ROUES A GAUCHE --
def rouesGauche():
print("Roue a gauche")
# -- FONCTION ROUES A DROITE --
def rouesDroite():
print("Roue a droite")
# -- FONCTION RECULER --
def reculer():
print("Reculer")
# -- FONCTION ROUES DIAGONALE A GAUCHE --
def rouesDiagonaleGauche():
print("Roue diagonale a gauche")
# -- FONCTION ROUES DIAGONALE A DROITE --
def rouesDiagonaleDroite():
print("Roue diagonale a droite")
mon_app = tk.Tk() #Instancie la classe
pan1=Pan1(mon_app) #Panneau Gauche
pan1.grid(column = 0, row = 0, sticky='N')
pan2=Pan2(mon_app) #PAnneau Centrale
pan2.grid(column = 1, row = 0, sticky='N')
pan3=Pan3(mon_app) #PAnneau Droite
pan3.grid(column = 2, row = 0, sticky='N')
pan4=Pan4(mon_app) #PAnneau Dessous (LOG)
pan4.grid(column = 0, row = 1, columnspan = 3)
mon_app.title('POSL Rover')
mon_app.mainloop() #Boucler |
Partager