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
4c6f6419
authored
May 03, 2024
by
Vicente Castellano Gómez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Prueba inicial
parent
ef89b60e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
14 deletions
main.py
robot.py
main.py
View file @
4c6f6419
#!/usr/bin/env pybricks-micropython
from
robot
import
Robot
from
pybricks.hubs
import
EV3Brick
from
pybricks.ev3devices
import
(
Motor
,
TouchSensor
,
ColorSensor
,
InfraredSensor
,
UltrasonicSensor
,
GyroSensor
)
from
pybricks.parameters
import
Port
,
Stop
,
Direction
,
Button
,
Color
from
pybricks.tools
import
wait
,
StopWatch
,
DataLog
from
pybricks.robotics
import
DriveBase
from
pybricks.media.ev3dev
import
SoundFile
,
ImageFile
robot
=
Robot
()
robot
.
sigueLineaHastaNegro
()
robot
=
Robot
()
\ No newline at end of file
robot.py
View file @
4c6f6419
...
...
@@ -4,14 +4,15 @@ from pybricks.parameters import Port, Stop, Direction, Button, Color
from
pybricks.tools
import
wait
,
StopWatch
,
DataLog
from
pybricks.robotics
import
DriveBase
from
pybricks.media.ev3dev
import
SoundFile
,
ImageFile
from
queue
import
Queue
class
Robot
:
green_rgb
=
(
35
,
55
,
39
)
black_rgb
=
(
8
,
4
,
19
)
green_rgb
=
(
27
,
47
,
16
)
black_rgb
=
(
4
,
2
,
7
)
blue_rgb
=
(
0
,
0
,
0
)
tolerancia
=
5
tolerancia
=
7
contadorNegros
=
0
w
=
10
velocidad
=
100
def
__init__
(
self
):
self
.
ev3
=
EV3Brick
()
...
...
@@ -20,7 +21,7 @@ class Robot:
self
.
giroSensor
=
GyroSensor
(
Port
.
S1
)
self
.
colorSensor
=
ColorSensor
(
Port
.
S4
)
self
.
robot
=
DriveBase
(
left_motor
,
right_motor
,
wheel_diameter
=
55.5
,
axle_track
=
124
)
self
.
colaMovimientos
=
Queue
()
self
.
colaMovimientos
=
[]
#Metodos gestion negros
def
queNegroEs
(
self
):
...
...
@@ -35,25 +36,25 @@ class Robot:
self
.
contadorNegros
=
self
.
contadorNegros
+
1
#metodos deteccion de colores
def
is_green
(
rgb
):
def
is_green
(
self
,
rgb
):
if
(
rgb
[
0
]
>=
(
Robot
.
green_rgb
[
0
]
-
Robot
.
tolerancia
)
and
rgb
[
0
]
<=
(
Robot
.
green_rgb
[
0
]
+
Robot
.
tolerancia
))
and
(
rgb
[
1
]
>=
(
Robot
.
green_rgb
[
1
]
-
Robot
.
tolerancia
)
and
rgb
[
1
]
<=
(
Robot
.
green_rgb
[
1
]
+
Robot
.
tolerancia
))
and
(
rgb
[
2
]
>=
(
Robot
.
green_rgb
[
2
]
-
Robot
.
tolerancia
)
and
rgb
[
2
]
<=
(
Robot
.
green_rgb
[
2
]
+
Robot
.
tolerancia
)):
return
True
return
False
def
is_black
(
rgb
):
def
is_black
(
self
,
rgb
):
if
(
rgb
[
0
]
>=
(
Robot
.
black_rgb
[
0
]
-
Robot
.
tolerancia
)
and
rgb
[
0
]
<=
(
Robot
.
black_rgb
[
0
]
+
Robot
.
tolerancia
))
and
(
rgb
[
1
]
>=
(
Robot
.
black_rgb
[
1
]
-
Robot
.
tolerancia
)
and
rgb
[
1
]
<=
(
Robot
.
black_rgb
[
1
]
+
Robot
.
tolerancia
))
and
(
rgb
[
2
]
>=
(
Robot
.
black_rgb
[
2
]
-
Robot
.
tolerancia
)
and
rgb
[
2
]
<=
(
Robot
.
black_rgb
[
2
]
+
Robot
.
tolerancia
)):
return
True
return
False
def
is_blue
(
rgb
):
def
is_blue
(
self
,
rgb
):
if
(
rgb
[
0
]
>=
(
Robot
.
blue_rgb
[
0
]
-
Robot
.
tolerancia
)
and
rgb
[
0
]
<=
(
Robot
.
blue_rgb
[
0
]
+
Robot
.
tolerancia
))
and
(
rgb
[
1
]
>=
(
Robot
.
blue_rgb
[
1
]
-
Robot
.
tolerancia
)
and
rgb
[
1
]
<=
(
Robot
.
blue_rgb
[
1
]
+
Robot
.
tolerancia
))
and
(
rgb
[
2
]
>=
(
Robot
.
blue_rgb
[
2
]
-
Robot
.
tolerancia
)
and
rgb
[
2
]
<=
(
Robot
.
blue_rgb
[
2
]
+
Robot
.
tolerancia
)):
return
True
return
False
# Recogemos la lista de movimientos del algoritmo
def
recogeListaMovimientosPedido
(
self
,
lMovimientos
):
for
movimiento
in
lMovimientos
:
self
.
colaMovimientos
.
put
(
movimiento
)
#
def recogeListaMovimientosPedido(self, lMovimientos):
#
for movimiento in lMovimientos:
#
self.colaMovimientos.put(movimiento)
#Metodos para el movimiento
def
giro
(
self
,
grados
):
...
...
@@ -70,8 +71,20 @@ class Robot:
if
(
ajuste
<
0
):
self
.
robot
.
turn
(
-
1
)
def
sigueLineaHastaNegro
(
self
,
color
=
green_rgb
):
rgb
=
self
.
colorSensor
.
rgb
()
def
seguir_linea
(
self
,
color
=
"verde"
):
while
not
self
.
is_black
(
rgb
)
or
self
.
queNegroEs
()
==
0
:
#Fase de lectura
rgb
=
self
.
colorSensor
.
rgb
()
if
self
.
is_green
(
rgb
):
self
.
w
=
10
else
:
self
.
w
=
-
10
#Fase de ejecución
self
.
robot
.
drive
(
self
.
velocidad
,
self
.
w
)
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