Esempio n. 1
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()
Esempio n. 2
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()
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()
Esempio n. 4
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)
Esempio n. 5
0
# 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:
    alarm.play(200)
    alarm.play(200)
    raise e

right_wheel.position = 0
left_wheel.position = 0
right_wheel.reset()
left_wheel.reset()

from web import views
            # Nachricht auswerten
            if not addr[0] == ownaddr and not mesg == "None":
                mesg = mesg.split(":")

                if len(mesg) < 2:
                    mesg.append(ownaddr)

                if mesg[0] == "STOP" and ( ownaddr in mesg or mesg[1] == "ALL" ):
                    sock.sendto("ACK", (addr[0],5005))
                    if not p.name == "wait":
                        p.terminate()
                        stop_all_motors()
                        p = Process(name="wait", target=time.sleep, args=(0.1,))
                        p.start()
                    hupe.play(440,250)

                elif mesg[0] == "START" and ( ownaddr in mesg or mesg[1] == "ALL" ):
                    sock.sendto("ACK", (addr[0],5005))
                    if not ( p.name == "follow_line"  and p.is_alive() ):
                        p.terminate()
                        p = Process(name="follow_line", target=follow_line, args=follow_line_args)
                        p.start()

                elif mesg[0] == "WHOS" and leader == None:
                    sock.sendto("ACK", (addr[0],5005))
                    if addr[0] in platoon:
                        platoon.remove(addr[0])
                    platoon.append(addr[0])

                elif mesg[0] == "BARRIER":
# print final particle set (used for particle visualization)
print ''
print 'PF: final particle set: '
print pf.p


if real_robot_mode and grab_target:

# Calculate distance/heading to target, move towards it, run spiral search - note that there is no collision avoidance

    distance_to_target = distance_between((estimated_position[0],estimated_position[1]), target_position)
    print 'Robot - Distance to target: ', distance_to_target
    heading_to_target = get_heading((estimated_position[0], estimated_position[1]), target_position)
    print 'Robot - Heading to target: ', heading_to_target
    turn_angle_deg = angle_trunc(heading_to_target - estimated_position[2]) * 180/pi
    print 'Robot - Turn angle towards target: ', turn_angle_deg
    print 'Robot - Turning towards target'
    ev3.turn_in_place(turn_angle_deg)
    print 'Robot - Driving towards target'
    ev3.move_distance(distance_to_target)

    found = ev3.spiral_search(100)
    if found:
        print 'Robot - Found target !'
        sound.play(1000, 3000)
    else:
        print 'Robot - Target not found'


            if not addr[0] == ownaddr and not mesg == "None":
                mesg = mesg.split(":")

                if len(mesg) < 2:
                    mesg.append("")

                if mesg[0] == "STOP":
                    sock.sendto("ACK", (addr[0],5005))
                    if not p.name == "wait":
                        p.terminate()
                        stop_all_motors()
                        p = Process(name="wait", target=time.sleep, args=(0.1,))
                        p.start()
                    if not backaddr == None:
                        backaddr = propagate(sock, ownaddr, backaddr, "STOP")
                    hupe.play(440,250)

                elif mesg[0] == "START":
                    sock.sendto("ACK", (addr[0],5005))
                    if not ( p.name == "follow_line" and p.is_alive() ):
                        p.terminate()
                        p = Process(name="follow_line", target=follow_line, args=follow_line_args)
                        p.start()
                    if not backaddr == None:
                        backaddr = propagate(sock, ownaddr, backaddr, "START")

                elif mesg[0] == "LOST" and frontaddr == mesg[1]:
                    sock.sendto("ACK", (addr[0],5005))
                    frontaddr = addr[0]
                    hupe.play(6000,250)
Esempio n. 9
0
# print final particle set (used for particle visualization)
print ''
print 'PF: final particle set: '
print pf.p

if real_robot_mode and grab_target:

    # Calculate distance/heading to target, move towards it, run spiral search - note that there is no collision avoidance

    distance_to_target = distance_between(
        (estimated_position[0], estimated_position[1]), target_position)
    print 'Robot - Distance to target: ', distance_to_target
    heading_to_target = get_heading(
        (estimated_position[0], estimated_position[1]), target_position)
    print 'Robot - Heading to target: ', heading_to_target
    turn_angle_deg = angle_trunc(heading_to_target -
                                 estimated_position[2]) * 180 / pi
    print 'Robot - Turn angle towards target: ', turn_angle_deg
    print 'Robot - Turning towards target'
    ev3.turn_in_place(turn_angle_deg)
    print 'Robot - Driving towards target'
    ev3.move_distance(distance_to_target)

    found = ev3.spiral_search(100)
    if found:
        print 'Robot - Found target !'
        sound.play(1000, 3000)
    else:
        print 'Robot - Target not found'
Esempio n. 10
0
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:
    alarm.play(200)
    alarm.play(200)
    raise e


right_wheel.position = 0
left_wheel.position = 0
right_wheel.reset()
left_wheel.reset()

from web import views