Project

General

Profile

Código e implementación » History » Version 4

Vranika Santiago, 12/04/2022 06:14 PM

1 1 Vranika Santiago
*Índice:* 
2 1 Vranika Santiago
* [[Introducción]]
3 1 Vranika Santiago
* [[Organización y planificación]]
4 1 Vranika Santiago
* [[Análisis y diseño]]
5 1 Vranika Santiago
* [[Código e implementación]]
6 1 Vranika Santiago
7 1 Vranika Santiago
---
8 1 Vranika Santiago
9 1 Vranika Santiago
h1. Código e implementación
10 2 Vranika Santiago
11 2 Vranika Santiago
---
12 3 Vranika Santiago
13 4 Vranika Santiago
{{collapse(Código movimientos del robot)
14 3 Vranika Santiago
<pre><code class="python">
15 3 Vranika Santiago
  #!/usr/bin/env python3
16 3 Vranika Santiago
from ev3dev2.motor import LargeMotor, MediumMotor, OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D, SpeedPercent, MoveTank
17 3 Vranika Santiago
from ev3dev2.sensor import INPUT_1
18 3 Vranika Santiago
from ev3dev2.sensor .lego import UltrasonicSensor
19 3 Vranika Santiago
from ev3dev2.sound import Sound
20 3 Vranika Santiago
from ev3dev2.led import Leds
21 3 Vranika Santiago
22 3 Vranika Santiago
motor_angle= LargeMotor(OUTPUT_A)
23 3 Vranika Santiago
cannon = MediumMotor(OUTPUT_D)
24 3 Vranika Santiago
sonido = Sound()
25 3 Vranika Santiago
sensor = UltrasonicSensor(INPUT_1)
26 3 Vranika Santiago
sensor.mode = "US-DIST-CM"
27 3 Vranika Santiago
tankmoves = MoveTank(OUTPUT_B,OUTPUT_C)
28 3 Vranika Santiago
print(sensor.value()/10)
29 3 Vranika Santiago
30 3 Vranika Santiago
def moveUp():
31 3 Vranika Santiago
    print("Moving up...")
32 3 Vranika Santiago
    tankmoves.on(SpeedPercent(100),SpeedPercent(100))
33 3 Vranika Santiago
def moveDown():
34 3 Vranika Santiago
    print("Moving down...")
35 3 Vranika Santiago
    tankmoves.on(SpeedPercent(-100),SpeedPercent(-100))
36 3 Vranika Santiago
def moveRight():
37 3 Vranika Santiago
    print("Moving right...")
38 3 Vranika Santiago
    tankmoves.on(SpeedPercent(100),SpeedPercent(-100))
39 3 Vranika Santiago
def moveLeft():
40 3 Vranika Santiago
    print("Moving left...")
41 3 Vranika Santiago
    tankmoves.on(SpeedPercent(-100),SpeedPercent(100))
42 3 Vranika Santiago
def Inclinacion0():
43 3 Vranika Santiago
    motor_angle.on_for_degrees(7,55,brake=True)
44 3 Vranika Santiago
def Inclinacion45():
45 3 Vranika Santiago
    motor_angle.on_for_degrees(7,-55,brake=True)
46 3 Vranika Santiago
    
47 3 Vranika Santiago
def Disparar():    
48 3 Vranika Santiago
    cannon.on(SpeedPercent(-100))
49 3 Vranika Santiago
def Apuntar():
50 3 Vranika Santiago
    sensor.value #valor del sensor en milimetro
51 3 Vranika Santiago
    
52 3 Vranika Santiago
def Luciano():
53 3 Vranika Santiago
    sonido.speak("gorila tank mak two")
54 3 Vranika Santiago
def Distancia():
55 3 Vranika Santiago
    
56 3 Vranika Santiago
    while(sensor.value()/10 <= 100 or sensor.value()/10 >= 110):
57 3 Vranika Santiago
        print(sensor.value()/10)
58 3 Vranika Santiago
        if(sensor.value()/10 < 100):
59 3 Vranika Santiago
            tankmoves.on(SpeedPercent(-40),SpeedPercent(-40))
60 3 Vranika Santiago
            
61 3 Vranika Santiago
        else:
62 3 Vranika Santiago
            tankmoves.on(SpeedPercent(40),SpeedPercent(40))
63 3 Vranika Santiago
    Stop()
64 3 Vranika Santiago
    
65 3 Vranika Santiago
def Stop():
66 3 Vranika Santiago
    tankmoves.stop()
67 3 Vranika Santiago
    
68 3 Vranika Santiago
def StopCannon():
69 3 Vranika Santiago
    cannon.stop()
70 3 Vranika Santiago
    sonido.play_file("misioncumplida.wav",100,1)
71 3 Vranika Santiago
    
72 3 Vranika Santiago
73 3 Vranika Santiago
</code></pre>
74 4 Vranika Santiago
}}