- 追加された行はこの色です。
- 削除された行はこの色です。
*目次 [#s97f036e]
#contents
*課題 [#ya29fe4b]
紙コップを運ぶロボットの作成。紙コップを運ぶ精度、早さ、紙コップを積み上げる正確さを競う。
*ルール概要 [#m2dd7852]
#ref(./2016a-mission2.png,100%)
紙コップをA.B,D地点の3か所に2個ずつ、計6個を一か所(スタート地点:C地点)に積み上げる。このとき、下からABDABDと積み上げるのが目標だった。
*ロボットの形状 [#ged2159a]
*プログラム [#k2274bd9]
#!/usr/bin/python
import ev3dev.ev3 as ev3
import time
ml = ev3.LargeMotor('outB')
mr = ev3.LargeMotor('outA')
mm = ev3.MediumMotor('outC')
cs = ev3.ColorSensor('in1')
de = ev3.InfraredSensor('in2')
def catch():
while de.value() < 50:
if de.value() < 10:
ml.run_forever(duty_cycle_sp=0)
mr.run_forever(duty_cycle_sp=0)
mm.run_forever(duty_cycle_sp=50)
time.sleep(4)
mm.run_forever(duty_cycle_sp=0)
ml.run_forever(duty_cycle_sp=-20)
mr.run_forever(duty_cycle_sp=-20)
time.sleep(1.5)
ml.run_forever(duty_cycle_sp=0)
mr.run_forever(duty_cycle_sp=0)
ml.run_forever(duty_cycle_sp=-50)
mr.run_forever(duty_cycle_sp=50)
time.sleep(1.6)
ml.run_forever(duty_cycle_sp=0)
mr.run_forever(duty_cycle_sp=0)
else:
ml.run_forever(duty_cycle_sp=15)
mr.run_forever(duty_cycle_sp=15)
def lineleft():
t0 = time.time()
while time.time() - t0 < 0.35:
if cs.value () > 50 :
mr.run_forever(duty_cycle_sp=-30)
ml.run_forever(duty_cycle_sp=60)
t0 = time.time()
else:
mr.run_forever(duty_cycle_sp=60)
ml.run_forever(duty_cycle_sp=-30)
def cross(t,dl,dr):
mr.run_forever(duty_cycle_sp=dr)
ml.run_forever(duty_cycle_sp=dl)
time.sleep(t/1000)
ml.stop()
mr.stop()
def toa():
lineright()
cross(1000,-20,20)
cross(1000,13,13)
lineright()
cross(1000,0,0)
cross(1000,-18,18)
cross(1000,0,0)
catch()
cross(1400,30,-30)
lineright()
cross(1000,0,0)
cross(1000,-20,20)
cross(1000,10,10)
lineright()
cross(1000,0,0)
cross(1000,-25,25)
mm.run_forever(duty_cycle_sp=-50)
time.sleep(3)
mm.run_forever(duty_cycle_sp=0)
cross(1000,-30,-30)
cross(2000,-40,40)
def tob():
lineleft()
cross(1000,-10,10)
lineright()
cross(1000,-20,20)
cross(1000,13,13)
lineright()
cross(1000,-20,20)
cross(1000,13,13)
lineright()
cross(1000,0,0)
cross(1000,-17,17)
cross(1000,0,0)
catch()
lineleft()
cross(1000,20,-20)
cross(1000,13,13)
lineleft()
cross(1000,20,-20)
cross(1000,40,13)
lineright()
cross(1000,0,0)
cross(1000,36,-36)
lineright()
cross(1000,0,0)
cross(1000,-20,20)
mm.run_forever(duty_cycle_sp=-50)
time.sleep(3)
mm.run_forever(duty_cycle_sp=0)
cross(1000,-30,-30)
def toc():
lineright()
cross(1000,-17,17)
cross(1000,30,-30)
cross(1000,10,10)
lineright()
cross(1000,-20,20)
cross(1000,13,13)
lineright()
cross(1000,-20,20)
cross(1000,13,13)
catch()
lineright()
cross(1000,0,0)
cross(1000,17,-17)
cross(1000,13,13)
lineright()
cross(1000,0,0)
cross(1000,-22,22)
cross(1000,0,0)
lineright()
cross(1000,0,0)
cross(1000,-25,25)
mm.run_forever(duty_cycle_sp=-50)
time.sleep(3)
mm.run_forever(duty_cycle_sp=0)
cross(1000,-30,-30)
cross(1500,-50,50)
mm.run_forever(duty_cycle_sp=-50)
time.sleep(3.5)
mm.run_forever(duty_cycle_sp=0)
tob()
cross(1000,-13,13)
tob()
*結果 [#m432ad7c]
46秒でゴールした。
*反省・感想 [#d170cbbb]
-交差点認識プログラムについて考えるのに時間をかけすぎてしまった。
-traceを改良してもっと早くゴールまでたどり着けるようにしたかった。