Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Vicente Castellano Gómez
/
robotAmbientales
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
cb2b5935
authored
May 06, 2024
by
Samuel Valverde Garcia
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
cambios
parent
3c91c677
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
37 deletions
conexion.py
conexionConfig.json
interfaz.py
main_map.py
mensajeInterfaz.py
conexion.py
View file @
cb2b5935
...
...
@@ -91,7 +91,7 @@ class Conexion:
# Función para enviar mensajes MQTT al broker
def
send_mqtt_message
(
topic
,
message
):
client
=
mqtt
.
Client
(
mqtt
.
CallbackAPIVersion
.
VERSION2
)
client
.
connect
(
"192.168.
0.19
"
,
1883
)
client
.
connect
(
"192.168.
48.245
"
,
1883
)
client
.
publish
(
topic
,
message
)
client
.
disconnect
()
...
...
conexionConfig.json
View file @
cb2b5935
{
"ipbroker"
:
"192.168.
0.19
"
,
"ipbroker"
:
"192.168.
48.245
"
,
"portbroker"
:
"1883"
,
"topicSubsRobot"
:
[
"A3-467/GrupoL/Robot"
,
"A3-467/GrupoL/SincRobot"
],
"topicSubsInterfaz"
:
[
"A3-467/GrupoL/Interfaz"
,
"map"
,
"A3-467/GrupoL/SincInterfaz"
],
...
...
interfaz.py
View file @
cb2b5935
...
...
@@ -4,6 +4,7 @@ from PIL import Image, ImageTk
import
conexion
as
cn
import
time
import
pedidos
as
pd
import
mensajeInterfaz
as
mi
# Clase que crea una ventana secundaria con la matriz de botones
class
MatrixWindow
:
...
...
@@ -88,13 +89,26 @@ class MainApp:
if
(
message
.
topic
==
"map"
):
self
.
cadena
=
str
(
message
.
payload
.
decode
(
"utf-8"
))
#Inicializa la posicion del robot
self
.
robot_position
=
None
self
.
master
=
master
master
.
title
(
"Ventana Principal"
)
self
.
left_panel
=
ttk
.
Frame
(
master
)
# Configuración de la interfaz
self
.
setup_interface
()
# Iniciar actualización periódica de la posición del robot
self
.
schedule_robot_updates
()
def
setup_interface
(
self
):
# Configuración del panel izquierdo y derecho, y otros elementos
self
.
left_panel
=
ttk
.
Frame
(
self
.
master
)
self
.
left_panel
.
pack
(
side
=
tk
.
LEFT
,
fill
=
tk
.
BOTH
,
expand
=
True
)
self
.
right_panel
=
ttk
.
Frame
(
master
)
self
.
right_panel
=
ttk
.
Frame
(
self
.
master
)
self
.
right_panel
.
pack
(
side
=
tk
.
RIGHT
,
fill
=
tk
.
BOTH
,
expand
=
True
)
ttk
.
Button
(
self
.
right_panel
,
text
=
"Añadir Peticiones"
,
command
=
self
.
open_matrix_window
)
.
pack
(
pady
=
20
)
...
...
@@ -103,25 +117,19 @@ class MainApp:
self
.
cadena
=
""
topics
=
[
"A3-467/GrupoL/Interfaz"
,
"map"
]
self
.
conex
=
cn
.
Conexion
(
topics
=
topics
,
on_msg
=
on_message
)
# Pruebas
self
.
cadena
=
"0202000105030705000200041109060110031000000200080101100110000106010701"
while
(
self
.
cadena
==
""
):
time
.
sleep
(
1
)
self
.
mensaje
=
mi
.
MensajeInterfaz
()
self
.
cadena
=
self
.
mensaje
.
getMapa
()
# Inicialización de la matriz
self
.
matriz
=
self
.
create_initial_matrix
()
#TODO enviar mapa al robot
self
.
conex
.
publicar
(
"A3-467/GrupoL/Robot"
,
self
.
cadena
)
# Cargar imágenes y mostrar matriz estática
self
.
load_images
()
self
.
labels
=
{}
self
.
display_static_matrix
()
# Carga imagenes desde un directorio y las ajusta al tamaño deseado. Si una imagen no se encuentra,
# muestra un mensaje de error y coloca una casilla gris
def
load_images
(
self
):
...
...
@@ -151,22 +159,6 @@ class MainApp:
# Crea una matriz basada en una cadena codificada que representa valores
def
create_initial_matrix
(
self
):
#self.cadena = ""
# def on_message(client, userdata, message):
# print(f'Topic:{message.topic} Mensage:{str(message.payload.decode("utf-8"))}')
# if(message.topic == "map"):
# self.cadena = str(message.payload.decode("utf-8"))
# topics = ["A3-467/GrupoL/Interfaz","map"]
# conex = cn.Conexion(topics=topics,on_msg=on_message)
# Pruebas
#self.cadena = "0202000105030705000200041109060110031000000200080101100110000106010701"
#while(self.cadena == ""):
# time.sleep(1)
segmentos
=
[
self
.
cadena
[
i
:
i
+
2
]
for
i
in
range
(
0
,
len
(
self
.
cadena
),
2
)]
matriz
=
[]
for
i
in
range
(
7
):
...
...
@@ -185,17 +177,32 @@ class MainApp:
self
.
queue_listbox
.
insert
(
tk
.
END
,
(
origen
,
destino
))
self
.
highlight_path
()
def
schedule_robot_updates
(
self
):
""" Programa la actualización de la posición del robot cada 10 segundos. """
self
.
update_robot_position
(
self
.
mensaje
.
getPosicion
())
self
.
master
.
after
(
1000
,
self
.
schedule_robot_updates
)
#Actualiza la posición del robot y actualiza el resaltado correspondiente.
def
update_robot_position
(
self
,
new_position
):
self
.
robot_position
=
mi
.
MensajeInterfaz
()
.
getPosicion
()
self
.
highlight_path
()
# Resalta los botones correspondientes al primer elemento de la Listbox
def
highlight_path
(
self
):
# Reset all labels
for
label
in
self
.
labels
.
values
():
label
.
config
(
relief
=
'flat'
,
bg
=
'SystemButtonFace'
)
# Reset all labels
# Highlight only the first item in the queue
label
.
config
(
relief
=
'flat'
,
bg
=
'SystemButtonFace'
)
if
self
.
queue_listbox
.
size
()
>
0
:
origen
,
destino
=
self
.
queue_listbox
.
get
(
0
)
# Resalta origen y destino
self
.
labels
[
origen
]
.
config
(
relief
=
'raised'
,
borderwidth
=
2
,
bg
=
'green'
)
self
.
labels
[
destino
]
.
config
(
relief
=
'raised'
,
borderwidth
=
2
,
bg
=
'red'
)
# Resalta la posición del robot si está disponible
if
self
.
robot_position
is
not
None
:
self
.
labels
[
self
.
robot_position
]
.
config
(
relief
=
'raised'
,
borderwidth
=
2
,
bg
=
'blue'
)
# Asumiendo azul para el robot
#Inicializa la aplicación
def
main
():
root
=
tk
.
Tk
()
...
...
main_map.py
View file @
cb2b5935
...
...
@@ -4,6 +4,23 @@ import time
mapa
=
"0202000105030705000200041109060110031000000200080101100110000106010701"
while
(
True
):
"""
cn.send_mqtt_message("map",mapa)
print("Enviado")
time
.
sleep
(
30
)
\ No newline at end of file
time.sleep(10)
"""
topic
=
"A3-467/GrupoL/Interfaz"
msg
=
"pos:(6,1)"
cn
.
send_mqtt_message
(
topic
,
msg
)
time
.
sleep
(
10
)
msg
=
"pos:(5,1)"
cn
.
send_mqtt_message
(
topic
,
msg
)
time
.
sleep
(
10
)
msg
=
"pos:(4,1)"
cn
.
send_mqtt_message
(
topic
,
msg
)
time
.
sleep
(
10
)
msg
=
"pos:(3,1)"
cn
.
send_mqtt_message
(
topic
,
msg
)
time
.
sleep
(
10
)
mensajeInterfaz.py
View file @
cb2b5935
...
...
@@ -66,9 +66,10 @@ class MensajeInterfaz:
defs
=
[
on_message_default
,
on_message_mapa
,
on_message_sinc
]
self
.
conex
=
cn
.
Conexion
(
self
.
topicSubs
,
on_msg
=
defs
)
self
.
mapa
=
""
self
.
posicion
:
list
self
.
posicion
=
None
self
.
pedidoSolicitado
=
False
self
.
sinc
=
False
#self.sinc = True
self
.
__sincronizacion
()
def
__sincronizacion
(
self
):
...
...
@@ -99,6 +100,7 @@ class MensajeInterfaz:
def
getPosicion
(
self
):
print
(
"Posicion"
,
self
.
posicion
)
while
(
self
.
posicion
is
None
):
print
(
"No hay posicion"
)
time
.
sleep
(
1
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment