- 追加された行はこの色です。
- 削除された行はこの色です。
[[2016a/Member]]
#contents
*内容 [#n9a47e72]
今回の課題はライントレースをすることである。~
今回自分がたどるルートは地点B→地点R→右折→地点Q→直進→地点Q→直進→地点P→右折→地点S→右折→地点Cです。
#ref(line01.jpg)
*ロボットについて [#eef3a4a8]
*プログラム [#o746260a]
#!/usr/bin/python
# -*- coding: utf-8 -*-
import ev3dev.ev3 as ev3
MR = ev3.LargeMotor('outA')
ML = ev3.LargeMotor('outB')
cs = ev3.ColorSensor('in1')
t0 = time.time()
S = ev3.Sound()
def st():
MR.stop()
ML.stop()
def line(a):
t0 = time.time()
while time.time() - t0 < a:
if cs.value() > 30:
MR.run_forever(duty_cycle_sp=-30)
ML.run_forever(duty_cycle_sp=20)
t0 = time.time()
elif cs.value() >= 10:
MR.run_forever(duty_cycle_sp=35)
ML.run_forever(duty_cycle_sp=35)
t0 = time.time()
else:
MR.run_forever(duty_cycle_sp=20)
ML.run_forever(duty_cycle_sp=-30)
def run(r,l,t):
MR.run_forever(duty_cycle_sp=r)
ML.run_forever(duty_cycle_sp=l)
time.sleep(t)
MR.stop()
ML.stop()
def R(b):
MR.run_forever(duty_cycle_sp=-30)
ML.run_forever(duty_cycle_sp=20)
time.sleep(1)
MR.stop()
ML.stop()
MR.run_forever(duty_cycle_sp=30)
ML.run_forever(duty_cycle_sp=30)
time.sleep(b)
MR.stop()
ML.stop()
line(0.22)
S.beep()
R(0.75)
line(0.245)
S.beep()
run(-30,20,0.22)
run(50,50,0.5)
line(0.22)
S.beep()
run(-30,20,0.22)
run(50,50,0.3)
line(0.22)
S.beep()
R(0.75)
line(0.22)
S.beep()
R(0.75)
line(0.22)
S.beep()
run(-30,20,0.22)
run(50,50,0.3)
run(100,100,1)
st()
*結果・考察 [#vd19bc09]