Desarrollo del Prototipo » History » Version 76
antonella butron, 11/17/2024 10:50 PM
1 | 33 | antonella butron | ---- |
---|---|---|---|
2 | 33 | antonella butron | |
3 | 34 | antonella butron | h1=. %{color: purple}Desarrollo del Prototipo% |
4 | 1 | antonella butron | |
5 | 32 | bastian cruz | h1=. %{color: purple}Avance del robot EV3% |
6 | 8 | antonella butron | |
7 | 72 | antonella butron | h1=. "Robot se mueve solo":https://youtube.com/shorts/gr5waMOEi_Q?si=b0sV5mOU094Sfs_I (video) |
8 | 71 | antonella butron | |
9 | 72 | antonella butron | h1=. "Movimiento de la Garra":https://youtube.com/shorts/DefEWpvIxXI?si=5R5jll9lt9r1wHsJ (video) |
10 | 69 | antonella butron | |
11 | 69 | antonella butron | |
12 | 1 | antonella butron | |
13 | 64 | antonella butron | table{border-collapse: collapse; width: 100%; text-align:center}. |
14 | 62 | antonella butron | |{border: 1px solid black; background-color:#D8BFD8; font-size: 15px; text-align:center}. *Versión* |{border: 1px solid black; background-color:#D8BFD8; font-size: 15px; text-align:center}. *Imagen* | |
15 | 66 | antonella butron | |{border: 1px solid black;text-align:center; background-color: #F7F2F7;}. _Versión Beta_ |{border: 1px solid black; text-align:center; background-color: #F7F2F7;}. !vprueba.jpg! | |
16 | 67 | antonella butron | |{border: 1px solid black;text-align:center; background-color: #F7F2F7;}. _Versión 1_ |{border: 1px solid black;text-align:center; background-color: #F7F2F7;}. !V1.jpg! | |
17 | 66 | antonella butron | |{border: 1px solid black;text-align:center; background-color: #F7F2F7;}. _Versión 2_ |{border: 1px solid black;text-align:center; background-color: #F7F2F7;}. !V2.jpg! | |
18 | 66 | antonella butron | |{border: 1px solid black;text-align:center; background-color: #F7F2F7;}. _Versión 3_ |{border: 1px solid black;text-align:center; background-color: #F7F2F7;}. !V3.jpg! | |
19 | 66 | antonella butron | |{border: 1px solid black;text-align:center; background-color: #F7F2F7;}. _Versión 4_ |{border: 1px solid black;text-align:center; background-color: #F7F2F7;}. !V4.jpg! | |
20 | 66 | antonella butron | |{border: 1px solid black;text-align:center; background-color: #F7F2F7;}. _Versión 5_ |{border: 1px solid black;text-align:center; background-color: #F7F2F7;}. !V5.jpg! | |
21 | 66 | antonella butron | |{border: 1px solid black;text-align:center; background-color: #F7F2F7;}. _Versión 6_ |{border: 1px solid black;text-align:center; background-color: #F7F2F7;}. !V6A.jpg! | |
22 | 66 | antonella butron | |{border: 1px solid black;text-align:center; background-color: #F7F2F7;}. _Versión 7_ |{border: 1px solid black;text-align:center; background-color: #F7F2F7;}. !V7final.jpg! | |
23 | 57 | antonella butron | |
24 | 54 | antonella butron | |
25 | 54 | antonella butron | |
26 | 54 | antonella butron | |
27 | 27 | antonella butron | h1=. **Código Utilizado** |
28 | 33 | antonella butron | |
29 | 73 | antonella butron | Interfaz Gráfica |
30 | 73 | antonella butron | |
31 | 73 | antonella butron | |
32 | 76 | antonella butron | <pre> |
33 | 76 | antonella butron | import socket |
34 | 76 | antonella butron | import tkinter as tk |
35 | 76 | antonella butron | from tkinter import font, messagebox |
36 | 76 | antonella butron | import threading |
37 | 73 | antonella butron | |
38 | 76 | antonella butron | class EV3ControlApp: |
39 | 76 | antonella butron | contador_subir = 0 |
40 | 76 | antonella butron | contador_bajar = 1 |
41 | 76 | antonella butron | contador_abrir = 1 |
42 | 76 | antonella butron | contador_cerrar = 0 |
43 | 76 | antonella butron | |
44 | 76 | antonella butron | def __init__(self, master): |
45 | 76 | antonella butron | self.master = master |
46 | 76 | antonella butron | self.master.title("EV3 Control Panel") |
47 | 76 | antonella butron | self.master.configure(bg='#1a1a1a') |
48 | 76 | antonella butron | self.master.geometry('600x400') |
49 | 76 | antonella butron | |
50 | 76 | antonella butron | self.sock = None |
51 | 76 | antonella butron | |
52 | 76 | antonella butron | # Configuración de columnas y filas |
53 | 76 | antonella butron | self.master.grid_columnconfigure(0, weight=1) |
54 | 76 | antonella butron | self.master.grid_columnconfigure(1, weight=1) |
55 | 76 | antonella butron | self.master.grid_columnconfigure(2, weight=1) |
56 | 76 | antonella butron | self.master.grid_columnconfigure(3, weight=1) |
57 | 76 | antonella butron | self.master.grid_rowconfigure(10, weight=1) |
58 | 76 | antonella butron | self.master.grid_rowconfigure(11, weight=1) |
59 | 76 | antonella butron | self.master.grid_rowconfigure(12, weight=1) |
60 | 76 | antonella butron | self.master.grid_rowconfigure(13, weight=1) |
61 | 76 | antonella butron | self.master.grid_rowconfigure(14, weight=1) |
62 | 76 | antonella butron | self.master.grid_rowconfigure(15, weight=1) |
63 | 76 | antonella butron | |
64 | 76 | antonella butron | # Configuración de fuentes y estilo |
65 | 76 | antonella butron | self.btn_font = font.Font(family='Helvetica', size=14, weight='bold') |
66 | 76 | antonella butron | self.bg_color = '#2e2e2e' |
67 | 76 | antonella butron | self.fg_color = 'white' |
68 | 76 | antonella butron | self.active_bg = '#4d4d4d' |
69 | 76 | antonella butron | self.padx = 15 |
70 | 76 | antonella butron | self.pady = 15 |
71 | 76 | antonella butron | |
72 | 76 | antonella butron | # Crear widgets |
73 | 76 | antonella butron | self.create_widgets() |
74 | 76 | antonella butron | |
75 | 76 | antonella butron | def create_widgets(self): |
76 | 76 | antonella butron | self.ip_label = tk.Label(self.master, text="IP del EV3:", font=self.btn_font, bg=self.master['bg'], fg=self.fg_color) |
77 | 76 | antonella butron | self.ip_label.grid(row=10, column=1, padx=self.padx, pady=self.pady) |
78 | 76 | antonella butron | |
79 | 76 | antonella butron | self.ip_entry = tk.Entry(self.master, font=self.btn_font, bg=self.bg_color, fg=self.fg_color) |
80 | 76 | antonella butron | self.ip_entry.grid(row=10, column=2, padx=self.padx, pady=self.pady) |
81 | 76 | antonella butron | |
82 | 76 | antonella butron | self.btn_connect = tk.Button(self.master, text="Conectar", font=self.btn_font, bg=self.bg_color, fg=self.fg_color, |
83 | 76 | antonella butron | activebackground=self.active_bg, command=self.start_connect_thread) |
84 | 76 | antonella butron | self.btn_connect.grid(row=10, column=3, padx=self.padx, pady=self.pady) |
85 | 76 | antonella butron | |
86 | 76 | antonella butron | # Botones de control de movimiento |
87 | 76 | antonella butron | self.btn_up = tk.Button(self.master, text="▲", font=self.btn_font, bg=self.bg_color, fg=self.fg_color, |
88 | 76 | antonella butron | activebackground=self.active_bg, command=self.move_up) |
89 | 76 | antonella butron | self.btn_up.grid(row=11, column=1, padx=self.padx, pady=self.pady, sticky="nsew") |
90 | 76 | antonella butron | |
91 | 76 | antonella butron | self.btn_left = tk.Button(self.master, text="", font=self.btn_font, bg=self.bg_color, fg=self.fg_color, |
92 | 76 | antonella butron | activebackground=self.active_bg, command=self.move_left) |
93 | 76 | antonella butron | self.btn_left.grid(row=12, column=0, padx=self.padx, pady=self.pady, sticky="nsew") |
94 | 76 | antonella butron | |
95 | 76 | antonella butron | self.btn_stop = tk.Button(self.master, text="■", font=self.btn_font, bg=self.bg_color, fg=self.fg_color, |
96 | 76 | antonella butron | activebackground=self.active_bg, command=self.stop) |
97 | 76 | antonella butron | self.btn_stop.grid(row=12, column=1, padx=self.padx, pady=self.pady, sticky="nsew") |
98 | 76 | antonella butron | |
99 | 76 | antonella butron | self.btn_right = tk.Button(self.master, text="", font=self.btn_font, bg=self.bg_color, fg=self.fg_color, |
100 | 76 | antonella butron | activebackground=self.active_bg, command=self.move_right) |
101 | 76 | antonella butron | self.btn_right.grid(row=12, column=2, padx=self.padx, pady=self.pady, sticky="nsew") |
102 | 76 | antonella butron | |
103 | 76 | antonella butron | self.btn_down = tk.Button(self.master, text="▼", font=self.btn_font, bg=self.bg_color, fg=self.fg_color, |
104 | 76 | antonella butron | activebackground=self.active_bg, command=self.move_down) |
105 | 76 | antonella butron | self.btn_down.grid(row=13, column=1, padx=self.padx, pady=self.pady, sticky="nsew") |
106 | 76 | antonella butron | |
107 | 76 | antonella butron | self.btn_claw_updown = tk.Button(self.master, text="Subir/Bajar garra", font=self.btn_font, bg=self.bg_color, fg=self.fg_color, |
108 | 76 | antonella butron | activebackground=self.active_bg, command=self.handle_updown) |
109 | 76 | antonella butron | self.btn_claw_updown.grid(row=12, column=3, padx=self.padx, pady=self.pady, sticky="nsew") |
110 | 76 | antonella butron | |
111 | 76 | antonella butron | self.btn_claw_openclose = tk.Button(self.master, text="Abrir/Cerrar garra", font=self.btn_font, bg=self.bg_color, fg=self.fg_color, |
112 | 76 | antonella butron | activebackground=self.active_bg, command=self.handle_openclose) |
113 | 76 | antonella butron | self.btn_claw_openclose.grid(row=13, column=3, padx=self.padx, pady=self.pady, sticky="nsew") |
114 | 76 | antonella butron | |
115 | 76 | antonella butron | self.btn_stop_handle = tk.Button(self.master, text="Parar garra", font=self.btn_font, bg=self.bg_color, fg=self.fg_color, |
116 | 76 | antonella butron | activebackground='#ff4c4c', command=self.stop_handle) |
117 | 76 | antonella butron | self.btn_stop_handle.grid(row=14, column=3, columnspan=2, padx=self.padx, pady=self.pady, sticky="nsew") |
118 | 76 | antonella butron | |
119 | 76 | antonella butron | self.btn_quit = tk.Button(self.master, text="Cerrar servidor", font=self.btn_font, bg='#ff5c5c', fg=self.fg_color, |
120 | 76 | antonella butron | activebackground='#ff4c4c', command=self.quit_app) |
121 | 76 | antonella butron | self.btn_quit.grid(row=15, column=1, columnspan=2, padx=self.padx, pady=self.pady, sticky="nsew") |
122 | 76 | antonella butron | |
123 | 76 | antonella butron | def start_connect_thread(self): |
124 | 76 | antonella butron | ip = self.ip_entry.get() |
125 | 76 | antonella butron | if self.is_valid_ip(ip): |
126 | 76 | antonella butron | threading.Thread(target=self.connect, args=(ip,), daemon=True).start() |
127 | 76 | antonella butron | else: |
128 | 76 | antonella butron | messagebox.showerror("Error de entrada", "La dirección IP ingresada no es válida.") |
129 | 76 | antonella butron | |
130 | 76 | antonella butron | def is_valid_ip(self, ip): |
131 | 76 | antonella butron | parts = ip.split('.') |
132 | 76 | antonella butron | if len(parts) != 4: |
133 | 76 | antonella butron | return False |
134 | 76 | antonella butron | for part in parts: |
135 | 76 | antonella butron | if not part.isdigit() or not (0 <= int(part) < 256): |
136 | 76 | antonella butron | return False |
137 | 76 | antonella butron | return True |
138 | 76 | antonella butron | |
139 | 76 | antonella butron | def connect(self, ip): |
140 | 76 | antonella butron | try: |
141 | 76 | antonella butron | if self.sock is not None: |
142 | 76 | antonella butron | self.sock.close() |
143 | 76 | antonella butron | self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
144 | 76 | antonella butron | self.sock.connect((ip, 8080)) |
145 | 76 | antonella butron | messagebox.showinfo("Conexión", "Conectado correctamente al EV3.") |
146 | 76 | antonella butron | self.enable_controls(True) |
147 | 76 | antonella butron | except Exception as e: |
148 | 76 | antonella butron | messagebox.showerror("Error de conexión", f"No se pudo conectar a {ip}. \n{str(e)}") |
149 | 76 | antonella butron | self.enable_controls(False) |
150 | 76 | antonella butron | |
151 | 76 | antonella butron | def enable_controls(self, state): |
152 | 76 | antonella butron | self.btn_up.config(state=tk.NORMAL if state else tk.DISABLED) |
153 | 76 | antonella butron | self.btn_left.config(state=tk.NORMAL if state else tk.DISABLED) |
154 | 76 | antonella butron | self.btn_stop.config(state=tk.NORMAL if state else tk.DISABLED) |
155 | 76 | antonella butron | self.btn_right.config(state=tk.NORMAL if state else tk.DISABLED) |
156 | 76 | antonella butron | self.btn_down.config(state=tk.NORMAL if state else tk.DISABLED) |
157 | 76 | antonella butron | self.btn_claw_updown.config(state=tk.NORMAL if state else tk.DISABLED) |
158 | 76 | antonella butron | self.btn_claw_openclose.config(state=tk.NORMAL if state else tk.DISABLED) |
159 | 76 | antonella butron | self.btn_stop_handle.config(state=tk.NORMAL if state else tk.DISABLED) |
160 | 76 | antonella butron | self.btn_quit.config(state=tk.NORMAL if state else tk.DISABLED) |
161 | 76 | antonella butron | |
162 | 76 | antonella butron | def send_command(self, command): |
163 | 76 | antonella butron | if self.sock: |
164 | 76 | antonella butron | self.sock.sendall(command.encode('utf-8')) |
165 | 76 | antonella butron | |
166 | 76 | antonella butron | def move_up(self): |
167 | 76 | antonella butron | self.send_command('w') |
168 | 76 | antonella butron | |
169 | 76 | antonella butron | def move_down(self): |
170 | 76 | antonella butron | self.send_command('s') |
171 | 76 | antonella butron | |
172 | 76 | antonella butron | def move_left(self): |
173 | 76 | antonella butron | self.send_command('a') |
174 | 76 | antonella butron | |
175 | 76 | antonella butron | def move_right(self): |
176 | 76 | antonella butron | self.send_command('d') |
177 | 76 | antonella butron | |
178 | 76 | antonella butron | def stop(self): |
179 | 76 | antonella butron | self.send_command('x') |
180 | 76 | antonella butron | |
181 | 76 | antonella butron | def handle_updown(self): |
182 | 76 | antonella butron | if EV3ControlApp.contador_bajar == 0: |
183 | 76 | antonella butron | self.send_command('g') |
184 | 76 | antonella butron | EV3ControlApp.contador_bajar += 1 |
185 | 76 | antonella butron | EV3ControlApp.contador_subir = 0 |
186 | 76 | antonella butron | else: |
187 | 76 | antonella butron | self.send_command('t') |
188 | 76 | antonella butron | EV3ControlApp.contador_subir += 1 |
189 | 76 | antonella butron | EV3ControlApp.contador_bajar = 0 |
190 | 76 | antonella butron | |
191 | 76 | antonella butron | def handle_openclose(self): |
192 | 76 | antonella butron | if EV3ControlApp.contador_cerrar == 0: |
193 | 76 | antonella butron | self.send_command('f') |
194 | 76 | antonella butron | EV3ControlApp.contador_cerrar += 1 |
195 | 76 | antonella butron | EV3ControlApp.contador_abrir = 0 |
196 | 76 | antonella butron | else: |
197 | 76 | antonella butron | self.send_command('r') |
198 | 76 | antonella butron | EV3ControlApp.contador_abrir += 1 |
199 | 76 | antonella butron | EV3ControlApp.contador_cerrar = 0 |
200 | 76 | antonella butron | |
201 | 76 | antonella butron | def stop_handle(self): |
202 | 76 | antonella butron | self.send_command('c') |
203 | 76 | antonella butron | |
204 | 76 | antonella butron | def quit_app(self): |
205 | 76 | antonella butron | if EV3ControlApp.contador_abrir == 0: |
206 | 76 | antonella butron | self.send_command('r') |
207 | 76 | antonella butron | if EV3ControlApp.contador_bajar == 0: |
208 | 76 | antonella butron | self.send_command('g') |
209 | 76 | antonella butron | self.send_command('c') |
210 | 76 | antonella butron | self.send_command('q') |
211 | 76 | antonella butron | self.sock.close() |
212 | 76 | antonella butron | self.master.quit() |
213 | 76 | antonella butron | |
214 | 76 | antonella butron | if __name__ == "__main__": |
215 | 76 | antonella butron | root = tk.Tk() |
216 | 76 | antonella butron | app = EV3ControlApp(root) |
217 | 76 | antonella butron | root.mainloop() |
218 | 76 | antonella butron | <pre> |
219 | 73 | antonella butron | |
220 | 73 | antonella butron | |
221 | 73 | antonella butron | |
222 | 47 | bastian cruz | --- |