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
2a69bc65
authored
May 03, 2024
by
Vicente Castellano Gómez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Va en linea recta, corregir giro cuenta una de mas
parent
e44f62a3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
20 deletions
main.py
robot.py
main.py
View file @
2a69bc65
...
...
@@ -12,9 +12,9 @@ robot = Robot()
robot
.
sigueLineaHastaNegro
()
robot
.
sigueLineaHastaNegro
()
robot
.
giro
(
90
)
robot
.
sigueLineaHastaNegro
()
robot
.
giro
(
-
90
)
robot
.
sigueLineaHastaNegro
()
#robot.sigueLineaHastaNegro()
#robot.giro(90)
#robot.sigueLineaHastaNegro()
#robot.calibraSensorColor()
robot.py
View file @
2a69bc65
...
...
@@ -25,10 +25,10 @@ class Robot:
self
.
colaMovimientos
=
[]
#Metodos gestion negros
def
queNegroEs
(
self
):
if
self
.
contadorNegros
==
0
:
def
queNegroEs
(
self
,
negro
):
if
negro
==
0
:
return
0
if
self
.
contadorNegros
%
2
==
0
:
if
negro
%
2
==
0
:
return
0
return
1
...
...
@@ -61,7 +61,6 @@ class Robot:
#Metodos para el movimiento
def
giro
(
self
,
grados
):
self
.
robot
.
reset
()
self
.
giroSensor
.
reset_angle
(
0
)
self
.
robot
.
turn
(
grados
)
while
(
self
.
giroSensor
.
angle
()
!=
grados
):
...
...
@@ -73,48 +72,60 @@ class Robot:
else
:
if
(
ajuste
<
0
):
self
.
robot
.
turn
(
-
1
)
def
giro2
(
self
,
grados
):
self
.
giroSensor
.
reset_angle
(
0
)
self
.
robot
.
turn
(
grados
)
while
(
self
.
giroSensor
.
angle
()
!=
grados
):
diferencia
=
self
.
giroSensor
.
angle
()
-
grados
ajuste
=
diferencia
*
-
1
for
i
in
range
(
abs
(
ajuste
)):
if
(
ajuste
>
0
):
self
.
robot
.
turn
(
1
)
else
:
if
(
ajuste
<
0
):
self
.
robot
.
turn
(
-
1
)
def
calibraSensorColor
(
self
):
while
True
:
print
(
self
.
colorSensor
.
rgb
())
wait
(
20
)
def
sigueLineaHastaNegro
(
self
,
color
=
green_rgb
):
# Valores iniciales
rgb
=
self
.
colorSensor
.
rgb
()
negroAnterior
=
self
.
negroFlag
#Valores iniciales
negroAnteriorFlag
=
self
.
negroFlag
contNegroAnterior
=
self
.
contadorNegros
if
self
.
is_black
(
rgb
):
self
.
negroFlag
=
True
while
self
.
queNegroEs
()
==
1
or
self
.
contadorNegros
==
0
:
while
(((
self
.
queNegroEs
(
contNegroAnterior
)
==
0
)
and
(
self
.
queNegroEs
(
self
.
contadorNegros
)
==
1
))
==
False
)
or
self
.
contadorNegros
==
1
:
#Fase de lectura
rgb
=
self
.
colorSensor
.
rgb
()
if
self
.
is_green
(
rgb
):
self
.
w
=
self
.
valorW
negroAnterior
=
self
.
negroFlag
negroAnterior
Flag
=
self
.
negroFlag
self
.
negroFlag
=
False
self
.
velocidad
=
50
elif
self
.
is_black
(
rgb
):
negroAnterior
=
self
.
negroFlag
negroAnterior
Flag
=
self
.
negroFlag
self
.
negroFlag
=
True
self
.
w
=
0
self
.
velocidad
=
50
else
:
negroAnterior
=
self
.
negroFlag
negroAnterior
Flag
=
self
.
negroFlag
self
.
negroFlag
=
False
self
.
w
=
-
self
.
valorW
self
.
velocidad
=
50
#Fase de ejecución
if
negroAnterior
and
not
self
.
negroFlag
:
#Incremento negro al salir
if
negroAnteriorFlag
and
not
self
.
negroFlag
:
contNegroAnterior
=
self
.
contadorNegros
self
.
incrementaContNegros
()
self
.
robot
.
drive
(
self
.
velocidad
,
self
.
w
)
print
(
self
.
contadorNegros
)
self
.
resetContadorNegros
(
)
print
(
self
.
contadorNegros
,
contNegroAnterior
)
def
gestionRuta
(
self
):
while
True
:
rgb
=
self
.
colorSensor
.
rgb
()
...
...
@@ -126,6 +137,7 @@ class Robot:
#caso detecta negro
elif
self
.
is_black
(
rgb
):
#incremento el contador
contNegroAnterior
=
self
.
contadorNegros
self
.
incrementaContNegros
()
#miro si es par o impar
...
...
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