Пример #1
0
class MySpeaker(object):
    def __init__(self):
        self.t = Tone()

    def play(self,frequency=100,milliseconds=100):
        self.t.play(frequency,milliseconds)

    def stop(self):
        self.t.stop()
Пример #2
0
def main():
    ir = InfraredSensor()
    touch = TouchSensor()
    tone = Tone()
    
    while True:
        sleep(duration)
        if not touch.is_pushed:
            tone.stop()
            continue
        dist = ir.prox
        freq = min(freq_range[1], max(freq_range[0], int((dist * (freq_range[0]-freq_range[1]) + dist_range[1] * freq_range[1] - dist_range[0] * freq_range[0]) / (dist_range[1]-dist_range[0]))))
        tone.play(freq)
        print("#" * dist)
Пример #3
0
 def test_tone(self):
     get_input('Test beep')
     d = Tone()
     d.play(1000, 3000)
     time.sleep(3)
     d.play(1000)
     time.sleep(3)
     d.stop()
Пример #4
0
 def test_tone(self):
     get_input('Test beep')
     d= Tone()
     d.play(1000, 3000)
     time.sleep(3)
     d.play(1000)
     time.sleep(3)
     d.stop()
Пример #5
0
#from ev3.lego import LargeMotor
from ev3.lego import TouchSensor
from ev3.lego import ColorSensor
from ev3.lego import InfraredSensor

import conf

# Create Flask application
app = Flask(__name__)
app.debug = True

# Create a random secrey key so we can use sessions
app.config['SECRET_KEY'] = os.urandom(12)

from ev3.ev3dev import Tone
alarm = Tone()

#head = None#Motor(port=Motor.PORT.A)
right_wheel = None
left_wheel = None
button = None
ir_sensor = None
color_sensor = None
try:
    right_wheel = Motor(port=Motor.PORT.B)
    left_wheel = Motor(port=Motor.PORT.C)
    button = TouchSensor()
    #ir_sensor = InfraredSensor()
    color_sensor = ColorSensor()
    alarm.play(200)
except Exception as e:
Пример #6
0
target = ((value_on_red - value_not_on_red) / 2) + value_not_on_red
tp = 70 # target power (speed)

kp = 0.65 # how fast we try to correct the 'out of target'
ki = 0.05 # smooth the correction by storing historical errors
kd = 0.09 # controls the overshooting

print "target power: " + str(tp)
print "proportional constant: " + str(kp)
print "proportional range: +" + str(target) + " / -" + str(target)

color_sensor = ColorSensor()
ultra_sensor = UltrasonicSensor()
motor_left = Motor(port=Motor.PORT.A)
motor_right = Motor(port=Motor.PORT.D)
tone = Tone()

def avg(lst):
    if len(lst) == 0:
        return 0
    return reduce(lambda x, y: x + y, lst) / len(lst)

def stop():
    motor_left.stop()
    motor_right.stop()

def victory():
    motor_left.run_forever(-100)
    motor_right.run_forever(-100)
    time.sleep(3)
    motor_right.run_forever(100)
Пример #7
0
 def __init__(self):
     self.t = Tone()

    # Socket erstellen und an eigene IPs (inkl. Broadcast) binden
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 4096)
    sock.bind(("0.0.0.0",5005))
    sock.settimeout(args.socktimeout)

    # Adressvariablen erstellen und Leader finden, falls vorhanden
    broadcast = netifaces.ifaddresses(args.iface)[netifaces.AF_INET][0]["broadcast"]
    ownaddr = netifaces.ifaddresses(args.iface)[netifaces.AF_INET][0]["addr"]
    leader = tell(sock, ownaddr, broadcast, "WHOS")
    platoon = []

    hupe = Tone()

    # Falls die Option start_idle nicht gesetzt ist, fahre direkt los
    if not args.start_idle:
        p = Process(name="follow_line", target=follow_line, args=follow_line_args)
        p.start()
    else:
        p = Process(name="wait", target=time.sleep, args=(0.1,))
        p.start()

    lasttime = time.time()

    try:
        while True:
            # Nachricht empfangen
            try:
