示例#1
0
if __name__ == "__main__":
    myThread = threading.Thread(target=keyboardInput, args=(1, ), daemon=True)
    myThread.start()
    print("Ready for keyboard commands...")

    ### Main Loop
    while (True):
        usDistCmVal = us.distance_centimeters
        if usDistCmVal != prev_usDistCmVal:
            print("usDistCmVal = ", usDistCmVal, "  irDistVal = ", irDistVal,
                  "  irHeadVal = ", irHeadVal, "  compassVal = ", compassVal
                  )  # print all sensor vals, regardless of which changed
            prev_usDistCmVal = usDistCmVal

        irDistVal = ir.distance()
        irHeadVal = ir.heading()
        if (irDistVal != prev_irDistVal) or (irHeadVal != prev_irHeadVal):
            print("usDistCmVal = ", usDistCmVal, "  irDistVal = ", irDistVal,
                  "  irHeadVal = ", irHeadVal, "  compassVal = ", compassVal
                  )  # print all sensor vals, regardless of which changed
            prev_irDistVal = irDistVal
            prev_irHeadVal = irHeadVal
            # if beacon has been found, set beaconLock True
            if irDistVal is not None:
                if irDistVal < 100:
                    beaconLock = True
                if irDistVal == 100:
                    beaconLock = False
            else:
                beaconLock = False
示例#2
0

### Main Loop
    while (True):
        usDistCmVal = us.distance_centimeters
        if usDistCmVal != prev_usDistCmVal:
            if printVerbose > 0:
                print("usDistCmVal = ", int(usDistCmVal), "  irDistVal = ", irDistVal, "  compassVal = ", compassVal)  # print all sensor vals, regardless of which changed
            prev_usDistCmVal = usDistCmVal

        irDistVal = ir.distance(channel=1)
        if irDistVal == None:
            irDistVal = -1  ### set to -1 instead of None or numpy.savetxt and other Ops will complain
        else:
            irDistVal = int(3.19 * irDistVal)
        irHeadVal = ir.heading(channel=1)
        if (irDistVal != prev_irDistVal):
            if printVerbose > 0:
                #print("usDistCmVal = ", int(usDistCmVal), "  irDistVal = ", irDistVal, "  irHeadVal = ", irHeadVal, "  compassVal = ", compassVal, "  mR.position = ", mR.position)  # print all sensor vals, regardless of which changed
                print("usDistCmVal = ", int(usDistCmVal), "  irDistVal = ", irDistVal, "  irHeadVal = ", irHeadVal, "  compassVal = ", compassVal)  # print all sensor vals, regardless of which changed
            prev_irDistVal = irDistVal
            prev_irHeadVal = irHeadVal

        compassVal = cmp.value(0)
        if compassVal != prev_compassVal:
            if printVerbose > 0:
                #print("usDistCmVal = ", int(usDistCmVal), "  irDistVal = ", irDistVal, "  compassVal = ", compassVal)  # print all sensor vals, regardless of which changed
                print("usDistCmVal = ", int(usDistCmVal), "  irDistVal = ", irDistVal, "  irHeadVal = ", irHeadVal, "  compassVal = ", compassVal)  # print all sensor vals, regardless of which changed
            prev_compassVal = compassVal

        ### halt if usDistCmVal < 5 
示例#3
0

# Start program
reset()

starting = True
while starting or infrared_sensor.distance(
) == None or infrared_sensor.distance() >= 50:
    starting = False
    search()
    steering_drive.on_for_rotations(steering=0,
                                    speed=SpeedPercent(75),
                                    rotations=4)

while infrared_sensor.distance() > 2:
    steering_drive.on(steering=(safe_steering(infrared_sensor.heading() * 5)),
                      speed=SpeedPercent(50))
steering_drive.off()
sound.play_file("/home/robot/sounds/Detected.wav",
                play_type=sound.PLAY_WAIT_FOR_COMPLETE)

steering_drive.on_for_rotations(steering=0,
                                speed=SpeedPercent(50),
                                rotations=0.7)

grab()

sleep(2)

steering_drive.on_for_rotations(steering=100,
                                speed=SpeedPercent(50),
    ### Main Loop
    while (True):
        usDistCmVal = us.distance_centimeters
        if usDistCmVal != prev_usDistCmVal:
            if printVerbose > 0:
                print("usDistCmVal = ", int(usDistCmVal), "  ir1DistVal = ",
                      ir1DistVal, "  compassVal = ", compassVal
                      )  # print all sensor vals, regardless of which changed
            prev_usDistCmVal = usDistCmVal

        ir1DistVal = ir.distance(channel=1)
        if ir1DistVal == None:
            ir1DistVal = -1  ### set to -1 instead of None or numpy.savetxt and other Ops will complain
        else:
            ir1DistVal = int(3.19 * ir1DistVal)
        ir1HeadVal = ir.heading(channel=1)
        if (ir1DistVal != prev_ir1DistVal):
            if printVerbose > 0:
                #print("usDistCmVal = ", int(usDistCmVal), "  ir1DistVal = ", ir1DistVal, "  ir1HeadVal = ", ir1HeadVal, "  compassVal = ", compassVal, "  mR.position = ", mR.position)  # print all sensor vals, regardless of which changed
                print("usDistCmVal = ", int(usDistCmVal), "  ir1DistVal = ",
                      ir1DistVal, "  ir1HeadVal = ", ir1HeadVal,
                      "  compassVal = ", compassVal
                      )  # print all sensor vals, regardless of which changed
            prev_ir1DistVal = ir1DistVal
            prev_ir1HeadVal = ir1HeadVal

        ir2DistVal = ir.distance(channel=2)
        if ir2DistVal == None:
            ir2DistVal = -1  ### set to -1 instead of None or numpy.savetxt and other Ops will complain
        else:
            ir2DistVal = int(3.19 * ir2DistVal)
示例#5
0
#!/usr/bin/env python3
from ev3dev2.motor import MoveSteering, OUTPUT_B, OUTPUT_C
from ev3dev2.sensor.lego import InfraredSensor
from time import sleep

steer_pair = MoveSteering(OUTPUT_B, OUTPUT_C)
ir = InfraredSensor()

while True:  # forever
    distance = ir.distance()
    if distance:  # If distance is not None
        error = distance - 10
        steer_pair.on(steering=2 * ir.heading(), speed=min(90, 3 * error))
    else:
        steer_pair.off()
    sleep(0.1)
示例#6
0
sleep(2)

us = UltrasonicSensor('ev3-ports:in2:i2c80:mux1')
ir = InfraredSensor('ev3-ports:in2:i2c81:mux2')
gyro = GyroSensor('ev3-ports:in2:i2c82:mux3')

us_value = us.value(0)
us_dist = us.distance_centimeters # takes multiple measurements
us_numvalues = us.num_values
us_address = us.address
us_units = us.units

ir_value = ir.value(0)
ir_proximity = ir.proximity # an estimate of the distance between the sensor and the objects in front of it
ir_beacon= ir.distance(channel=1) # returns distance (0,100) to the beacon on the given channel
ir_heading = ir.heading(channel=1) # returns heading (-25,25) to the beacon on the given channel
ir_address = ir.address

gyro_value = gyro.value(0)
gyro_angle = gyro.angle
gyro_address = gyro.address
gyro_units = gyro.units

# Sensors connected to NXT-Sensor-Split MUX - Barometer---------------------------------------------------------

temp1 = Sensor(INPUT_1)
temp1.mode = 'TEMP'
Temp_NXT = (temp1.value(0)/1000)

pressure = Sensor(INPUT_1)
pressure.mode = 'PRESS'