Project

General

Profile

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

Vranika Santiago, 12/04/2022 06:08 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 3 Vranika Santiago
<pre><code class="python">
14 3 Vranika Santiago
  #!/usr/bin/env python3
15 3 Vranika Santiago
from ev3dev2.motor import LargeMotor, MediumMotor, OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D, SpeedPercent, MoveTank
16 3 Vranika Santiago
from ev3dev2.sensor import INPUT_1
17 3 Vranika Santiago
from ev3dev2.sensor .lego import UltrasonicSensor
18 3 Vranika Santiago
from ev3dev2.sound import Sound
19 3 Vranika Santiago
from ev3dev2.led import Leds
20 3 Vranika Santiago
21 3 Vranika Santiago
motor_angle= LargeMotor(OUTPUT_A)
22 3 Vranika Santiago
cannon = MediumMotor(OUTPUT_D)
23 3 Vranika Santiago
sonido = Sound()
24 3 Vranika Santiago
sensor = UltrasonicSensor(INPUT_1)
25 3 Vranika Santiago
sensor.mode = "US-DIST-CM"
26 3 Vranika Santiago
tankmoves = MoveTank(OUTPUT_B,OUTPUT_C)
27 3 Vranika Santiago
print(sensor.value()/10)
28 3 Vranika Santiago
29 3 Vranika Santiago
def moveUp():
30 3 Vranika Santiago
    print("Moving up...")
31 3 Vranika Santiago
    tankmoves.on(SpeedPercent(100),SpeedPercent(100))
32 3 Vranika Santiago
def moveDown():
33 3 Vranika Santiago
    print("Moving down...")
34 3 Vranika Santiago
    tankmoves.on(SpeedPercent(-100),SpeedPercent(-100))
35 3 Vranika Santiago
def moveRight():
36 3 Vranika Santiago
    print("Moving right...")
37 3 Vranika Santiago
    tankmoves.on(SpeedPercent(100),SpeedPercent(-100))
38 3 Vranika Santiago
def moveLeft():
39 3 Vranika Santiago
    print("Moving left...")
40 3 Vranika Santiago
    tankmoves.on(SpeedPercent(-100),SpeedPercent(100))
41 3 Vranika Santiago
def Inclinacion0():
42 3 Vranika Santiago
    motor_angle.on_for_degrees(7,55,brake=True)
43 3 Vranika Santiago
def Inclinacion45():
44 3 Vranika Santiago
    motor_angle.on_for_degrees(7,-55,brake=True)
45 3 Vranika Santiago
    
46 3 Vranika Santiago
def Disparar():    
47 3 Vranika Santiago
    cannon.on(SpeedPercent(-100))
48 3 Vranika Santiago
def Apuntar():
49 3 Vranika Santiago
    sensor.value #valor del sensor en milimetro
50 3 Vranika Santiago
    
51 3 Vranika Santiago
def Luciano():
52 3 Vranika Santiago
    sonido.speak("gorila tank mak two")
53 3 Vranika Santiago
def Distancia():
54 3 Vranika Santiago
    
55 3 Vranika Santiago
    while(sensor.value()/10 <= 100 or sensor.value()/10 >= 110):
56 3 Vranika Santiago
        print(sensor.value()/10)
57 3 Vranika Santiago
        if(sensor.value()/10 < 100):
58 3 Vranika Santiago
            tankmoves.on(SpeedPercent(-40),SpeedPercent(-40))
59 3 Vranika Santiago
            
60 3 Vranika Santiago
        else:
61 3 Vranika Santiago
            tankmoves.on(SpeedPercent(40),SpeedPercent(40))
62 3 Vranika Santiago
    Stop()
63 3 Vranika Santiago
    
64 3 Vranika Santiago
def Stop():
65 3 Vranika Santiago
    tankmoves.stop()
66 3 Vranika Santiago
    
67 3 Vranika Santiago
def StopCannon():
68 3 Vranika Santiago
    cannon.stop()
69 3 Vranika Santiago
    sonido.play_file("misioncumplida.wav",100,1)
70 3 Vranika Santiago
    
71 3 Vranika Santiago
72 3 Vranika Santiago
</code></pre>