2019b/Member/LaiHen/Mission3
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
----
目次
#contents
----
* 課題?「ボール運搬ロボット」 [#m7fda309]
下の図の点C,E,Fに置かれた缶の上のボールを点C',E',F'に置か...
&ref(2019b/Member/LaiHen/Mission3/2019b-mission2.png,70%,...
* ロボットについて [#b2d9ff38]
** ロボットの構造について [#p337419d]
今回の課題ではEV3本体を2台使ってロボットを作成できるため...
-1つ目のアイデアは2台を使って1つのロボットを作成する方法
-2つ目のアイデアは2つのロボットを作成する方法です~
この2つのアイデアについて考えていきます。~
1つ目はライントレースに使うモーター2つ以外は自由に使える...
2つ目はライントレースにモーターを2つ使うためロボットそれ...
ここで今回の課題について考えてみると今回ロボットがするの...
こうした考えから下の写真のような同じ型にロボットの作成を...
&ref(2019b/Member/LaiHen/Mission3/lobo1.jpg,40%,ロボット);~
以下でこのロボットの工夫点を説明していきます。
*** アームの小型化 [#ke64d09d]
ロボットの小型化で最も重要なのがアームです。このアームを...
&ref(2019b/Member/LaiHen/Mission3/lobo2.jpg,30%,ロボット);
&ref(2019b/Member/LaiHen/Mission3/lobo3.jpg,30%,ロボット);~
*** センサーの設置 [#p7aab33a]
ロボットの小型化で最も苦労したのが超音波センサーの設置場...
&ref(2019b/Member/LaiHen/Mission3/lobo4.jpg,10%,ロボット);~
** ロボットのまとめ [#o50710eb]
ロボットの作成は相方がメインでやっていたので詳しく説明す...
* プログラムについて [#oab3b1ff]
** プログラムのシステムについて [#w0083243]
今回の課題では同じロボットを2つ用意しているため、1台で缶...
+ 線をたどっていくシステム(ライントレース)
+ 缶の配置や道などのマップ管理システム
+ ルート決定システム~
それぞれのシステムについての説明をしていきます。
*** ライントレースシステム [#l9962598]
このシステムについては課題?で作成したライントレースの基準...
*** マップ管理システム [#u91678d0]
このシステムについては様々な方法が思いつき試行錯誤を重な...
&ref(2019b/Member/LaiHen/Mission3/2019b-mission3_1.png,70...
まず缶の位置と2つのロボットの初期地点である点A,A'から考え...
&ref(2019b/Member/LaiHen/Mission3/2019b-mission3_2.png,70...
そうして上の図の黄色で塗られた部分は、缶があって通れない...
&ref(2019b/Member/LaiHen/Mission3/2019b-mission3_3.png,70...
そうしてできたのが、上の図のマップになります。四角は点を...
*** ルート決定システム [#scddaa10]
先ほど作成したマップを参考にルート決定システムを作成して...
+ ボールを回収するのか設置するのか
+ どこの缶に向かうのか~
この2つでボールを回収しに行っているときは「x」、ボール...
また、点と点の移動の際にどちらを基準にしてライントレース...
&ref(2019b/Member/LaiHen/Mission3/2019b-mission3_4.png,70...
** プログラムの説明 [#ta9d6f93]
先の説明でのシステムをもとにプログラムを作成していきます...
- 1台目のプログラム
#!/usr/bin/env python3
from ev3dev2.motor import *
from ev3dev2.sensor import *
from ev3dev2.sensor.lego import *
from ev3dev2.sound import *
from time import *
Wmax,Bmax,spmax,spmin,brockch,tst,balltime=75,5,8,4,6,2....
tw = MoveTank(OUTPUT_A, OUTPUT_D)
Mm= MediumMotor(OUTPUT_B)
cs,ts,us = ColorSensor(),TouchSensor(),UltrasonicSensor()
us.mode = 'US-DIST-CM'
Mv=(Wmax+Bmax)/2
Lp=(Wmax-Mv)/4
llp=2*Lp
spab=(spmax+spmin)/2
Clev=[Wmax,Wmax-Lp,Mv+Lp,Mv-Lp,Bmax+Lp,Bmax]
ballst=[1,1,1,0,0,0]
snd=Sound()
class Linetorace:
def __init__(self,a):
self.cv=a
self.colortyp,self.dcv,self.lesp,self.risp=0,0,0,0
self.typcheck()
self.movesp()
def typcheck(self):
for i in range(5):
if Clev[i+1]<=self.cv<Clev[i]:
self.colortyp=i
self.dcv=Clev[i]-self.cv
def movesp(self):
zuw=round(self.dcv/llp,1)
if self.colortyp==0:
self.lesp=spab-(spab-spmin)*zuw
self.risp=-spmin
elif self.colortyp==1:
self.lesp=spmax
self.risp=spab+(spmax-spab)*zuw
elif self.colortyp==2:
self.lesp=spmax
self.risp=spmax
elif self.colortyp==3:
self.lesp=spab+(spmax-spab)*zuw
self.risp=spmax
else:
self.lesp=-spmin
self.risp=spab-(spab-spmin)*zuw
class accomand:
def __init__(self,line,cltyp,sttime,endtime):
self.line,self.cltyp,self.sttime,self.endtime=li...
def sendcomand(self):
action(self.line,self.sttime,self.endtime)
closs(self.cltyp,self.line)
class Vector2:
def __init__(self,x,y):
self.x,self.y=x,y
self.comp=complex(x,y)
def disp(self):
print(self.x,",",self.y)
def fukusosuu(self):
print(self.comp)
class houkou:
def __init__(self,hou):
self.hou=hou
self.x,self.y=0,0
self.kakutei()
def kakutei(self):
if self.hou==1:
self.x=1
elif self.hou==2:
self.y=1
elif self.hou==3:
self.x=-1
elif self.hou==4:
self.y=-1
self.ch=complex(self.x,self.y)
class st:
def __init__(self):
self.stt="xa"
self.line,self.point=0,0
def go(self):
print("0")
def linekizyun(linehou,pointhou):
a=houkou(linehou)
b=houkou(pointhou)
che=Vector2(0,1)
if a.ch==(b.ch*che.comp):
print("left")
ty=0
else:
print("ri")
ty=1
return ty
def vector2math(vec1,vec2):
avec=Vector2(vec1.x+vec2.x,vec1.y+vec2.y)
return avec
def action(line,stti,enti):
sttime1,notime1 = time(),time()
bcon=0
while not (ts.is_pressed) and not ((notime1-sttime1)...
cvp = cs.reflected_light_intensity
MLT=Linetorace(cvp)
if MLT.colortyp==4:
bcon=bcon+1
else:
bcon=0
notime1=time()
if (stti <= (notime1-sttime1) <=enti) and (bcon=...
break
if line==0:
tw.on(MLT.lesp,MLT.risp)
elif line==1:
tw.on(MLT.risp,MLT.lesp)
else:
tw.on(-MLT.lesp,-MLT.risp)
sleep(0.1)
tw.off()
def closs(pp,line):
cvp= cs.reflected_light_intensity
MLT = Linetorace(cvp)
if line==0:
tw.on(-MLT.lesp,-MLT.risp)
else:
tw.on(-MLT.risp,-MLT.lesp)
sleep(0.1*brockch)
tw.off()
if pp==0:
action(0,tst,tst+0.1)
else:
if pp==1:
action(0,tst,tst+0.1)
elif pp==2:
tw.on_for_seconds(spmax,spmax,1)
else:
action(1,tst,tst+0.1)
tw.off()
def ballaction(tp):
face=0
while not (ts.is_pressed):
cvp= cs.reflected_light_intensity
MLT= Linetorace(cvp)
tw.on(MLT.risp,MLT.lesp)
txle= us.distance_centimeters
if txle<=4:
tw.on_for_seconds(4,4,0.9)
face=1
break
sleep(0.1)
tw.off()
if face==1:
print("check")
if tp==0:
Mm.on_for_rotations(20,0.3)
tw.on_for_seconds(-15,-15,1.1)
tw.on_for_degrees(-4,4,360)
else:
Mm.on_for_rotations(-10,0.3)
tw.on_for_seconds(-15,-15,1.1)
tw.on_for_degrees(-4,4,360)
def point_a(stas):
print("a")
root=accomand(linekizyun(1,4),1,0,30)
root.sendcomand()
stas.stt="yl"
if not (ts.is_pressed):
point_b(stas)
def point_b(stas):
print("b")
if stas.stt in "xa":
ballaction(0)
if not (ts.is_pressed):
point_a(stas)
elif stas.stt in "y" or "xg" or "xh":
root=accomand(linekizyun(2,1),0,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_c(stas)
def point_c(stas):
sleep(15)
print("c")
if stas.stt in "x":
root=accomand(linekizyun(2,3),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_b(stas)
elif stas.stt in "y" or "yl":
root=accomand(linekizyun(2,1),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
def point_d(stas):
print("d")
if stas.stt in "xa":
root=accomand(linekizyun(2,3),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_c(stas)
elif stas.stt in "yl":
root=accomand(linekizyun(4,2),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
elif stas.stt in "yn":
root=accomand(linekizyun(4,2),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
elif stas.stt in "yp":
root=accomand(linekizyun(4,2),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
elif stas.stt in "xg":
root=accomand(linekizyun(3,2),2,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_e(stas)
elif stas.stt in "xh":
root=accomand(linekizyun(3,2),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_e(stas)
def point_e(stas):
print("e")
if stas.stt in "xg":
root=accomand(linekizyun(3,2),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_f(stas)
if stas.stt in "xh":
ballaction(0)
if not (ts.is_pressed):
point_h(stas)
elif stas.stt in "yp" or "yn":
root=accomand(linekizyun(3,4),1,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
def point_f(stas):
print("f")
if stas.stt in "xg":
ballaction(0)
if not (ts.is_pressed):
point_g(stas)
elif stas.stt in "yp":
root=accomand(linekizyun(3,4),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_e(stas)
def point_g(stas):
print("g")
stas.stt="yp"
root=accomand(linekizyun(3,4),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_e(stas)
def point_h(stas):
print("h")
stas.stt="yn"
root=accomand(linekizyun(3,4),1,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
def point_i(stas):
print("i")
if stas.stt in "xa":
root=accomand(linekizyun(2,3),2,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
elif stas.stt in "yl":
root=accomand(linekizyun(4,1),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_j(stas)
elif stas.stt in "yn":
root=accomand(linekizyun(1,4),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_m(stas)
elif stas.stt in "yp":
root=accomand(linekizyun(1,4),2,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_m(stas)
elif stas.stt in "xg":
root=accomand(1,3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
elif stas.stt in "xh":
root=accomand(linekizyun(2,3),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
def point_j(stas):
print("j")
if stas.stt in "xg":
root=accomand(linekizyun(4,3),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
elif stas.stt in "y" or "yl":
root=accomand(linekizyun(4,1),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_k(stas)
def point_k(stas):
print("k")
if stas.stt in "yl":
ballaction(1)
if not (ts.is_pressed):
point_l(stas)
elif stas.stt in "x" or "xg":
root=accomand(linekizyun(4,3),0,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_j(stas)
def point_l(stas):
print("l")
stas.stt="ee"
root=accomand(linekizyun(3,2),1,0,30)
root.sendcomand()
if not (ts.is_pressed):
endd()
def point_m(stas):
print("m")
if stas.stt in "yp":
root=accomand(linekizyun(1,4),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_o(stas)
elif stas.stt in "yn":
ballaction(1)
if not (ts.is_pressed):
endd()
stas.stt="ee"
elif stas.stt in "xa" or "xh":
root=accomand(linekizyun(1,2),1,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
def point_n(stas):
print("n")
stas.stt="xa"
root=accomand(linekizyun(1,2),1,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
def point_o(stas):
print("o")
if stas.stt in "yp":
ballaction(1)
if not (ts.is_pressed):
point_p(stas)
elif stas.stt in "xa":
root=accomand(linekizyun(1,2),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_m(stas)
def point_p(stas):
print("p")
stas.stt="xh"
root=accomand(linekizyun(1,2),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_m(stas)
def endd():
snd.speak("finish")
def main():
snd.speak("start")
lobo=st()
point_b(lobo)
snd.beep()
if __name__ == '__main__':
main()
- 2台目のプログラム
#!/usr/bin/env python3
from ev3dev2.motor import *
from ev3dev2.sensor import *
from ev3dev2.sensor.lego import *
from ev3dev2.sound import *
from time import *
Wmax,Bmax,spmax,spmin,brockch,tst,balltime=75,5,8,4,6,2....
tw = MoveTank(OUTPUT_A, OUTPUT_D)
Mm= MediumMotor(OUTPUT_B)
cs,ts,us = ColorSensor(),TouchSensor(),UltrasonicSensor()
us.mode = 'US-DIST-CM'
Mv=(Wmax+Bmax)/2
Lp=(Wmax-Mv)/4
llp=2*Lp
spab=(spmax+spmin)/2
Clev=[Wmax,Wmax-Lp,Mv+Lp,Mv-Lp,Bmax+Lp,Bmax]
ballst=[1,1,1,0,0,0]
snd=Sound()
class Linetorace:
def __init__(self,a):
self.cv=a
self.colortyp,self.dcv,self.lesp,self.risp=0,0,0,0
self.typcheck()
self.movesp()
def typcheck(self):
for i in range(5):
if Clev[i+1]<=self.cv<Clev[i]:
self.colortyp=i
self.dcv=Clev[i]-self.cv
def movesp(self):
zuw=round(self.dcv/llp,1)
if self.colortyp==0:
self.lesp=spab-(spab-spmin)*zuw
self.risp=-spmin
elif self.colortyp==1:
self.lesp=spmax
self.risp=spab+(spmax-spab)*zuw
elif self.colortyp==2:
self.lesp=spmax
self.risp=spmax
elif self.colortyp==3:
self.lesp=spab+(spmax-spab)*zuw
self.risp=spmax
else:
self.lesp=-spmin
self.risp=spab-(spab-spmin)*zuw
class accomand:
def __init__(self,line,cltyp,sttime,endtime):
self.line,self.cltyp,self.sttime,self.endtime=li...
def sendcomand(self):
action(self.line,self.sttime,self.endtime)
closs(self.cltyp,self.line)
class Vector2:
def __init__(self,x,y):
self.x,self.y=x,y
self.comp=complex(x,y)
def disp(self):
print(self.x,",",self.y)
def fukusosuu(self):
print(self.comp)
class houkou:
def __init__(self,hou):
self.hou=hou
self.x,self.y=0,0
self.kakutei()
def kakutei(self):
if self.hou==1:
self.x=1
elif self.hou==2:
self.y=1
elif self.hou==3:
self.x=-1
elif self.hou==4:
self.y=-1
self.ch=complex(self.x,self.y)
class st:
def __init__(self):
self.stt="xg"
self.line,self.point=0,0
def go(self):
print("0")
def linekizyun(linehou,pointhou):
a=houkou(linehou)
b=houkou(pointhou)
che=Vector2(0,1)
if a.ch==(b.ch*che.comp):
print("left")
ty=0
else:
print("ri")
ty=1
return ty
def vector2math(vec1,vec2):
avec=Vector2(vec1.x+vec2.x,vec1.y+vec2.y)
return avec
def action(line,stti,enti):
sttime1,notime1 = time(),time()
bcon=0
while not (ts.is_pressed) and not ((notime1-sttime1)...
cvp = cs.reflected_light_intensity
MLT=Linetorace(cvp)
if MLT.colortyp==4:
bcon=bcon+1
else:
bcon=0
notime1=time()
if (stti <= (notime1-sttime1) <=enti) and (bcon=...
break
if line==0:
tw.on(MLT.lesp,MLT.risp)
elif line==1:
tw.on(MLT.risp,MLT.lesp)
else:
tw.on(-MLT.lesp,-MLT.risp)
sleep(0.1)
tw.off()
def closs(pp,line):
cvp= cs.reflected_light_intensity
MLT = Linetorace(cvp)
if line==0:
tw.on(-MLT.lesp,-MLT.risp)
else:
tw.on(-MLT.risp,-MLT.lesp)
sleep(0.1*brockch)
tw.off()
if pp==0:
action(0,tst,tst+0.1)
else:
if pp==1:
action(0,tst,tst+0.1)
elif pp==2:
tw.on_for_seconds(spmax,spmax,1)
else:
action(1,tst,tst+0.1)
tw.off()
def ballaction(tp):
face=0
while not (ts.is_pressed):
cvp= cs.reflected_light_intensity
MLT= Linetorace(cvp)
tw.on(MLT.risp,MLT.lesp)
txle= us.distance_centimeters
if txle<=4:
tw.on_for_seconds(4,4,0.9)
face=1
break
sleep(0.1)
tw.off()
if face==1:
print("check")
if tp==0:
Mm.on_for_rotations(20,0.3)
tw.on_for_seconds(-15,-15,1.1)
tw.on_for_degrees(-4,4,360)
else:
Mm.on_for_rotations(-10,0.3)
tw.on_for_seconds(-15,-15,1.1)
tw.on_for_degrees(-4,4,360)
def point_a(stas):
print("a")
root=accomand(linekizyun(1,4),1,0,30)
root.sendcomand()
stas.stt="yl"
if not (ts.is_pressed):
point_b(stas)
def point_b(stas):
print("b")
if stas.stt in "xa":
ballaction(0)
if not (ts.is_pressed):
point_a(stas)
elif stas.stt in "y" or "xg" or "xh":
root=accomand(linekizyun(2,1),0,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_c(stas)
def point_c(stas):
print("c")
if stas.stt in "x":
root=accomand(linekizyun(2,3),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_b(stas)
elif stas.stt in "y" or "yl":
root=accomand(linekizyun(2,1),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
def point_d(stas):
print("d")
if stas.stt in "xa":
root=accomand(linekizyun(2,3),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_c(stas)
elif stas.stt in "yl":
root=accomand(linekizyun(4,2),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
elif stas.stt in "yn":
root=accomand(linekizyun(4,2),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
elif stas.stt in "yp":
root=accomand(linekizyun(4,2),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
elif stas.stt in "xg":
root=accomand(linekizyun(3,2),2,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_e(stas)
elif stas.stt in "xh":
root=accomand(linekizyun(3,2),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_e(stas)
def point_e(stas):
print("e")
if stas.stt in "xg":
root=accomand(linekizyun(3,2),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_f(stas)
if stas.stt in "xh":
ballaction(0)
if not (ts.is_pressed):
point_h(stas)
elif stas.stt in "yp" or "yn":
root=accomand(linekizyun(3,4),1,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
def point_f(stas):
print("f")
if stas.stt in "xg":
ballaction(0)
if not (ts.is_pressed):
point_g(stas)
elif stas.stt in "yp":
root=accomand(linekizyun(3,4),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_e(stas)
def point_g(stas):
sleep(20)
print("g")
stas.stt="yp"
root=accomand(linekizyun(3,4),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_e(stas)
def point_h(stas):
print("h")
stas.stt="yn"
root=accomand(linekizyun(3,4),1,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
def point_i(stas):
print("i")
if stas.stt in "xa":
root=accomand(linekizyun(2,3),2,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
elif stas.stt in "yl":
root=accomand(linekizyun(4,1),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_j(stas)
elif stas.stt in "yn":
root=accomand(linekizyun(1,4),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_m(stas)
elif stas.stt in "yp":
root=accomand(linekizyun(1,4),2,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_m(stas)
elif stas.stt in "xg":
root=accomand(1,3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
elif stas.stt in "xh":
root=accomand(linekizyun(2,3),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
def point_j(stas):
print("j")
if stas.stt in "xg":
root=accomand(linekizyun(4,3),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
elif stas.stt in "y" or "yl":
root=accomand(linekizyun(4,1),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_k(stas)
def point_k(stas):
print("k")
if stas.stt in "yl":
ballaction(1)
if not (ts.is_pressed):
point_l(stas)
elif stas.stt in "x" or "xg":
root=accomand(linekizyun(4,3),0,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_j(stas)
def point_l(stas):
print("l")
stas.stt="xg"
root=accomand(linekizyun(3,2),1,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_k(stas)
def point_m(stas):
print("m")
if stas.stt in "yp":
root=accomand(linekizyun(1,4),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_o(stas)
elif stas.stt in "yn":
ballaction(1)
if not (ts.is_pressed):
endd()
stas.stt="ee"
elif stas.stt in "xa" or "xh":
root=accomand(linekizyun(1,2),1,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
def point_n(stas):
print("n")
stas.stt="xa"
root=accomand(linekizyun(1,2),1,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
def point_o(stas):
print("o")
if stas.stt in "yp":
ballaction(1)
if not (ts.is_pressed):
point_p(stas)
elif stas.stt in "xa":
root=accomand(linekizyun(1,2),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_m(stas)
def point_p(stas):
print("p")
stas.stt="xh"
root=accomand(linekizyun(1,2),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_m(stas)
def endd():
snd.speak("finish")
def main():
snd.speak("start")
lobo=st()
point_j(lobo)
snd.beep()
if __name__ == '__main__':
main()
以上のプログラムをいくつかに分けて説明していきます。
*** ?プログラムの事前設定と基準値の算出 [#jb56f6b0]
この部分はほとんど課題?と同じです。
#!/usr/bin/env python3
from ev3dev2.motor import *
from ev3dev2.sensor import *
from ev3dev2.sensor.lego import *
from ev3dev2.sound import *
from time import *
この部分で必要な物のインポートをする
Wmax,Bmax,spmax,spmin,brockch,tst=75,5,8,4,6,1.5
ここで使う数値を入力します。この部分以外では極力数値を直...
入力するのは
+ 白色のセンサーの値(Wmax) ==75
+ 黒色のセンサーの値(Bmax) ==5
+ モーターの最高速度(spmax) ==8
+ モーターの最低速度(spmin) ==4
+ 交差点判断する黒色のカウント値(brockch) ==6
+ 交差点等のコマンドの継続時間(tst) ==1.5~
上記の6つです。
これ以外の数値はこれらをもとに計算していきます
- モーターやセンサーを使うための準備を行います。
tw = MoveTank(OUTPUT_B, OUTPUT_C)
Mm= MediumMotor(OUTPUT_A)
cs,ts,us = ColorSensor(),TouchSensor(),UltrasonicSensor()
us.mode = 'US-DIST-CM'
- 入力された数値からプログラムで使うものの決定をしていき...
Mv=(Wmax+Bmax)/2
Lp=(Wmax-Mv)/4
llp=2*Lp
spab=(spmax+spmin)/2
Clev=[Wmax,Wmax-Lp,Mv+Lp,Mv-Lp,Bmax+Lp,Bmax]
-- 白色と黒色の境界線(灰色)でのセンサーの数値
灰色の値を計測する場合正確に境界線の中央を測ることは難し...
Mv=(Wmax+Bmax)/2
-- 色の段階を判断の範囲を決定する
白から黒までを均等に分けるのに使う。ここでは(白色の値-灰...
Lp=(Wmax-Mv)/4
llp=2*Lp
-- 速度の平均値を決定
ライントレースの速度の計算の際に最高速度と最低速度の平均...
spab=(spmax+spmin)/2
-- 色の範囲の基準値をリストとして決定する
白から黒までを5段階に分けるときの基準値を先に求めた数値か...
各段階の基準値は
+ Wmax〜Wmax-Lp
+ Wmax-Lp〜Mv+Lp
+ Mv+Lp〜Mv-Lp
+ Mv-Lp〜Bmax+Lp
+ Bmax+Lp〜Bmax
Clev=[Wmax,Wmax-Lp,Mv+Lp,Mv-Lp,Bmax+Lp,Bmax]
- これで今後使う変数の準備ができました。プログラムを起動...
*** ?ライントレース用のクラス [#vfd492c2]
このクラスは課題?で作成したものをそのまま流用しました。
class Linetorace:
def __init__(self,a):
self.cv=a
self.colortyp,self.dcv,self.lesp,self.risp=0,0,0,0
self.typcheck()
self.movesp()
def typcheck(self):
for i in range(5):
if Clev[i+1]<=self.cv<Clev[i]:
self.colortyp=i
self.dcv=Clev[i]-self.cv
def movesp(self):
zuw=round(self.dcv/llp,1)
if self.colortyp==0:
self.lesp=spab-(spab-spmin)*zuw
self.risp=-spmin
elif self.colortyp==1:
self.lesp=spmax
self.risp=spab+(spmax-spab)*zuw
elif self.colortyp==2:
self.lesp=spmax
self.risp=spmax
elif self.colortyp==3:
self.lesp=spab+(spmax-spab)*zuw
self.risp=spmax
else:
self.lesp=-spmin
self.risp=spab-(spab-spmin)*zuw
カラーセンサーの値を5段階のうちどれに該当するかを判定する...
このクラスはセンサーの値から左右の速度、段階などを取得で...
このクラスのメインである段階分けと左右の速度決定を説明し...
+ 段階分け
カラーセンサーの値を以下の表と照らし合わせて段階数を決め...
|色の段階|白色|白色と灰色の中間|灰色|黒色と灰色の中間|黒色|
|段階数|0|1|2|3|4|
|値の範囲|Wmax〜Wmax-Lp|Wmax-Lp〜Mv+Lp|Mv+Lp〜Mv-Lp|Mv-Lp...
+ 左右の速度決定
段階数が決まったらその段階数ごとに決められた速度を求める...
''(決定した段階の上限-カラーセンサーの値)÷(範囲の幅×2...
|段階数|0|1|2|3|4|
|右の速度(文字)|-(最低速度)|速度の平均値+(最高速度-速...
|右の速度(式)|-spmin|spab+(spmax-spab)*zuw|spmax|spmax|sp...
|左の速度(文字)|速度の平均値-(速度の平均値-最低速度)×調...
|左の速度(式)|spab-(spab-spmin)*zuw|spmax|spmax|spab+(spm...
表からわかるように段階が0と4、1と3は式が左右反対だけで計...
- ''任意による左右の基準を変更可能''~
段階分けの対称および計算式の調整によってライントレースの...
-- 左側の時は右の速度を右のモーターに左の速度を左のモータ...
-- 右側の時は右の速度を左のモーターに左の速度を右のモータ...
*** ?ライントレース関係の一括管理用クラス [#sbb279a1]
class accomand:
def __init__(self,line,cltyp,sttime,endtime):
self.line,self.cltyp,self.sttime,self.endtime=li...
def sendcomand(self):
action(self.line,self.sttime,self.endtime)
closs(self.cltyp,self.line)
このクラスを用いてライントレースと交差点または直角カーブ...
このクラスではライントレースの基準、交差点での動き、交差...
*** ?ベクトルに使うクラス [#d943504f]
class Vector2:
def __init__(self,x,y):
self.x,self.y=x,y
self.comp=complex(x,y)
def disp(self):
print(self.x,",",self.y)
def fukusosuu(self):
print(self.comp)
class houkou:
def __init__(self,hou):
self.hou=hou
self.x,self.y=0,0
self.kakutei()
def kakutei(self):
if self.hou==1:
self.x=1
elif self.hou==2:
self.y=1
elif self.hou==3:
self.x=-1
elif self.hou==4:
self.y=-1
self.ch=complex(self.x,self.y)
この2つのクラスでベクトルの設定と、上下左右の方向を表すベ...
*** ?ロボットのID設定用クラス [#n203d7bb]
class st:
def __init__(self):
self.stt="xg"
self.line,self.point=0,0
def go(self):
print("0")
このクラスを作成して、各点での動きの管理をできるようにし...
ここではIDの初期設定は「xg」となっていますが、もう一方の...
*** ?複素数を用いたライントレースの左右の基準の決定 [#be4...
def linekizyun(linehou,pointhou):
a=houkou(linehou)
b=houkou(pointhou)
che=Vector2(0,1)
if a.ch==(b.ch*che.comp):
print("left")
ty=0
else:
print("ri")
ty=1
return ty
ある道は決まった側をライントレースして進んでほしいですが...
*** ?ライントレース用関数 [#p3613cc8]
def action(line,stti,enti):
sttime1,notime1 = time(),time()
bcon=0
while not (ts.is_pressed) and not ((notime1-sttime1)...
cvp = cs.reflected_light_intensity
MLT=Linetorace(cvp)
if MLT.colortyp==4:
bcon=bcon+1
else:
bcon=0
notime1=time()
if (stti <= (notime1-sttime1) <=enti) and (bcon=...
break
if line==0:
tw.on(MLT.lesp,MLT.risp)
elif line==1:
tw.on(MLT.risp,MLT.lesp)
else:
tw.on(-MLT.lesp,-MLT.risp)
sleep(0.1)
tw.off()
プログラムの構造は課題?とほとんど同じですが、今回はそこに...
3つの引数(ライントレースの基準、交差点判定開始までの時間...
- 1つ目は今のカラーセンサーの値から左右のモーターの速度を...
- 2つ目は交差点または直角カーブに来ているかどうか
の2つです。これらの処理について説明していきます。
+ ライントレース
ここでの処理はタッチセンサーが押されておらずまた、関数の...
while not (ts.is_pressed) and not ((notime1-sttime1)...
cvp = cs.reflected_light_intensity
MLT=Linetorace(cvp)
tw.on(MLT.lesp,MLT.risp)
sleep(0.1)
+ 交差点判定
交差点判定は最初はカラーセンサーの変化の具合から判定しよ...
ここでの処理は1つ目の処理で使ったクラスの段階が黒色の場合...
if MLT.colortyp==4:
bcon=bcon+1
else:
bcon=0
notime1=time()
if (chst <= (notime1-sttime1) <=ched) and (bcon=...
break
この関数は0.1秒おきに色のチェックをするため曲線部分での交...
*** ?直角カーブと交差点での行動用関数 [#q91b87c6]
def closs(pp,line):
cvp= cs.reflected_light_intensity
MLT = Linetorace(cvp)
if line==0:
tw.on(-MLT.lesp,-MLT.risp)
else:
tw.on(-MLT.risp,-MLT.lesp)
sleep(0.1*brockch)
tw.off()
if pp==0:
action(0,tst,tst+0.1)
else:
if pp==1:
action(0,tst,tst+0.1)
elif pp==2:
tw.on_for_seconds(spmax,spmax,1)
else:
action(1,tst,tst+0.1)
tw.off()
引数でカーブ、交差点を左折、右折、直進の4つを指示しそれぞ...
+ 現在のカラーセンサーの値からさっきまでの道を戻る
+ その後4つそれぞれの動きを実行する
といった流れです。~
なぜ交差点での処理で一旦道を戻るのはこの関数が呼び出され...
後は引数の値で処理を変えて4つの行動を分けます。
++ カーブ~
カーブの場合は一旦止まる必要はないのでそのまま黒線の左側...
++ 交差点を左折~
交差点なのでカーブと同様の処理をします。
++ 交差点を直進~
交差点なので左右のモーターを最大速度で1秒間動かします。
++ 交差点を右折~
交差点なので黒線の右側を基準にライントレースを行います。
*** ?ボール関係の行動用関数 [#xc2f5d47]
def ballaction(tp):
face=0
while not (ts.is_pressed):
cvp= cs.reflected_light_intensity
MLT= Linetorace(cvp)
tw.on(MLT.risp,MLT.lesp)
txle= us.distance_centimeters
if txle<=4:
tw.on_for_seconds(4,4,0.9)
face=1
break
sleep(0.1)
tw.off()
if face==1:
print("check")
if tp==0:
Mm.on_for_rotations(20,0.3)
tw.on_for_seconds(-15,-15,1.1)
tw.on_for_degrees(-4,4,360)
else:
Mm.on_for_rotations(-10,0.3)
tw.on_for_seconds(-15,-15,1.1)
tw.on_for_degrees(-4,4,360)
この関数でボールの回収と設置を行います。この関数は缶があ...
*** ?マップ関数 [#q841576d]
専用のマップをプログラムで管理していくための関数を作成し...
+ 缶が設置してある点(A,G,H,L,N,P)
+ 中間点または分岐点~
- 缶が設置してある点に来たということはボールの回収または...
def point_a(stas):
print("a")
root=accomand(linekizyun(1,4),1,0,30)
root.sendcomand()
stas.stt="yl"
if not (ts.is_pressed):
point_b(stas)
-- 点Aの次の点であるBに向かうためのライントレースを行います
root=accomand(linekizyun(1,4),1,0,30)
root.sendcomand()
-- 点Aで回収したボールを点Lに置きに行くためロボットのIDを...
stas.stt="yl"
-- 点Aでの処理が終わったので次の点である点Bの関数を呼び出...
if not (ts.is_pressed):
point_b(stas)
- 中間点または分岐点ではロボットのIDに応じて次の点と行動...
def point_b(stas):
print("b")
if stas.stt in "xa":
ballaction(0)
if not (ts.is_pressed):
point_a(stas)
elif stas.stt in "y" or "xg" or "xh":
root=accomand(linekizyun(2,1),0,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_c(stas)
-- 点BではIDが「xa」の時は点Aに進み、ID「y_」,「xg」,「xh...
- この2種類の点を使いすべての点の関数を作成します。すべて...
*** ?運搬終了用関数 [#t7422e7d]
def point_m(stas):
print("m")
if stas.stt in "yp":
root=accomand(linekizyun(1,4),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_o(stas)
elif stas.stt in "yn":
ballaction(1)
if not (ts.is_pressed):
endd()
stas.stt="ee"
elif stas.stt in "xa" or "xh":
root=accomand(linekizyun(1,2),1,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
def endd():
snd.speak("finish")
?で説明したマップの関数では1台で3つのボールの運搬をできる...
*** ?メインプログラム [#u379c5d1]
def main():
snd.speak("start")
lobo=st()
point_j(lobo)
snd.beep()
if __name__ == '__main__':
main()
プログラムが起動したのをわかりやすくするためにいったん音...
** プログラムのまとめ [#da77f4c5]
本来この課題では2台の間で通信しないといけないのですが、通...
* 結果 [#jff54c82]
本番ではロボット本体とプログラムの両方がうまくできていた...
終了行:
----
目次
#contents
----
* 課題?「ボール運搬ロボット」 [#m7fda309]
下の図の点C,E,Fに置かれた缶の上のボールを点C',E',F'に置か...
&ref(2019b/Member/LaiHen/Mission3/2019b-mission2.png,70%,...
* ロボットについて [#b2d9ff38]
** ロボットの構造について [#p337419d]
今回の課題ではEV3本体を2台使ってロボットを作成できるため...
-1つ目のアイデアは2台を使って1つのロボットを作成する方法
-2つ目のアイデアは2つのロボットを作成する方法です~
この2つのアイデアについて考えていきます。~
1つ目はライントレースに使うモーター2つ以外は自由に使える...
2つ目はライントレースにモーターを2つ使うためロボットそれ...
ここで今回の課題について考えてみると今回ロボットがするの...
こうした考えから下の写真のような同じ型にロボットの作成を...
&ref(2019b/Member/LaiHen/Mission3/lobo1.jpg,40%,ロボット);~
以下でこのロボットの工夫点を説明していきます。
*** アームの小型化 [#ke64d09d]
ロボットの小型化で最も重要なのがアームです。このアームを...
&ref(2019b/Member/LaiHen/Mission3/lobo2.jpg,30%,ロボット);
&ref(2019b/Member/LaiHen/Mission3/lobo3.jpg,30%,ロボット);~
*** センサーの設置 [#p7aab33a]
ロボットの小型化で最も苦労したのが超音波センサーの設置場...
&ref(2019b/Member/LaiHen/Mission3/lobo4.jpg,10%,ロボット);~
** ロボットのまとめ [#o50710eb]
ロボットの作成は相方がメインでやっていたので詳しく説明す...
* プログラムについて [#oab3b1ff]
** プログラムのシステムについて [#w0083243]
今回の課題では同じロボットを2つ用意しているため、1台で缶...
+ 線をたどっていくシステム(ライントレース)
+ 缶の配置や道などのマップ管理システム
+ ルート決定システム~
それぞれのシステムについての説明をしていきます。
*** ライントレースシステム [#l9962598]
このシステムについては課題?で作成したライントレースの基準...
*** マップ管理システム [#u91678d0]
このシステムについては様々な方法が思いつき試行錯誤を重な...
&ref(2019b/Member/LaiHen/Mission3/2019b-mission3_1.png,70...
まず缶の位置と2つのロボットの初期地点である点A,A'から考え...
&ref(2019b/Member/LaiHen/Mission3/2019b-mission3_2.png,70...
そうして上の図の黄色で塗られた部分は、缶があって通れない...
&ref(2019b/Member/LaiHen/Mission3/2019b-mission3_3.png,70...
そうしてできたのが、上の図のマップになります。四角は点を...
*** ルート決定システム [#scddaa10]
先ほど作成したマップを参考にルート決定システムを作成して...
+ ボールを回収するのか設置するのか
+ どこの缶に向かうのか~
この2つでボールを回収しに行っているときは「x」、ボール...
また、点と点の移動の際にどちらを基準にしてライントレース...
&ref(2019b/Member/LaiHen/Mission3/2019b-mission3_4.png,70...
** プログラムの説明 [#ta9d6f93]
先の説明でのシステムをもとにプログラムを作成していきます...
- 1台目のプログラム
#!/usr/bin/env python3
from ev3dev2.motor import *
from ev3dev2.sensor import *
from ev3dev2.sensor.lego import *
from ev3dev2.sound import *
from time import *
Wmax,Bmax,spmax,spmin,brockch,tst,balltime=75,5,8,4,6,2....
tw = MoveTank(OUTPUT_A, OUTPUT_D)
Mm= MediumMotor(OUTPUT_B)
cs,ts,us = ColorSensor(),TouchSensor(),UltrasonicSensor()
us.mode = 'US-DIST-CM'
Mv=(Wmax+Bmax)/2
Lp=(Wmax-Mv)/4
llp=2*Lp
spab=(spmax+spmin)/2
Clev=[Wmax,Wmax-Lp,Mv+Lp,Mv-Lp,Bmax+Lp,Bmax]
ballst=[1,1,1,0,0,0]
snd=Sound()
class Linetorace:
def __init__(self,a):
self.cv=a
self.colortyp,self.dcv,self.lesp,self.risp=0,0,0,0
self.typcheck()
self.movesp()
def typcheck(self):
for i in range(5):
if Clev[i+1]<=self.cv<Clev[i]:
self.colortyp=i
self.dcv=Clev[i]-self.cv
def movesp(self):
zuw=round(self.dcv/llp,1)
if self.colortyp==0:
self.lesp=spab-(spab-spmin)*zuw
self.risp=-spmin
elif self.colortyp==1:
self.lesp=spmax
self.risp=spab+(spmax-spab)*zuw
elif self.colortyp==2:
self.lesp=spmax
self.risp=spmax
elif self.colortyp==3:
self.lesp=spab+(spmax-spab)*zuw
self.risp=spmax
else:
self.lesp=-spmin
self.risp=spab-(spab-spmin)*zuw
class accomand:
def __init__(self,line,cltyp,sttime,endtime):
self.line,self.cltyp,self.sttime,self.endtime=li...
def sendcomand(self):
action(self.line,self.sttime,self.endtime)
closs(self.cltyp,self.line)
class Vector2:
def __init__(self,x,y):
self.x,self.y=x,y
self.comp=complex(x,y)
def disp(self):
print(self.x,",",self.y)
def fukusosuu(self):
print(self.comp)
class houkou:
def __init__(self,hou):
self.hou=hou
self.x,self.y=0,0
self.kakutei()
def kakutei(self):
if self.hou==1:
self.x=1
elif self.hou==2:
self.y=1
elif self.hou==3:
self.x=-1
elif self.hou==4:
self.y=-1
self.ch=complex(self.x,self.y)
class st:
def __init__(self):
self.stt="xa"
self.line,self.point=0,0
def go(self):
print("0")
def linekizyun(linehou,pointhou):
a=houkou(linehou)
b=houkou(pointhou)
che=Vector2(0,1)
if a.ch==(b.ch*che.comp):
print("left")
ty=0
else:
print("ri")
ty=1
return ty
def vector2math(vec1,vec2):
avec=Vector2(vec1.x+vec2.x,vec1.y+vec2.y)
return avec
def action(line,stti,enti):
sttime1,notime1 = time(),time()
bcon=0
while not (ts.is_pressed) and not ((notime1-sttime1)...
cvp = cs.reflected_light_intensity
MLT=Linetorace(cvp)
if MLT.colortyp==4:
bcon=bcon+1
else:
bcon=0
notime1=time()
if (stti <= (notime1-sttime1) <=enti) and (bcon=...
break
if line==0:
tw.on(MLT.lesp,MLT.risp)
elif line==1:
tw.on(MLT.risp,MLT.lesp)
else:
tw.on(-MLT.lesp,-MLT.risp)
sleep(0.1)
tw.off()
def closs(pp,line):
cvp= cs.reflected_light_intensity
MLT = Linetorace(cvp)
if line==0:
tw.on(-MLT.lesp,-MLT.risp)
else:
tw.on(-MLT.risp,-MLT.lesp)
sleep(0.1*brockch)
tw.off()
if pp==0:
action(0,tst,tst+0.1)
else:
if pp==1:
action(0,tst,tst+0.1)
elif pp==2:
tw.on_for_seconds(spmax,spmax,1)
else:
action(1,tst,tst+0.1)
tw.off()
def ballaction(tp):
face=0
while not (ts.is_pressed):
cvp= cs.reflected_light_intensity
MLT= Linetorace(cvp)
tw.on(MLT.risp,MLT.lesp)
txle= us.distance_centimeters
if txle<=4:
tw.on_for_seconds(4,4,0.9)
face=1
break
sleep(0.1)
tw.off()
if face==1:
print("check")
if tp==0:
Mm.on_for_rotations(20,0.3)
tw.on_for_seconds(-15,-15,1.1)
tw.on_for_degrees(-4,4,360)
else:
Mm.on_for_rotations(-10,0.3)
tw.on_for_seconds(-15,-15,1.1)
tw.on_for_degrees(-4,4,360)
def point_a(stas):
print("a")
root=accomand(linekizyun(1,4),1,0,30)
root.sendcomand()
stas.stt="yl"
if not (ts.is_pressed):
point_b(stas)
def point_b(stas):
print("b")
if stas.stt in "xa":
ballaction(0)
if not (ts.is_pressed):
point_a(stas)
elif stas.stt in "y" or "xg" or "xh":
root=accomand(linekizyun(2,1),0,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_c(stas)
def point_c(stas):
sleep(15)
print("c")
if stas.stt in "x":
root=accomand(linekizyun(2,3),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_b(stas)
elif stas.stt in "y" or "yl":
root=accomand(linekizyun(2,1),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
def point_d(stas):
print("d")
if stas.stt in "xa":
root=accomand(linekizyun(2,3),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_c(stas)
elif stas.stt in "yl":
root=accomand(linekizyun(4,2),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
elif stas.stt in "yn":
root=accomand(linekizyun(4,2),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
elif stas.stt in "yp":
root=accomand(linekizyun(4,2),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
elif stas.stt in "xg":
root=accomand(linekizyun(3,2),2,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_e(stas)
elif stas.stt in "xh":
root=accomand(linekizyun(3,2),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_e(stas)
def point_e(stas):
print("e")
if stas.stt in "xg":
root=accomand(linekizyun(3,2),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_f(stas)
if stas.stt in "xh":
ballaction(0)
if not (ts.is_pressed):
point_h(stas)
elif stas.stt in "yp" or "yn":
root=accomand(linekizyun(3,4),1,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
def point_f(stas):
print("f")
if stas.stt in "xg":
ballaction(0)
if not (ts.is_pressed):
point_g(stas)
elif stas.stt in "yp":
root=accomand(linekizyun(3,4),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_e(stas)
def point_g(stas):
print("g")
stas.stt="yp"
root=accomand(linekizyun(3,4),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_e(stas)
def point_h(stas):
print("h")
stas.stt="yn"
root=accomand(linekizyun(3,4),1,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
def point_i(stas):
print("i")
if stas.stt in "xa":
root=accomand(linekizyun(2,3),2,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
elif stas.stt in "yl":
root=accomand(linekizyun(4,1),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_j(stas)
elif stas.stt in "yn":
root=accomand(linekizyun(1,4),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_m(stas)
elif stas.stt in "yp":
root=accomand(linekizyun(1,4),2,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_m(stas)
elif stas.stt in "xg":
root=accomand(1,3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
elif stas.stt in "xh":
root=accomand(linekizyun(2,3),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
def point_j(stas):
print("j")
if stas.stt in "xg":
root=accomand(linekizyun(4,3),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
elif stas.stt in "y" or "yl":
root=accomand(linekizyun(4,1),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_k(stas)
def point_k(stas):
print("k")
if stas.stt in "yl":
ballaction(1)
if not (ts.is_pressed):
point_l(stas)
elif stas.stt in "x" or "xg":
root=accomand(linekizyun(4,3),0,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_j(stas)
def point_l(stas):
print("l")
stas.stt="ee"
root=accomand(linekizyun(3,2),1,0,30)
root.sendcomand()
if not (ts.is_pressed):
endd()
def point_m(stas):
print("m")
if stas.stt in "yp":
root=accomand(linekizyun(1,4),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_o(stas)
elif stas.stt in "yn":
ballaction(1)
if not (ts.is_pressed):
endd()
stas.stt="ee"
elif stas.stt in "xa" or "xh":
root=accomand(linekizyun(1,2),1,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
def point_n(stas):
print("n")
stas.stt="xa"
root=accomand(linekizyun(1,2),1,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
def point_o(stas):
print("o")
if stas.stt in "yp":
ballaction(1)
if not (ts.is_pressed):
point_p(stas)
elif stas.stt in "xa":
root=accomand(linekizyun(1,2),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_m(stas)
def point_p(stas):
print("p")
stas.stt="xh"
root=accomand(linekizyun(1,2),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_m(stas)
def endd():
snd.speak("finish")
def main():
snd.speak("start")
lobo=st()
point_b(lobo)
snd.beep()
if __name__ == '__main__':
main()
- 2台目のプログラム
#!/usr/bin/env python3
from ev3dev2.motor import *
from ev3dev2.sensor import *
from ev3dev2.sensor.lego import *
from ev3dev2.sound import *
from time import *
Wmax,Bmax,spmax,spmin,brockch,tst,balltime=75,5,8,4,6,2....
tw = MoveTank(OUTPUT_A, OUTPUT_D)
Mm= MediumMotor(OUTPUT_B)
cs,ts,us = ColorSensor(),TouchSensor(),UltrasonicSensor()
us.mode = 'US-DIST-CM'
Mv=(Wmax+Bmax)/2
Lp=(Wmax-Mv)/4
llp=2*Lp
spab=(spmax+spmin)/2
Clev=[Wmax,Wmax-Lp,Mv+Lp,Mv-Lp,Bmax+Lp,Bmax]
ballst=[1,1,1,0,0,0]
snd=Sound()
class Linetorace:
def __init__(self,a):
self.cv=a
self.colortyp,self.dcv,self.lesp,self.risp=0,0,0,0
self.typcheck()
self.movesp()
def typcheck(self):
for i in range(5):
if Clev[i+1]<=self.cv<Clev[i]:
self.colortyp=i
self.dcv=Clev[i]-self.cv
def movesp(self):
zuw=round(self.dcv/llp,1)
if self.colortyp==0:
self.lesp=spab-(spab-spmin)*zuw
self.risp=-spmin
elif self.colortyp==1:
self.lesp=spmax
self.risp=spab+(spmax-spab)*zuw
elif self.colortyp==2:
self.lesp=spmax
self.risp=spmax
elif self.colortyp==3:
self.lesp=spab+(spmax-spab)*zuw
self.risp=spmax
else:
self.lesp=-spmin
self.risp=spab-(spab-spmin)*zuw
class accomand:
def __init__(self,line,cltyp,sttime,endtime):
self.line,self.cltyp,self.sttime,self.endtime=li...
def sendcomand(self):
action(self.line,self.sttime,self.endtime)
closs(self.cltyp,self.line)
class Vector2:
def __init__(self,x,y):
self.x,self.y=x,y
self.comp=complex(x,y)
def disp(self):
print(self.x,",",self.y)
def fukusosuu(self):
print(self.comp)
class houkou:
def __init__(self,hou):
self.hou=hou
self.x,self.y=0,0
self.kakutei()
def kakutei(self):
if self.hou==1:
self.x=1
elif self.hou==2:
self.y=1
elif self.hou==3:
self.x=-1
elif self.hou==4:
self.y=-1
self.ch=complex(self.x,self.y)
class st:
def __init__(self):
self.stt="xg"
self.line,self.point=0,0
def go(self):
print("0")
def linekizyun(linehou,pointhou):
a=houkou(linehou)
b=houkou(pointhou)
che=Vector2(0,1)
if a.ch==(b.ch*che.comp):
print("left")
ty=0
else:
print("ri")
ty=1
return ty
def vector2math(vec1,vec2):
avec=Vector2(vec1.x+vec2.x,vec1.y+vec2.y)
return avec
def action(line,stti,enti):
sttime1,notime1 = time(),time()
bcon=0
while not (ts.is_pressed) and not ((notime1-sttime1)...
cvp = cs.reflected_light_intensity
MLT=Linetorace(cvp)
if MLT.colortyp==4:
bcon=bcon+1
else:
bcon=0
notime1=time()
if (stti <= (notime1-sttime1) <=enti) and (bcon=...
break
if line==0:
tw.on(MLT.lesp,MLT.risp)
elif line==1:
tw.on(MLT.risp,MLT.lesp)
else:
tw.on(-MLT.lesp,-MLT.risp)
sleep(0.1)
tw.off()
def closs(pp,line):
cvp= cs.reflected_light_intensity
MLT = Linetorace(cvp)
if line==0:
tw.on(-MLT.lesp,-MLT.risp)
else:
tw.on(-MLT.risp,-MLT.lesp)
sleep(0.1*brockch)
tw.off()
if pp==0:
action(0,tst,tst+0.1)
else:
if pp==1:
action(0,tst,tst+0.1)
elif pp==2:
tw.on_for_seconds(spmax,spmax,1)
else:
action(1,tst,tst+0.1)
tw.off()
def ballaction(tp):
face=0
while not (ts.is_pressed):
cvp= cs.reflected_light_intensity
MLT= Linetorace(cvp)
tw.on(MLT.risp,MLT.lesp)
txle= us.distance_centimeters
if txle<=4:
tw.on_for_seconds(4,4,0.9)
face=1
break
sleep(0.1)
tw.off()
if face==1:
print("check")
if tp==0:
Mm.on_for_rotations(20,0.3)
tw.on_for_seconds(-15,-15,1.1)
tw.on_for_degrees(-4,4,360)
else:
Mm.on_for_rotations(-10,0.3)
tw.on_for_seconds(-15,-15,1.1)
tw.on_for_degrees(-4,4,360)
def point_a(stas):
print("a")
root=accomand(linekizyun(1,4),1,0,30)
root.sendcomand()
stas.stt="yl"
if not (ts.is_pressed):
point_b(stas)
def point_b(stas):
print("b")
if stas.stt in "xa":
ballaction(0)
if not (ts.is_pressed):
point_a(stas)
elif stas.stt in "y" or "xg" or "xh":
root=accomand(linekizyun(2,1),0,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_c(stas)
def point_c(stas):
print("c")
if stas.stt in "x":
root=accomand(linekizyun(2,3),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_b(stas)
elif stas.stt in "y" or "yl":
root=accomand(linekizyun(2,1),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
def point_d(stas):
print("d")
if stas.stt in "xa":
root=accomand(linekizyun(2,3),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_c(stas)
elif stas.stt in "yl":
root=accomand(linekizyun(4,2),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
elif stas.stt in "yn":
root=accomand(linekizyun(4,2),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
elif stas.stt in "yp":
root=accomand(linekizyun(4,2),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
elif stas.stt in "xg":
root=accomand(linekizyun(3,2),2,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_e(stas)
elif stas.stt in "xh":
root=accomand(linekizyun(3,2),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_e(stas)
def point_e(stas):
print("e")
if stas.stt in "xg":
root=accomand(linekizyun(3,2),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_f(stas)
if stas.stt in "xh":
ballaction(0)
if not (ts.is_pressed):
point_h(stas)
elif stas.stt in "yp" or "yn":
root=accomand(linekizyun(3,4),1,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
def point_f(stas):
print("f")
if stas.stt in "xg":
ballaction(0)
if not (ts.is_pressed):
point_g(stas)
elif stas.stt in "yp":
root=accomand(linekizyun(3,4),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_e(stas)
def point_g(stas):
sleep(20)
print("g")
stas.stt="yp"
root=accomand(linekizyun(3,4),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_e(stas)
def point_h(stas):
print("h")
stas.stt="yn"
root=accomand(linekizyun(3,4),1,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
def point_i(stas):
print("i")
if stas.stt in "xa":
root=accomand(linekizyun(2,3),2,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
elif stas.stt in "yl":
root=accomand(linekizyun(4,1),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_j(stas)
elif stas.stt in "yn":
root=accomand(linekizyun(1,4),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_m(stas)
elif stas.stt in "yp":
root=accomand(linekizyun(1,4),2,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_m(stas)
elif stas.stt in "xg":
root=accomand(1,3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
elif stas.stt in "xh":
root=accomand(linekizyun(2,3),3,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_d(stas)
def point_j(stas):
print("j")
if stas.stt in "xg":
root=accomand(linekizyun(4,3),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
elif stas.stt in "y" or "yl":
root=accomand(linekizyun(4,1),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_k(stas)
def point_k(stas):
print("k")
if stas.stt in "yl":
ballaction(1)
if not (ts.is_pressed):
point_l(stas)
elif stas.stt in "x" or "xg":
root=accomand(linekizyun(4,3),0,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_j(stas)
def point_l(stas):
print("l")
stas.stt="xg"
root=accomand(linekizyun(3,2),1,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_k(stas)
def point_m(stas):
print("m")
if stas.stt in "yp":
root=accomand(linekizyun(1,4),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_o(stas)
elif stas.stt in "yn":
ballaction(1)
if not (ts.is_pressed):
endd()
stas.stt="ee"
elif stas.stt in "xa" or "xh":
root=accomand(linekizyun(1,2),1,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
def point_n(stas):
print("n")
stas.stt="xa"
root=accomand(linekizyun(1,2),1,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
def point_o(stas):
print("o")
if stas.stt in "yp":
ballaction(1)
if not (ts.is_pressed):
point_p(stas)
elif stas.stt in "xa":
root=accomand(linekizyun(1,2),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_m(stas)
def point_p(stas):
print("p")
stas.stt="xh"
root=accomand(linekizyun(1,2),2,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_m(stas)
def endd():
snd.speak("finish")
def main():
snd.speak("start")
lobo=st()
point_j(lobo)
snd.beep()
if __name__ == '__main__':
main()
以上のプログラムをいくつかに分けて説明していきます。
*** ?プログラムの事前設定と基準値の算出 [#jb56f6b0]
この部分はほとんど課題?と同じです。
#!/usr/bin/env python3
from ev3dev2.motor import *
from ev3dev2.sensor import *
from ev3dev2.sensor.lego import *
from ev3dev2.sound import *
from time import *
この部分で必要な物のインポートをする
Wmax,Bmax,spmax,spmin,brockch,tst=75,5,8,4,6,1.5
ここで使う数値を入力します。この部分以外では極力数値を直...
入力するのは
+ 白色のセンサーの値(Wmax) ==75
+ 黒色のセンサーの値(Bmax) ==5
+ モーターの最高速度(spmax) ==8
+ モーターの最低速度(spmin) ==4
+ 交差点判断する黒色のカウント値(brockch) ==6
+ 交差点等のコマンドの継続時間(tst) ==1.5~
上記の6つです。
これ以外の数値はこれらをもとに計算していきます
- モーターやセンサーを使うための準備を行います。
tw = MoveTank(OUTPUT_B, OUTPUT_C)
Mm= MediumMotor(OUTPUT_A)
cs,ts,us = ColorSensor(),TouchSensor(),UltrasonicSensor()
us.mode = 'US-DIST-CM'
- 入力された数値からプログラムで使うものの決定をしていき...
Mv=(Wmax+Bmax)/2
Lp=(Wmax-Mv)/4
llp=2*Lp
spab=(spmax+spmin)/2
Clev=[Wmax,Wmax-Lp,Mv+Lp,Mv-Lp,Bmax+Lp,Bmax]
-- 白色と黒色の境界線(灰色)でのセンサーの数値
灰色の値を計測する場合正確に境界線の中央を測ることは難し...
Mv=(Wmax+Bmax)/2
-- 色の段階を判断の範囲を決定する
白から黒までを均等に分けるのに使う。ここでは(白色の値-灰...
Lp=(Wmax-Mv)/4
llp=2*Lp
-- 速度の平均値を決定
ライントレースの速度の計算の際に最高速度と最低速度の平均...
spab=(spmax+spmin)/2
-- 色の範囲の基準値をリストとして決定する
白から黒までを5段階に分けるときの基準値を先に求めた数値か...
各段階の基準値は
+ Wmax〜Wmax-Lp
+ Wmax-Lp〜Mv+Lp
+ Mv+Lp〜Mv-Lp
+ Mv-Lp〜Bmax+Lp
+ Bmax+Lp〜Bmax
Clev=[Wmax,Wmax-Lp,Mv+Lp,Mv-Lp,Bmax+Lp,Bmax]
- これで今後使う変数の準備ができました。プログラムを起動...
*** ?ライントレース用のクラス [#vfd492c2]
このクラスは課題?で作成したものをそのまま流用しました。
class Linetorace:
def __init__(self,a):
self.cv=a
self.colortyp,self.dcv,self.lesp,self.risp=0,0,0,0
self.typcheck()
self.movesp()
def typcheck(self):
for i in range(5):
if Clev[i+1]<=self.cv<Clev[i]:
self.colortyp=i
self.dcv=Clev[i]-self.cv
def movesp(self):
zuw=round(self.dcv/llp,1)
if self.colortyp==0:
self.lesp=spab-(spab-spmin)*zuw
self.risp=-spmin
elif self.colortyp==1:
self.lesp=spmax
self.risp=spab+(spmax-spab)*zuw
elif self.colortyp==2:
self.lesp=spmax
self.risp=spmax
elif self.colortyp==3:
self.lesp=spab+(spmax-spab)*zuw
self.risp=spmax
else:
self.lesp=-spmin
self.risp=spab-(spab-spmin)*zuw
カラーセンサーの値を5段階のうちどれに該当するかを判定する...
このクラスはセンサーの値から左右の速度、段階などを取得で...
このクラスのメインである段階分けと左右の速度決定を説明し...
+ 段階分け
カラーセンサーの値を以下の表と照らし合わせて段階数を決め...
|色の段階|白色|白色と灰色の中間|灰色|黒色と灰色の中間|黒色|
|段階数|0|1|2|3|4|
|値の範囲|Wmax〜Wmax-Lp|Wmax-Lp〜Mv+Lp|Mv+Lp〜Mv-Lp|Mv-Lp...
+ 左右の速度決定
段階数が決まったらその段階数ごとに決められた速度を求める...
''(決定した段階の上限-カラーセンサーの値)÷(範囲の幅×2...
|段階数|0|1|2|3|4|
|右の速度(文字)|-(最低速度)|速度の平均値+(最高速度-速...
|右の速度(式)|-spmin|spab+(spmax-spab)*zuw|spmax|spmax|sp...
|左の速度(文字)|速度の平均値-(速度の平均値-最低速度)×調...
|左の速度(式)|spab-(spab-spmin)*zuw|spmax|spmax|spab+(spm...
表からわかるように段階が0と4、1と3は式が左右反対だけで計...
- ''任意による左右の基準を変更可能''~
段階分けの対称および計算式の調整によってライントレースの...
-- 左側の時は右の速度を右のモーターに左の速度を左のモータ...
-- 右側の時は右の速度を左のモーターに左の速度を右のモータ...
*** ?ライントレース関係の一括管理用クラス [#sbb279a1]
class accomand:
def __init__(self,line,cltyp,sttime,endtime):
self.line,self.cltyp,self.sttime,self.endtime=li...
def sendcomand(self):
action(self.line,self.sttime,self.endtime)
closs(self.cltyp,self.line)
このクラスを用いてライントレースと交差点または直角カーブ...
このクラスではライントレースの基準、交差点での動き、交差...
*** ?ベクトルに使うクラス [#d943504f]
class Vector2:
def __init__(self,x,y):
self.x,self.y=x,y
self.comp=complex(x,y)
def disp(self):
print(self.x,",",self.y)
def fukusosuu(self):
print(self.comp)
class houkou:
def __init__(self,hou):
self.hou=hou
self.x,self.y=0,0
self.kakutei()
def kakutei(self):
if self.hou==1:
self.x=1
elif self.hou==2:
self.y=1
elif self.hou==3:
self.x=-1
elif self.hou==4:
self.y=-1
self.ch=complex(self.x,self.y)
この2つのクラスでベクトルの設定と、上下左右の方向を表すベ...
*** ?ロボットのID設定用クラス [#n203d7bb]
class st:
def __init__(self):
self.stt="xg"
self.line,self.point=0,0
def go(self):
print("0")
このクラスを作成して、各点での動きの管理をできるようにし...
ここではIDの初期設定は「xg」となっていますが、もう一方の...
*** ?複素数を用いたライントレースの左右の基準の決定 [#be4...
def linekizyun(linehou,pointhou):
a=houkou(linehou)
b=houkou(pointhou)
che=Vector2(0,1)
if a.ch==(b.ch*che.comp):
print("left")
ty=0
else:
print("ri")
ty=1
return ty
ある道は決まった側をライントレースして進んでほしいですが...
*** ?ライントレース用関数 [#p3613cc8]
def action(line,stti,enti):
sttime1,notime1 = time(),time()
bcon=0
while not (ts.is_pressed) and not ((notime1-sttime1)...
cvp = cs.reflected_light_intensity
MLT=Linetorace(cvp)
if MLT.colortyp==4:
bcon=bcon+1
else:
bcon=0
notime1=time()
if (stti <= (notime1-sttime1) <=enti) and (bcon=...
break
if line==0:
tw.on(MLT.lesp,MLT.risp)
elif line==1:
tw.on(MLT.risp,MLT.lesp)
else:
tw.on(-MLT.lesp,-MLT.risp)
sleep(0.1)
tw.off()
プログラムの構造は課題?とほとんど同じですが、今回はそこに...
3つの引数(ライントレースの基準、交差点判定開始までの時間...
- 1つ目は今のカラーセンサーの値から左右のモーターの速度を...
- 2つ目は交差点または直角カーブに来ているかどうか
の2つです。これらの処理について説明していきます。
+ ライントレース
ここでの処理はタッチセンサーが押されておらずまた、関数の...
while not (ts.is_pressed) and not ((notime1-sttime1)...
cvp = cs.reflected_light_intensity
MLT=Linetorace(cvp)
tw.on(MLT.lesp,MLT.risp)
sleep(0.1)
+ 交差点判定
交差点判定は最初はカラーセンサーの変化の具合から判定しよ...
ここでの処理は1つ目の処理で使ったクラスの段階が黒色の場合...
if MLT.colortyp==4:
bcon=bcon+1
else:
bcon=0
notime1=time()
if (chst <= (notime1-sttime1) <=ched) and (bcon=...
break
この関数は0.1秒おきに色のチェックをするため曲線部分での交...
*** ?直角カーブと交差点での行動用関数 [#q91b87c6]
def closs(pp,line):
cvp= cs.reflected_light_intensity
MLT = Linetorace(cvp)
if line==0:
tw.on(-MLT.lesp,-MLT.risp)
else:
tw.on(-MLT.risp,-MLT.lesp)
sleep(0.1*brockch)
tw.off()
if pp==0:
action(0,tst,tst+0.1)
else:
if pp==1:
action(0,tst,tst+0.1)
elif pp==2:
tw.on_for_seconds(spmax,spmax,1)
else:
action(1,tst,tst+0.1)
tw.off()
引数でカーブ、交差点を左折、右折、直進の4つを指示しそれぞ...
+ 現在のカラーセンサーの値からさっきまでの道を戻る
+ その後4つそれぞれの動きを実行する
といった流れです。~
なぜ交差点での処理で一旦道を戻るのはこの関数が呼び出され...
後は引数の値で処理を変えて4つの行動を分けます。
++ カーブ~
カーブの場合は一旦止まる必要はないのでそのまま黒線の左側...
++ 交差点を左折~
交差点なのでカーブと同様の処理をします。
++ 交差点を直進~
交差点なので左右のモーターを最大速度で1秒間動かします。
++ 交差点を右折~
交差点なので黒線の右側を基準にライントレースを行います。
*** ?ボール関係の行動用関数 [#xc2f5d47]
def ballaction(tp):
face=0
while not (ts.is_pressed):
cvp= cs.reflected_light_intensity
MLT= Linetorace(cvp)
tw.on(MLT.risp,MLT.lesp)
txle= us.distance_centimeters
if txle<=4:
tw.on_for_seconds(4,4,0.9)
face=1
break
sleep(0.1)
tw.off()
if face==1:
print("check")
if tp==0:
Mm.on_for_rotations(20,0.3)
tw.on_for_seconds(-15,-15,1.1)
tw.on_for_degrees(-4,4,360)
else:
Mm.on_for_rotations(-10,0.3)
tw.on_for_seconds(-15,-15,1.1)
tw.on_for_degrees(-4,4,360)
この関数でボールの回収と設置を行います。この関数は缶があ...
*** ?マップ関数 [#q841576d]
専用のマップをプログラムで管理していくための関数を作成し...
+ 缶が設置してある点(A,G,H,L,N,P)
+ 中間点または分岐点~
- 缶が設置してある点に来たということはボールの回収または...
def point_a(stas):
print("a")
root=accomand(linekizyun(1,4),1,0,30)
root.sendcomand()
stas.stt="yl"
if not (ts.is_pressed):
point_b(stas)
-- 点Aの次の点であるBに向かうためのライントレースを行います
root=accomand(linekizyun(1,4),1,0,30)
root.sendcomand()
-- 点Aで回収したボールを点Lに置きに行くためロボットのIDを...
stas.stt="yl"
-- 点Aでの処理が終わったので次の点である点Bの関数を呼び出...
if not (ts.is_pressed):
point_b(stas)
- 中間点または分岐点ではロボットのIDに応じて次の点と行動...
def point_b(stas):
print("b")
if stas.stt in "xa":
ballaction(0)
if not (ts.is_pressed):
point_a(stas)
elif stas.stt in "y" or "xg" or "xh":
root=accomand(linekizyun(2,1),0,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_c(stas)
-- 点BではIDが「xa」の時は点Aに進み、ID「y_」,「xg」,「xh...
- この2種類の点を使いすべての点の関数を作成します。すべて...
*** ?運搬終了用関数 [#t7422e7d]
def point_m(stas):
print("m")
if stas.stt in "yp":
root=accomand(linekizyun(1,4),3,0,30)
root.sendcomand()
if not (ts.is_pressed):
point_o(stas)
elif stas.stt in "yn":
ballaction(1)
if not (ts.is_pressed):
endd()
stas.stt="ee"
elif stas.stt in "xa" or "xh":
root=accomand(linekizyun(1,2),1,2,30)
root.sendcomand()
if not (ts.is_pressed):
point_i(stas)
def endd():
snd.speak("finish")
?で説明したマップの関数では1台で3つのボールの運搬をできる...
*** ?メインプログラム [#u379c5d1]
def main():
snd.speak("start")
lobo=st()
point_j(lobo)
snd.beep()
if __name__ == '__main__':
main()
プログラムが起動したのをわかりやすくするためにいったん音...
** プログラムのまとめ [#da77f4c5]
本来この課題では2台の間で通信しないといけないのですが、通...
* 結果 [#jff54c82]
本番ではロボット本体とプログラムの両方がうまくできていた...
ページ名: