コード例 #1
0
    def USscanForward_timed(self):
        #This function scans for objects and implements avoidance measures
        #if necessary

        motor2 = ev3.MediumMotor('outD')
        motor2.connected

        #motor2.run_timed(time_sp=2000, speed_sp=-90)
        us = ev3.UltrasonicSensor()
        #t_end = time.time() + 5
        #while time.time() <  t_end:
        print us.value()
        if us.value() < 100:
            ev3.Sound.speak('object detected').wait()
            OD = OC.OdometryControl()
            OD.turn_left_ObjectAvoid()
            motor2.run_timed(time_sp=1000, speed_sp=90)
            OD.objectAvoidForward()
            motor2.run_timed(time_sp=1000, speed_sp=90)
            ev3.Sound.speak('object still in range').wait()
            motor2.run_timed(time_sp=1000, speed_sp=-90)
            motor2.run_timed(time_sp=1000, speed_sp=-90)
            OD.turn_right_ObjectAvoid()
            OD.objectAvoidForward()
            OD.turn_right_ObjectAvoid()
            OD.objectAvoidForward2()
            ev3.Sound.speak('object has been avoided')
コード例 #2
0
#print("object at:"+str(sensor_value) + "mm")
#ev3.Sound.speak("object at"+str(motor2.position) + "degrees").wait()

o=olc.openLoopControl()
o.operateMotors()
#motor2 =ev3.MediumMotor('outD'); assert motor2.connected
#motor0 = ev3.LargeMotor('outB'); assert motor0.connected
#motor1 = ev3.LargeMotor('outC'); assert motor1.connected


ev3.Sound.speak('I am going to follow these lines').wait()
Follow=FL.FollowLine()
Follow.Straight_PD_timed()
#time.sleep(4)
ev3.Sound.speak('I have reached the end of first line').wait()
OD=OC.OdometryControl()
OD.turn_right()
ev3.Sound.speak('I have reached the second line').wait()
Follow=FL.FollowLine()
Follow.Straight_PD2_timed()
ev3.Sound.speak('I have reached the end of second line').wait()
OD=OC.OdometryControl()
OD.turn_left()
ev3.Sound.speak('I have reached the final line').wait()
Follow=FL.FollowLine()
Follow.Straight_PD_timed()
ev3.Sound.speak('Impressive for a brain the size of a planet isnt it').wait()
# remove this if you want it to exit as soon as its done:
#print "wait 10sec, then end"
#time.sleep(10)