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