Codigo Utilizado » History » Version 7
israel tebes, 10/18/2024 08:59 AM
1 | 1 | israel tebes | h1. Codigo Utilizado |
---|---|---|---|
2 | 1 | israel tebes | |
3 | 6 | israel tebes | *INTERFAZ* |
4 | 5 | israel tebes | |
5 | 5 | israel tebes | <pre> |
6 | 5 | israel tebes | import tkinter as tk |
7 | 5 | israel tebes | from tkinter import * |
8 | 5 | israel tebes | from tkinter import messagebox |
9 | 5 | israel tebes | from tkinter import ttk |
10 | 5 | israel tebes | import socket |
11 | 5 | israel tebes | |
12 | 5 | israel tebes | def adelante(): |
13 | 5 | israel tebes | clientSocket.send(bytes([ord('w')])) |
14 | 5 | israel tebes | |
15 | 5 | israel tebes | def atras(): |
16 | 5 | israel tebes | clientSocket.send(bytes([ord('s')])) |
17 | 5 | israel tebes | |
18 | 5 | israel tebes | def derecha(): |
19 | 5 | israel tebes | clientSocket.send(bytes([ord('d')])) |
20 | 5 | israel tebes | |
21 | 5 | israel tebes | def izquierda(): |
22 | 5 | israel tebes | clientSocket.send(bytes([ord('a')])) |
23 | 5 | israel tebes | |
24 | 5 | israel tebes | def Subir(): |
25 | 5 | israel tebes | clientSocket.send(bytes([ord('o')])) |
26 | 5 | israel tebes | |
27 | 5 | israel tebes | def Bajar(): |
28 | 5 | israel tebes | clientSocket.send(bytes([ord('i')])) |
29 | 5 | israel tebes | |
30 | 5 | israel tebes | def Agarrar(): |
31 | 5 | israel tebes | clientSocket.send(bytes([ord('k')])) |
32 | 5 | israel tebes | |
33 | 5 | israel tebes | def Soltar(): |
34 | 5 | israel tebes | clientSocket.send(bytes([ord('l')])) |
35 | 5 | israel tebes | |
36 | 5 | israel tebes | def on_release(event): |
37 | 5 | israel tebes | clientSocket.send(bytes([ord(' ')])) |
38 | 5 | israel tebes | |
39 | 5 | israel tebes | def get_ip(): |
40 | 5 | israel tebes | ventana_ip = Tk() |
41 | 5 | israel tebes | ventana_ip.geometry("300x100") |
42 | 5 | israel tebes | ventana_ip.resizable(0,0) |
43 | 5 | israel tebes | |
44 | 5 | israel tebes | ip = StringVar(ventana_ip) |
45 | 5 | israel tebes | ventana_ip.title("Configurar Ip") |
46 | 5 | israel tebes | ip_label = Label(ventana_ip, text="Ingresar Ip:").place(x=10,y=10) |
47 | 5 | israel tebes | ip_entry = ttk.Entry(ventana_ip,textvariable=ip).place(x=80,y=10) |
48 | 5 | israel tebes | button = Button(ventana_ip,text =" Aplicar",command=lambda:[conectar(ip.get(),port),ventana_ip.destroy()]).place(x=140,y=60) |
49 | 5 | israel tebes | |
50 | 5 | israel tebes | print(ip.get()) |
51 | 5 | israel tebes | |
52 | 5 | israel tebes | def conectar(adress,port): |
53 | 5 | israel tebes | try: |
54 | 5 | israel tebes | clientSocket.connect((adress,port)) |
55 | 5 | israel tebes | messagebox.showinfo("Mensaje Servido","Cliente conectado al robot: {0} : {1}".format(adress,port)) |
56 | 5 | israel tebes | except socket.error: |
57 | 5 | israel tebes | messagebox.showwarning("Conexión erronea","No se ha logrado al conexión, verifique la Ip {0}".format(adress)) |
58 | 5 | israel tebes | get_ip() |
59 | 5 | israel tebes | clientSocket.close() |
60 | 5 | israel tebes | |
61 | 5 | israel tebes | #Ventana |
62 | 5 | israel tebes | ventana = Tk() |
63 | 5 | israel tebes | ventana.geometry("500x500") |
64 | 5 | israel tebes | ventana.title("hola") |
65 | 5 | israel tebes | ventana.resizable(0,0) |
66 | 5 | israel tebes | |
67 | 5 | israel tebes | boton_adelante = Button(ventana, text= "Adelante",repeatdelay=50,repeatinterval=50,command=adelante) |
68 | 5 | israel tebes | boton_adelante.bind('<ButtonRelease-1>',on_release) |
69 | 5 | israel tebes | boton_adelante.place(x=70,y=20) |
70 | 5 | israel tebes | |
71 | 5 | israel tebes | boton_atras = Button(ventana, text= "Atrás",repeatdelay=50,repeatinterval=50,command=atras) |
72 | 5 | israel tebes | boton_atras.bind('<ButtonRelease-1>',on_release) |
73 | 5 | israel tebes | boton_atras.place(x=80,y=170) |
74 | 5 | israel tebes | |
75 | 5 | israel tebes | boton_der = Button(ventana,text= "Derecha",repeatdelay=50,repeatinterval=50,command=derecha) |
76 | 5 | israel tebes | boton_der.bind('<ButtonRelease-1>',on_release) |
77 | 5 | israel tebes | boton_der.place(x=140,y=90) |
78 | 5 | israel tebes | |
79 | 5 | israel tebes | boton_izq = Button(ventana, text = "Izquierda",repeatdelay=50,repeatinterval=50,command=izquierda) |
80 | 5 | israel tebes | boton_izq.bind('<ButtonRelease-1>',on_release) |
81 | 5 | israel tebes | boton_izq.place(x=5,y=90) |
82 | 5 | israel tebes | |
83 | 5 | israel tebes | boton_subir = tk.Button(ventana,text = "Subir",command=Subir) |
84 | 5 | israel tebes | boton_subir.bind('<ButtonRelease-1>',on_release) |
85 | 5 | israel tebes | boton_subir.place(x=0,y=0) |
86 | 5 | israel tebes | |
87 | 5 | israel tebes | boton_bajar = tk.Button(ventana,text = "Abajar",command=Bajar) |
88 | 5 | israel tebes | boton_bajar.bind('<ButtonRelease-1>',on_release) |
89 | 5 | israel tebes | boton_bajar.place(x=100,y=0) |
90 | 5 | israel tebes | |
91 | 5 | israel tebes | boton_agarrar = tk.Button(ventana,text = "Agarrar",command=Agarrar) |
92 | 5 | israel tebes | boton_agarrar.bind('<ButtonRelease-1>',on_release) |
93 | 5 | israel tebes | boton_agarrar.place(x=200,y=0) |
94 | 5 | israel tebes | |
95 | 5 | israel tebes | boton_soltar = tk.Button(ventana,text = "Soltar",command=Soltar) |
96 | 5 | israel tebes | boton_soltar.bind('<ButtonRelease-1>',on_release) |
97 | 5 | israel tebes | boton_soltar.place(x=300,y=0) |
98 | 5 | israel tebes | |
99 | 5 | israel tebes | boton_conectar = Button(ventana,text="Conectar",command=lambda:[get_ip()]).place(x=70,y=82) |
100 | 5 | israel tebes | |
101 | 5 | israel tebes | |
102 | 5 | israel tebes | clientSocket = socket.socket() |
103 | 5 | israel tebes | port = 8080 |
104 | 5 | israel tebes | |
105 | 5 | israel tebes | ventana.mainloop() |
106 | 5 | israel tebes | |
107 | 5 | israel tebes | </pre> |
108 | 7 | israel tebes | |
109 | 7 | israel tebes | |
110 | 7 | israel tebes | *FUNCIONES DEL ROBOT* |
111 | 7 | israel tebes | |
112 | 7 | israel tebes | <pre> |
113 | 7 | israel tebes | from ev3dev2.motor import LargeMotor, MediumMotor, OUTPUT_A, OUTPUT_B, OUTPUT_C$ |
114 | 7 | israel tebes | import time |
115 | 7 | israel tebes | from ev3dev2.sound import Sound |
116 | 7 | israel tebes | |
117 | 7 | israel tebes | ma = LargeMotor(OUTPUT_A) |
118 | 7 | israel tebes | mb = LargeMotor(OUTPUT_B) |
119 | 7 | israel tebes | mc = MediumMotor(OUTPUT_C) |
120 | 7 | israel tebes | md = MediumMotor(OUTPUT_D) |
121 | 7 | israel tebes | tankmoves = MoveTank(OUTPUT_A,OUTPUT_B) |
122 | 7 | israel tebes | def moveUp(): |
123 | 7 | israel tebes | print("Moving up...") |
124 | 7 | israel tebes | tankmoves.on(50,50) |
125 | 7 | israel tebes | def moveDown(): |
126 | 7 | israel tebes | print("Moving down...") |
127 | 7 | israel tebes | tankmoves.on(-50,-50) |
128 | 7 | israel tebes | def moveRight(): |
129 | 7 | israel tebes | print("Moving right...") |
130 | 7 | israel tebes | tankmoves.on(50,0) |
131 | 7 | israel tebes | def moveLeft(): |
132 | 7 | israel tebes | print("Moving left...") |
133 | 7 | israel tebes | tankmoves.on(0,50) |
134 | 7 | israel tebes | def getUp(): |
135 | 7 | israel tebes | print("upping") |
136 | 7 | israel tebes | mc.on(SpeedPercent(25)) |
137 | 7 | israel tebes | time.sleep(1) |
138 | 7 | israel tebes | mc.off() |
139 | 7 | israel tebes | def getDown(): |
140 | 7 | israel tebes | print("dowwing") |
141 | 7 | israel tebes | mc.on(SpeedPercent(-25)) |
142 | 7 | israel tebes | time.sleep(1) |
143 | 7 | israel tebes | mc.off() |
144 | 7 | israel tebes | def catch(): |
145 | 7 | israel tebes | print("caching") |
146 | 7 | israel tebes | md.on(SpeedPercent(9)) |
147 | 7 | israel tebes | time.sleep(1) |
148 | 7 | israel tebes | md.off() |
149 | 7 | israel tebes | def drop(): |
150 | 7 | israel tebes | print("droping") |
151 | 7 | israel tebes | md.on(SpeedPercent(-9)) |
152 | 7 | israel tebes | time.sleep(1) |
153 | 7 | israel tebes | md.off() |
154 | 7 | israel tebes | def stop(): |
155 | 7 | israel tebes | print("Stopping...") |
156 | 7 | israel tebes | tankmoves.off() |
157 | 7 | israel tebes | def music(): |
158 | 7 | israel tebes | print("danceeee") |
159 | 7 | israel tebes | sound = Sound() |
160 | 7 | israel tebes | sound.play_file('/home/robot/fernan_arreglado.wav') |
161 | 7 | israel tebes | </pre> |