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
538747d1
authored
Apr 29, 2024
by
Alfonso Manuel
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Envia mapa al robot
parent
d9d76bbb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
254 deletions
camino.py
prueba.py → interfaz.py
pedidos.py
camino.py
deleted
100644 → 0
View file @
d9d76bbb
from
enum
import
Enum
class
Bloque
(
Enum
):
Edificio
=
0
Calle_Izquierda_Derecha
=
1
Calle_Arriba_Abajo
=
2
Calle_Arriba_Derecha
=
3
Calle_Derecha_Abajo
=
4
Calle_Abajo_Izquierda
=
5
Calle_Izquierda_Arriba
=
6
Calle_Izquierda_Arriba_Derecha
=
7
Calle_Arriba_Derecha_Abajo
=
8
Calle_Derecha_Abajo_Izquierda
=
9
Calle_Abajo_Izquierda_Arriba
=
10
Calle_Arriba_Derecha_Abajo_Izquierda
=
11
class
Direccion
(
Enum
):
Arriba
=
0
Derecha
=
1
Abajo
=
2
Izquierda
=
3
class
Casilla
:
def
__init__
(
self
,
x
:
int
,
y
:
int
,
codigo_bloque
:
str
):
self
.
x
=
x
self
.
y
=
y
self
.
bloque
=
Bloque
(
int
(
codigo_bloque
))
def
__str__
(
self
):
return
f
'x : {self.x} | y : {self.y} | {self.bloque}'
def
encontrarCamino
(
matriz
,
posicionInicial
,
posicionFinal
):
#distOptima : int = maxsize
def
matrizAdyacencia
(
matriz
):
def
convertirMatrizCasillas
(
matriz
):
matCas
=
[]
for
i
in
range
(
len
(
matriz
)):
fila
=
[]
for
j
in
range
(
len
(
matriz
[
0
])):
fila
.
append
(
Casilla
(
i
,
j
,
matriz
[
i
][
j
]))
matCas
.
append
(
fila
)
return
matCas
def
dentroTablero
(
coord
):
if
(
coord
[
0
]
<
len
(
matriz
)
and
coord
[
0
]
>=
0
and
coord
[
1
]
<
len
(
matriz
[
0
])
and
coord
[
1
]
>=
0
):
return
True
return
False
matrizCasillas
=
convertirMatrizCasillas
(
matriz
=
matriz
)
matrizAdy
=
[]
for
i
in
range
(
len
(
matriz
)):
fila
=
[]
for
j
in
range
(
len
(
matriz
[
0
])):
fila
.
append
(
matrizCasillas
[
i
][
j
]
.
bloque
.
value
)
matrizAdy
.
append
(
fila
)
return
matrizAdy
matriz
=
matrizAdyacencia
(
matriz
)
solOptima
=
[]
direcOptima
=
[]
sol
=
[
posicionInicial
]
direcciones
=
[]
def
caminoVueltraAtras
(
direccion
,
posicion
):
global
distOptima
#print(sol)
def
factible
(
direc
,
pos
):
def
movimientoAceptado
(
direccion
:
Direccion
,
bloque
:
int
,
bloqueSiguiente
:
int
):
def
moviAcept
(
direccion
:
Direccion
,
bloque
:
int
):
#print(direccion.name, bloque)
if
(
direccion
==
Direccion
.
Arriba
):
#arriba = [2,4,5,8,9,10,11]
arriba
=
[
2
,
3
,
6
,
7
,
8
,
10
,
11
]
if
(
bloque
in
arriba
):
return
True
return
False
if
(
direccion
==
Direccion
.
Abajo
):
#abajo = [2,3,6,7,8,10,11]
abajo
=
[
2
,
4
,
5
,
8
,
9
,
10
,
11
]
if
(
bloque
in
abajo
):
return
True
return
False
#if(bloquePosterio.value == 2 or bloquePosterio.value == 3
# or bloquePosterio.value == 6 or bloquePosterio.value == 7
# or bloquePosterio.value == 10 or bloquePosterio.value == 11):
# return True
#return False
if
(
direccion
==
Direccion
.
Izquierda
):
#izquierda = [1,3,4,7,8,9,11]
izquierda
=
[
1
,
5
,
6
,
7
,
9
,
10
,
11
]
if
(
bloque
in
izquierda
):
return
True
return
False
if
(
direccion
==
Direccion
.
Derecha
):
#derecha = [1,6,7,9,10,11]
derecha
=
[
1
,
3
,
4
,
7
,
8
,
9
,
11
]
if
(
bloque
in
derecha
):
return
True
return
False
direcSiguiente
=
Direccion
((
direccion
.
value
+
2
)
%
4
)
if
(
moviAcept
(
direccion
,
bloque
)
and
moviAcept
(
direcSiguiente
,
bloqueSiguiente
)):
return
True
return
False
#pos = sol[-1]
if
(
pos
==
posicionInicial
):
#print(f"Descartado Inicio {direccion} : {pos}")
return
False
if
(
pos
in
sol
):
#print(f"Descartado Usada {direccion} : {pos}")
return
False
if
(
pos
[
0
]
<
0
or
pos
[
0
]
>=
len
(
matriz
)
or
pos
[
1
]
<
0
or
pos
[
1
]
>=
len
(
matriz
[
0
])):
#print(f"Descartado Fuera de Rango {direccion} : {pos}")
return
False
if
(
matriz
[
pos
[
0
]][
pos
[
1
]]
==
0
):
#print(f"Descartado Edificio {direccion} : {pos}")
return
False
if
(
not
movimientoAceptado
(
direc
,
matriz
[
sol
[
-
1
][
0
]][
sol
[
-
1
][
1
]],
matriz
[
pos
[
0
]][
pos
[
1
]])):
#print(f"Descartado Movimiento no aceptado {direccion} : {sol[-1]}")
return
False
#if(len(sol)+1 >= distOptima):
if
(
len
(
solOptima
)
>
0
):
if
(
len
(
sol
)
+
1
>=
len
(
solOptima
)):
#print(f"Descartado Muy Largo {direccion} : {pos}")
return
False
return
True
if
(
factible
(
direccion
,
posicion
)):
sol
.
append
(
posicion
)
direcciones
.
append
(
direccion
)
pos
=
sol
[
-
1
]
#bq = mAdy[pos[0]][pos[1]]
#mAdy[pos[0]][pos[1]] = 0
if
(
pos
!=
posicionFinal
):
caminoVueltraAtras
(
Direccion
.
Arriba
,(
pos
[
0
]
-
1
,
pos
[
1
]))
caminoVueltraAtras
(
Direccion
.
Abajo
,(
pos
[
0
]
+
1
,
pos
[
1
]))
caminoVueltraAtras
(
Direccion
.
Derecha
,(
pos
[
0
],
pos
[
1
]
+
1
))
caminoVueltraAtras
(
Direccion
.
Izquierda
,(
pos
[
0
],
pos
[
1
]
-
1
))
else
:
if
(
len
(
solOptima
)
>
0
):
if
(
len
(
sol
)
<
len
(
solOptima
)):
#distOptima = len(sol)
solOptima
.
clear
()
direcOptima
.
clear
()
for
i
in
range
(
len
(
direcciones
)):
solOptima
.
append
(
sol
[
i
])
direcOptima
.
append
(
direcciones
[
i
])
solOptima
.
append
(
sol
[
-
1
])
else
:
#distOptima = len(sol)
solOptima
.
clear
()
direcOptima
.
clear
()
for
i
in
range
(
len
(
direcciones
)):
solOptima
.
append
(
sol
[
i
])
direcOptima
.
append
(
direcciones
[
i
])
solOptima
.
append
(
sol
[
-
1
])
#mAdy[pos[0]][pos[1]] = bq
sol
.
pop
()
direcciones
.
pop
()
caminoVueltraAtras
(
Direccion
.
Arriba
,(
posicionInicial
[
0
]
-
1
,
posicionInicial
[
1
]))
caminoVueltraAtras
(
Direccion
.
Abajo
,(
posicionInicial
[
0
]
+
1
,
posicionInicial
[
1
]))
caminoVueltraAtras
(
Direccion
.
Derecha
,(
posicionInicial
[
0
],
posicionInicial
[
1
]
+
1
))
caminoVueltraAtras
(
Direccion
.
Abajo
,(
posicionInicial
[
0
],
posicionInicial
[
1
]
-
1
))
# Devuelve el recogido realizado tanto en posiciones como en direcciones
#return solOptima,direcOptima
return
direcOptima
#02 02 00 01 05
#03 07 05 00 02
#00 04 11 09 06
#01 10 03 10 00
#00 02 00 08 01
#01 10 01 10 00
#01 06 01 07 01
matriz
=
[[
"02"
,
"02"
,
"00"
,
"01"
,
"05"
],
[
"03"
,
"07"
,
"05"
,
"00"
,
"02"
],
[
"00"
,
"04"
,
"11"
,
"09"
,
"06"
],
[
"01"
,
"10"
,
"03"
,
"10"
,
"00"
],
[
"00"
,
"02"
,
"00"
,
"08"
,
"01"
],
[
"01"
,
"10"
,
"01"
,
"10"
,
"00"
],
[
"01"
,
"06"
,
"01"
,
"07"
,
"01"
]]
#mAdy = matrizAdyacencia(matriz)
#pos = mAdy[6][0]
#mAdy[6][0] = 2
sol
=
encontrarCamino
(
matriz
,(
5
,
2
),(
6
,
0
))
#mAdy[6][0] = pos
for
s
in
sol
:
print
(
s
)
\ No newline at end of file
prueba
.py
→
interfaz
.py
View file @
538747d1
...
...
@@ -3,6 +3,7 @@ from tkinter import ttk
from
PIL
import
Image
,
ImageTk
import
conexion
as
cn
import
time
import
pedidos
as
pd
# Clase que crea una ventana secundaria con la matriz de botones
class
MatrixWindow
:
...
...
@@ -77,7 +78,16 @@ class MatrixWindow:
# Clase principal que gestiona la ventana principal de la aplicación
class
MainApp
:
def
__init__
(
self
,
master
):
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"
))
self
.
master
=
master
master
.
title
(
"Ventana Principal"
)
...
...
@@ -91,7 +101,23 @@ class MainApp:
self
.
queue_listbox
=
tk
.
Listbox
(
self
.
right_panel
,
width
=
40
,
height
=
10
)
self
.
queue_listbox
.
pack
(
padx
=
20
,
pady
=
20
)
self
.
matriz
=
self
.
create_initial_matrix
()
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
.
matriz
=
self
.
create_initial_matrix
()
#TODO enviar mapa al robot
self
.
conex
.
publicar
(
"A3-467/GrupoL/Robot"
,
self
.
cadena
)
self
.
load_images
()
self
.
labels
=
{}
self
.
display_static_matrix
()
...
...
@@ -125,7 +151,7 @@ class MainApp:
# Crea una matriz basada en una cadena codificada que representa valores
def
create_initial_matrix
(
self
):
self
.
cadena
=
""
#
self.cadena = ""
# def on_message(client, userdata, message):
# print(f'Topic:{message.topic} Mensage:{str(message.payload.decode("utf-8"))}')
...
...
@@ -135,16 +161,19 @@ class MainApp:
# conex = cn.Conexion(topics=topics,on_msg=on_message)
# Pruebas
self
.
cadena
=
"0202000105030705000200041109060110031000000200080101100110000106010701"
#
self.cadena = "0202000105030705000200041109060110031000000200080101100110000106010701"
while
(
self
.
cadena
==
""
):
time
.
sleep
(
1
)
#
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
):
fila
=
segmentos
[
i
*
5
:(
i
+
1
)
*
5
]
matriz
.
append
(
fila
)
return
matriz
# Inicia la ventana secundaria MatrixWindow
...
...
pedidos.py
View file @
538747d1
...
...
@@ -124,16 +124,16 @@ def ordenarPedidos(posicionActual : Posicion,lista : list):
posicionInicio
=
Posicion
(
6
,
0
)
#
posicionInicio = Posicion(6,0)
listaPed
=
[]
listaPed
.
append
(((
6
,
4
),(
0
,
3
)))
listaPed
.
append
(((
0
,
1
),(
3
,
0
)))
#
listaPed = []
#
listaPed.append(((6,4),(0,3)))
#
listaPed.append(((0,1),(3,0)))
#listap = transformarAPedidos(posicionInicio,listaPed)
peds
=
ordenarPedidos
(
posicionActual
=
posicionInicio
,
lista
=
listaPed
)
for
p
in
peds
:
print
(
p
)
#
peds = ordenarPedidos(posicionActual=posicionInicio,lista=listaPed)
#
for p in peds:
#
print(p)
#print(transformarAPedidos(listaPed))
\ No newline at end of file
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