[[2016a/Member]] #contents *課題内容 [#t279e582] 今回の課題は地点A・B・Cに紙コップが3個ずつ設置されそのコップを回収しコースの真ん中にある円の部分に運ぶという課題です。~ またコップは同じ地点にあったものを連続で重ねてはいけなく、A・B・Cの順番に重ねなければなりません。 #ref(line01.jpg) *ロボットの仕組み [#t000242c] 今回この課題をクリアするために二つのロボットを作成することにしました。~ 1つ目は紙コップを各地点から回収するためのロボットです。~ もう1つは紙コップを積み重ねるためのロボットです。 **1つ目 [#l1199943] #ref(robot3.jpg) #ref(robot4.jpg) **2つ目 [#n62a7075] #ref(robot1.jpg) #ref(robot2.jpg) *プログラム [#n8c7f74e] **1つ目 [#fe069469] #!/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() **2つ目 [#o5553f5f] #!/usr/bin/python import ev3dev.ev3 as ev3 import time m1 = ev3.LargeMotor('outA') m2 = ev3.MediumMotor('outB') m3 = ev3.MediumMotor('outC') m4 = ev3.LargeMotor('outD') us = ev3.UltrasonicSensor('in1') def search(p): t0 = time.time() while time.time() - t0 < 0.001: if us.value() > p: m4.run_forever(duty_cycle_sp=50) t0 = time.time() else: m4.stop() def bring(x,y): m4.run_forever(duty_cycle_sp=x) time.sleep(y) m4.stop() def close(): m1.run_forever(duty_cycle_sp=-37.5) time.sleep(0.32) m1.stop() def up(): m3.run_forever(duty_cycle_sp=-50) m2.run_forever(duty_cycle_sp=50) time.sleep(2.25) m2.stop() m3.stop() def down(): m3.run_forever(duty_cycle_sp=50) m2.run_forever(duty_cycle_sp=-50) time.sleep(1.5) m2.stop() m3.stop() def open(a,b): m1.run_forever(duty_cycle_sp=a) time.sleep(b) m1.stop() search(60) bring(45,0.2) close() up() search(60) open(20,0.275) bring(45,0.2) down() open(27.5,0.325) bring(-40,7.5) *最後に [#x3786c4f]