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
e44f62a3
authored
May 03, 2024
by
Vicente Castellano Gómez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Movimiento funca
parent
4c6f6419
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
9 deletions
main.py
robot.py
main.py
View file @
e44f62a3
...
...
@@ -11,4 +11,10 @@ from pybricks.media.ev3dev import SoundFile, ImageFile
robot
=
Robot
()
robot
.
sigueLineaHastaNegro
()
robot
.
sigueLineaHastaNegro
()
robot
.
giro
(
90
)
robot
.
sigueLineaHastaNegro
()
robot
.
giro
(
-
90
)
robot
.
sigueLineaHastaNegro
()
#robot.calibraSensorColor()
robot.py
View file @
e44f62a3
...
...
@@ -6,13 +6,14 @@ from pybricks.robotics import DriveBase
from
pybricks.media.ev3dev
import
SoundFile
,
ImageFile
class
Robot
:
green_rgb
=
(
27
,
47
,
16
)
black_rgb
=
(
4
,
2
,
7
)
blue_rgb
=
(
0
,
0
,
0
)
tolerancia
=
7
green_rgb
=
(
36
,
70
,
38
)
black_rgb
=
(
5
,
5
,
16
)
tolerancia
=
10
contadorNegros
=
0
w
=
10
valorW
=
30
w
=
0
velocidad
=
100
negroFlag
=
False
def
__init__
(
self
):
self
.
ev3
=
EV3Brick
()
...
...
@@ -25,6 +26,8 @@ class Robot:
#Metodos gestion negros
def
queNegroEs
(
self
):
if
self
.
contadorNegros
==
0
:
return
0
if
self
.
contadorNegros
%
2
==
0
:
return
0
return
1
...
...
@@ -70,20 +73,48 @@ class Robot:
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
):
rgb
=
self
.
colorSensor
.
rgb
()
negroAnterior
=
self
.
negroFlag
while
not
self
.
is_black
(
rgb
)
or
self
.
queNegroEs
()
==
0
:
#Valores iniciales
if
self
.
is_black
(
rgb
):
self
.
negroFlag
=
True
while
self
.
queNegroEs
()
==
1
or
self
.
contadorNegros
==
0
:
#Fase de lectura
rgb
=
self
.
colorSensor
.
rgb
()
if
self
.
is_green
(
rgb
):
self
.
w
=
10
self
.
w
=
self
.
valorW
negroAnterior
=
self
.
negroFlag
self
.
negroFlag
=
False
self
.
velocidad
=
50
elif
self
.
is_black
(
rgb
):
negroAnterior
=
self
.
negroFlag
self
.
negroFlag
=
True
self
.
w
=
0
self
.
velocidad
=
50
else
:
self
.
w
=
-
10
negroAnterior
=
self
.
negroFlag
self
.
negroFlag
=
False
self
.
w
=
-
self
.
valorW
self
.
velocidad
=
50
#Fase de ejecución
if
negroAnterior
and
not
self
.
negroFlag
:
self
.
incrementaContNegros
()
self
.
robot
.
drive
(
self
.
velocidad
,
self
.
w
)
print
(
self
.
contadorNegros
)
self
.
resetContadorNegros
()
def
gestionRuta
(
self
):
while
True
:
rgb
=
self
.
colorSensor
.
rgb
()
...
...
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