Código e Implementación » History » Version 20
« Previous -
Version 20/41
(diff) -
Next » -
Current version
Cesar Jimenez, 12/01/2023 08:48 AM
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤWikipedia¶
Grupo A:
Integrantes: Cristian Sánchez, Jean Pier Duran, Sergio Rabanal, Valentina Álvarez, César Jiménez
Nombre del Producto: Machine EV3 G
Modulo: Proyecto I
Docente: Humberto Urrutia
Fecha de Inicio: 2023-08-14
Fecha de Termino: 2023-11-30
ㅤㅤㅤㅤㅤㅤㅤÍndice:
- Introducción
- Descripción y Objetivos
- Organización y Planificación
- Análisis y Diseño
- Código e Implementación
- Bibliografía
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤIntefaz Gráfica¶
import tkinter as tk
from tkinter import ttk
from tkinter import *
from tkinter import messagebox
from tkinter import PhotoImage
import socket
conection = False
def stop(Event):
try:
server.send(bytes([ord(' ')]))
except BrokenPipeError:
messagebox.showwarning("Lo siento","Intentelo Nuevamente")
def Shoter():
try:
server.send(bytes([ord('r')]))
except BrokenPipeError:
messagebox.showwarning("Lo siento","Intentelo Nuevamente")
def Up():
try:
server.send(bytes([ord('w')]))
except BrokenPipeError:
messagebox.showwarning("Lo siento","Intentelo Nuevamente")
def Down():
try:
server.send(bytes([ord('s')]))
except BrokenPipeError:
messagebox.showwarning("Lo siento","Intentelo Nuevamente")
def Left():
try:
server.send(bytes([ord('a')]))
except BrokenPipeError:
messagebox.showwarning("Lo siento","Intentelo Nuevamente")
def Right():
try:
server.send(bytes([ord('d')]))
except BrokenPipeError:
messagebox.showwarning("Lo siento","Intentelo Nuevamente")
def Disconnect():
if conection:
server.send(bytes([ord('z')]))
ventana.destroy()
else:
ventana.destroy()
def Power(Pow):
if (Pow == 45):
server.send(bytes([ord('1')]))
elif (Pow == 60):
server.send(bytes([ord('2')]))
elif (Pow == 90):
server.send(bytes([ord('2')]))
else:
server.send(bytes([ord('3')]))
def conectar():
puerto = 4999
direccion = "192.168.137.147"
try:
server.connect((direccion,puerto))
messagebox.showinfo("Conectado","Se ha establecido la conexion exitosamente")
conection = True
except BrokenPipeError:
messagebox.showwarning("Desconectado","Ingrese la dirección correcta")
conection = False
# Ventana principal
ventana = tk.Tk()
ventana.geometry("750x500")
ventana.title("Machine EV3")
ventana.configure(bg="light sea green")
ventana.resizable(0,0)
# Ingresar Imagenes
up = PhotoImage(file="up.png")
down = PhotoImage(file="down.png")
left = PhotoImage(file="left.png")
right = PhotoImage(file="right.png")
cross = PhotoImage(file="cross.png")
# Dimensiones de las Imagenes
up = up.subsample(6, 6)
down = down.subsample(6, 6)
left = left.subsample(6, 6)
right = right.subsample(6, 6)
cross = cross.subsample(6, 6)
# Iniciar Servidor
server = socket.socket()
# Boton Arriba
boton_arriba = Button(None, repeatdelay=50,repeatinterval=50,text="UP", command=Up, background="cadetblue2", image=up)
boton_arriba.place(x=500, y=110)
# Boton Derecha
boton_derech = Button(None, repeatdelay=50,repeatinterval=50 ,text="RIGHT", command=Right, background="cadetblue2", image=right)
boton_derech.place(x=610, y=220)
# Boton Izquierda
boton_izq = Button(None, repeatdelay=50,repeatinterval=50, text="LEFT", command=Left, background="cadetblue2", image=left)
boton_izq.place(x=390, y=220)
# Boton Abajo
boton_abajo = Button(None, repeatdelay=50, repeatinterval=50,text="DOWN", command=Down, background="cadetblue2", image=down)
boton_abajo.place(x=500, y=330)
# Boton Disparar
boton_disparar = Button(text="SHOT", command=lambda:[Power(50)], background="cadetblue2", image=cross)
boton_disparar.place(x=130, y=270)
# Boton Power de 30°
boton_p30 = Button(text="Angle 45%", command=lambda:[Power(45)], background="cadetblue2",fg = "DodgerBlue4")
boton_p30.config(width=9, height=4)
boton_p30.place(x=50, y=230)
# Boton Power de 60°
boton_p60 = Button(text="Angle 60%", command=lambda:[Power(60)], background="cadetblue2",fg = "DodgerBlue4")
boton_p60.config(width=9, height=4)
boton_p60.place(x=140, y=170)
# Boton potenca de 90°
boton_p100 = Button(text="Angle 90%", command=lambda:[Power(90)], background="cadetblue2",fg = "DodgerBlue4")
boton_p100.config(width=9, height=4)
boton_p100.place(x=230, y=230)
# Boton ingreso ip
boton_conectar = Button(text="Conect",background="cadetblue2",fg = "DodgerBlue4",command=conectar)
boton_conectar.config(width=9, height=1)
boton_conectar.place(x=30, y=20)
# Desconectar Brick
boton_exit = Button(text="Disconnect",command = Disconnect,background="cadetblue2",fg = "DodgerBlue4")
boton_exit.config(width=9, height=1)
boton_exit.place(x=130, y=20)
# Detener Motores
boton_arriba.bind('<ButtonRelease-1>',stop)
boton_abajo.bind('<ButtonRelease-1>',stop)
boton_izq.bind('<ButtonRelease-1>',stop)
boton_derech.bind('<ButtonRelease-1>',stop)
ventana.mainloop()
Servidor¶
import socket
from Funciones import *
# Crear un socket del servreceptor
server = socket.socket()
# Vincular el socket a una dirección IP y un puerto
server.bind(('',4999))
print("CONECTADO")
# Poner el socket en modo de escucha
server.listen(5) # Permite hasta 5 conexiones pendientes
print("Esperando conexiones entrantes...")
# Aceptar una conexión entrante
socket_client, address_client = server.accept()
print("Conexion entrante desde 192.168.47.147")
while True:
recept = socket_client.recv(1).recept.decode("utf-8")
if (recept == 'w'): # arriba
Mov_Up()
if (recept == 's'): # abajo
Mov_Down()
if (recept == 'a'): # izquierda
Mov_Left()
if (recept == 'd'): # derecha
Mov_Right()
if (Id.isdigit()): # disparo por angulo
if (recept == '1'):
Angle45()
elif (recept == '2'):
Angle60()
elif (recept == '3'):
Angle90()
if (recept == 'z'): # Cierre Ventana
break
if (recept == ' '): # Detener Movimiento
Stop_Motor()
Funciones Principales del Robot¶
from ev3dev.ev3 import Sound
from ev3dev2.motor import LargeMotor,OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D, MoveTank
from time import sleep
import time
#Agregar Funciones del ROBOT
rueda_left = LargeMotor(OUTPUT_C)
rueda_right = LargeMotor(OUTPUT_B)
motor_A = LargeMotor(OUTPUT_A)
def Mov_Right():
motor_A.run_forever(speed_sp=80)
def Mov_Left():
motor_A.run_forever(speed_sp=-80)
def Mov_Down():
rueda_left.run_forever(speed_sp=500)
rueda_right.run_forever(speed_sp=500)
def Mov_Up():
rueda_left.run_forever(speed_sp=-500)
rueda_right.run_forever(speed_sp=-500)
def Stop_Motor():
rueda_left.stop()
rueda_right.stop()
motor_A.stop()
def Angle45():
motor_D = LargeMotor(OUTPUT_D)
motor_D.on_for_degrees(speed=10, degrees = 45)
motor_D.on_for_degrees(speed=100, degrees = -105)
motor_D.on_for_degrees(speed=10, degrees = 60)
motor_D.off()
def Angle60():
motor_D = LargeMotor(OUTPUT_D)
motor_D.on_for_degrees(speed=10, degrees = 60)
motor_D.on_for_degrees(speed=100, degrees = -120)
motor_D.on_for_degrees(speed=10, degrees = 60)
motor_D.off()
def Angle90():
motor_D = LargeMotor(OUTPUT_D)
motor_D.on_for_degrees(speed=10, degrees = 90)
motor_D.on_for_degrees(speed=100, degrees = -150)
motor_D.on_for_degrees(speed=10, degrees = 60)
motor_D.off()
def Sonido():
sound = Sound()
sound.beep()
sound.speak("Vini o' rey do futebol")