Código de las funciones » History » Version 1
Ruben Salas, 01/03/2024 10:29 PM
1 | 1 | Ruben Salas | h1. Código de las funciones |
---|---|---|---|
2 | 1 | Ruben Salas | |
3 | 1 | Ruben Salas | <pre> |
4 | 1 | Ruben Salas | #!/usr/bin/env pybricks-micropython |
5 | 1 | Ruben Salas | |
6 | 1 | Ruben Salas | # Librerias |
7 | 1 | Ruben Salas | from pybricks.hubs import EV3Brick |
8 | 1 | Ruben Salas | from pybricks.ev3devices import Motor |
9 | 1 | Ruben Salas | from pybricks.parameters import Port |
10 | 1 | Ruben Salas | from pybricks.robotics import DriveBase |
11 | 1 | Ruben Salas | |
12 | 1 | Ruben Salas | RobotGolf = EV3Brick |
13 | 1 | Ruben Salas | motor_izquierda = Motor(Port.A) |
14 | 1 | Ruben Salas | motor_derecha = Motor(Port.B) |
15 | 1 | Ruben Salas | motor_brazo = Motor(Port.D) |
16 | 1 | Ruben Salas | base_robot = DriveBase(motor_izquierda, motor_derecha, wheel_diameter = 55.5, axle_track = 100) |
17 | 1 | Ruben Salas | |
18 | 1 | Ruben Salas | # Funciones |
19 | 1 | Ruben Salas | def avanzar(): |
20 | 1 | Ruben Salas | print("Avanzando...") |
21 | 1 | Ruben Salas | base_robot.straight(-10) |
22 | 1 | Ruben Salas | |
23 | 1 | Ruben Salas | def retroceder(): |
24 | 1 | Ruben Salas | print("Retrocediendo...") |
25 | 1 | Ruben Salas | base_robot.straight(10) |
26 | 1 | Ruben Salas | |
27 | 1 | Ruben Salas | def rotarDerecha(): |
28 | 1 | Ruben Salas | print("Rotando derecha...") |
29 | 1 | Ruben Salas | base_robot.turn(-10) |
30 | 1 | Ruben Salas | |
31 | 1 | Ruben Salas | def rotarIzquierda(): |
32 | 1 | Ruben Salas | print("Rotando izquierda...") |
33 | 1 | Ruben Salas | base_robot.turn(10) |
34 | 1 | Ruben Salas | |
35 | 1 | Ruben Salas | def golpeSuave(): |
36 | 1 | Ruben Salas | print("Golpe suave...") |
37 | 1 | Ruben Salas | motor_brazo.run(100) |
38 | 1 | Ruben Salas | |
39 | 1 | Ruben Salas | def golpeFuerte(): |
40 | 1 | Ruben Salas | print("Golpe fuerte...") |
41 | 1 | Ruben Salas | motor_brazo.run(1000000) |
42 | 1 | Ruben Salas | |
43 | 1 | Ruben Salas | def devolverBrazo(): |
44 | 1 | Ruben Salas | print("Retrocediendo brazo...") |
45 | 1 | Ruben Salas | motor_brazo.run(-100) |
46 | 1 | Ruben Salas | |
47 | 1 | Ruben Salas | def detener(): |
48 | 1 | Ruben Salas | base_robot.stop() |
49 | 1 | Ruben Salas | |
50 | 1 | Ruben Salas | def detenerBrazo(): |
51 | 1 | Ruben Salas | motor_brazo.stop() |
52 | 1 | Ruben Salas | </pre> |