Project

General

Profile

Function.py

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

Download (1.67 KB)

 
1
#!/usr/bin/env python3
2
from ev3dev2.motor import LargeMotor, MediumMotor, OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D, SpeedPercent, MoveTank
3
from ev3dev2.sensor import INPUT_1
4
from ev3dev2.sensor .lego import UltrasonicSensor
5
from ev3dev2.sound import Sound
6
from ev3dev2.led import Leds
7

    
8
motor_angle= LargeMotor(OUTPUT_A)
9
cannon = MediumMotor(OUTPUT_D)
10
sonido = Sound()
11
sensor = UltrasonicSensor(INPUT_1)
12
sensor.mode = "US-DIST-CM"
13
tankmoves = MoveTank(OUTPUT_B,OUTPUT_C)
14
print(sensor.value()/10)
15

    
16
def moveUp():
17
    print("Moving up...")
18
    tankmoves.on(SpeedPercent(100),SpeedPercent(100))
19
def moveDown():
20
    print("Moving down...")
21
    tankmoves.on(SpeedPercent(-100),SpeedPercent(-100))
22
def moveRight():
23
    print("Moving right...")
24
    tankmoves.on(SpeedPercent(100),SpeedPercent(-100))
25
def moveLeft():
26
    print("Moving left...")
27
    tankmoves.on(SpeedPercent(-100),SpeedPercent(100))
28
def Inclinacion0():
29
    motor_angle.on_for_degrees(7,55,brake=True)
30
def Inclinacion45():
31
    motor_angle.on_for_degrees(7,-55,brake=True)
32
    
33
def Disparar():    
34
    cannon.on(SpeedPercent(-100))
35
def Apuntar():
36
    sensor.value #valor del sensor en milimetro
37
    
38
def Luciano():
39
    sonido.speak("gorila tank mak two")
40
def Distancia():
41
    
42
    while(sensor.value()/10 <= 100 or sensor.value()/10 >= 110):
43
        print(sensor.value()/10)
44
        if(sensor.value()/10 < 100):
45
            tankmoves.on(SpeedPercent(-40),SpeedPercent(-40))
46
            
47
        else:
48
            tankmoves.on(SpeedPercent(40),SpeedPercent(40))
49
    Stop()
50
    
51
def Stop():
52
    tankmoves.stop()
53
    
54
def StopCannon():
55
    cannon.stop()
56
    sonido.play_file("misioncumplida.wav",100,1)
57