if real_robot_mode:
    from ev3.lego import Motor
    from ev3.lego import UltrasonicSensor
    from ev3.lego import ColorSensor
    from ev3.ev3dev import Tone
    a = Motor(port=Motor.PORT.A) # left large motor
    d = Motor(port=Motor.PORT.D) # right large motor
    a.reset()
    d.reset()
    a.position_mode=Motor.POSITION_MODE.RELATIVE
    d.position_mode=Motor.POSITION_MODE.RELATIVE
    sonar_left = UltrasonicSensor(port=2)
    sonar_front = UltrasonicSensor(port=3)
    color_left = ColorSensor(port=1)
    color_right = ColorSensor(port=4)
    sound = Tone()


# Occupancy grid - checks for available positions
class Grid:

    def __init__(self, rows, cols):
        self.obstacles = []
        self.grid = []
        for row in xrange(rows): self.grid += [[0]*cols]

    def add_obstacle(self, row_start, row_end, col_start, col_end):
        for row in xrange(row_start, row_end + 1):
            for col in xrange(col_start, col_end + 1):
                self.grid[row][col] = 1
    # Sammlung der Argumente fuer die Funktion follow_line
    follow_line_args = (args.Vref, args.colmax, args.colmin, args.distref, args.Vtremble, args.timeout, args.cycledelay, args.lKp, args.lKi, args.lKd, args.dKp, args.dKi, args.dKd)

    # Socket erstellen und an eigene IPs (inkl. Broadcast) binden
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    sock.bind(("0.0.0.0",5005))
    sock.settimeout(args.socktimeout)

    # Adressvariablen erstellen und Vordermann finden, falls vorhanden
    broadcast = netifaces.ifaddresses(args.iface)[netifaces.AF_INET][0]["broadcast"]
    ownaddr = netifaces.ifaddresses(args.iface)[netifaces.AF_INET][0]["addr"]
    frontaddr = tell(sock, ownaddr, broadcast, "WHOS")
    backaddr = None

    hupe = Tone()

    # Falls die Option start_idle nicht gesetzt ist, fahre direkt los
    if not args.start_idle:
        p = Process(name="follow_line", target=follow_line, args=follow_line_args)
        p.start()
    else:
        p = Process(name="wait", target=time.sleep, args=(0.1,))
        p.start()

    lasttime = time.time()

    try:
        while True:
            # Nachricht empfangen
            try:
Пример #11
0
if real_robot_mode:
    from ev3.lego import Motor
    from ev3.lego import UltrasonicSensor
    from ev3.lego import ColorSensor
    from ev3.ev3dev import Tone
    a = Motor(port=Motor.PORT.A)  # left large motor
    d = Motor(port=Motor.PORT.D)  # right large motor
    a.reset()
    d.reset()
    a.position_mode = Motor.POSITION_MODE.RELATIVE
    d.position_mode = Motor.POSITION_MODE.RELATIVE
    sonar_left = UltrasonicSensor(port=2)
    sonar_front = UltrasonicSensor(port=3)
    color_left = ColorSensor(port=1)
    color_right = ColorSensor(port=4)
    sound = Tone()


# Occupancy grid - checks for available positions
class Grid:
    def __init__(self, rows, cols):
        self.obstacles = []
        self.grid = []
        for row in xrange(rows):
            self.grid += [[0] * cols]

    def add_obstacle(self, row_start, row_end, col_start, col_end):
        for row in xrange(row_start, row_end + 1):
            for col in xrange(col_start, col_end + 1):
                self.grid[row][col] = 1
Пример #12
0
#from ev3.lego import LargeMotor
from ev3.lego import TouchSensor
from ev3.lego import ColorSensor
from ev3.lego import InfraredSensor

import conf

# Create Flask application
app = Flask(__name__)
app.debug = True

# Create a random secrey key so we can use sessions
app.config['SECRET_KEY'] = os.urandom(12)

from ev3.ev3dev import Tone
alarm = Tone()

#head = None#Motor(port=Motor.PORT.A)
right_wheel = None
left_wheel  = None
button = None
ir_sensor = None
color_sensor = None
try:
    right_wheel = Motor(port=Motor.PORT.B)
    left_wheel = Motor(port=Motor.PORT.C)
    button = TouchSensor()
    #ir_sensor = InfraredSensor()
    color_sensor = ColorSensor()
    alarm.play(200)
except Exception as e: