2017a/Member/sianna/Mission2
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
#contents
*課題について [#k833dc5c]
課題概要については→[[課題2:http://yakushi.shinshu-u.ac.j...
#ref(./2017a-mission2.png);
~E地点を右折するプログラムを作成した。
~・E地点右折コース
~E右折(SOUND_UP)
~P一時停止(SOUND_DOWN)&左折
~Q(SOUND_UP)&直進
~R(SOUND_UP)&左折
~T一時停止(SOUND_DOWN)&直進
~T一時停止(SOUND_DOWN)&直進
~H(SOUND_UP)
~G(SOUND_UP)
~S一時停止(SOUND_DOWN)&左折
~P直進(SOUND_UP)
~Q左折(SOUND_UP)
~F(SOUND_UP)
~E直進
~A停止(SOUND_DOWN)
*ロボットの構造について [#kefa40d7]
#ref(./DSC_0402.JPG,10%.);
ロボットの長さは16.9cm、幅は14.0cm、高さは15.5cmである。...
*プログラム [#e25666b8]
**定義部分 [#f3c42062]
#define THRESHOLD 39
#define HIPOWER 7
#define LOWPOWER 2
#define set_power_H SetPower(OUT_AC,HIPOWER);
#define set_power_L SetPower(OUT_AC,LOWPOWER);
#define go_forward set_power_H;OnFwd(OUT_AC);
#define turn_right1 set_power_L;OnFwd(OUT_C); OnRev(OUT...
#define turn_right0 set_power_L;OnFwd(OUT_C); Off(OUT_A);
#define turn_left0 set_power_L;OnFwd(OUT_A); Off(OUT_C);
#define turn_left1 set_power_L;OnFwd(OUT_A); OnRev(OUT_...
#define Break Off(OUT_AC);Wait(100);
まずは閾値(明暗を判別する際の境界の値)を計測の結果から39...
**サブルーチン [#u7d48f44]
sub L_LINE()
{int Black_Time; Black_Time=0;
while(Black_Time < 6){
if (SENSOR_2 < THRESHOLD -2) {
turn_left1; Black_Time++;
} else if (SENSOR_2 < THRESHOLD -1) {
turn_left0; Black_Time++;
} else if (SENSOR_2 < THRESHOLD +1) {
go_forward;
} else if (SENSOR_2 < THRESHOLD +2) {
turn_right0; Black_Time = 0;
} else {
turn_right1; Black_Time = 0;
}
Wait(1);}
}
sub R_LINE()
{int Black_Time; Black_Time=0;
while(Black_Time < 6){
if (SENSOR_2 < THRESHOLD -2) {
turn_right1; Black_Time++;
} else if (SENSOR_2 < THRESHOLD -1) {
turn_right0; Black_Time++;
} else if (SENSOR_2 < THRESHOLD +1) {
go_forward;
} else if (SENSOR_2 < THRESHOLD +2) {
turn_left0; Black_Time = 0;
} else {
turn_left1; Black_Time = 0;
}
Wait(1);}
}
まず黒い線の左側をトレースするプログラムと右側をトレース...
**動作プログラム [#y1433ac9]
task main()
{
SetSensor(SENSOR_2,SENSOR_LIGHT);
int C_TIME;
C_TIME = 0;
int Black_Time;
Black_Time=0;
if(C_TIME ==0) //A出発
{ R_LINE();
C_TIME++;
}
if(C_TIME == 1) //E右折
{
PlaySound(SOUND_UP);
ClearTimer(0);
while(FastTimer(0) < 100)
{if (SENSOR_2 < THRESHOLD -2) {
turn_right1; Black_Time++;
} else if (SENSOR_2 < THRESHOLD -1) {
turn_right0; Black_Time++;
} else if (SENSOR_2 < THRESHOLD +1) {
go_forward;
} else if (SENSOR_2 < THRESHOLD +2) {
turn_left0; Black_Time = 0;
} else {
turn_left1; Black_Time = 0;
}
Wait(1);
}
R_LINE();
C_TIME++;
}
if(C_TIME == 2) //P左折
{
PlaySound(SOUND_DOWN);
Break;
turn_left1;
Wait(75);
go_forward;
Wait(10);
L_LINE();
C_TIME++;
}
if(C_TIME == 3) //Q通過
{ PlaySound(SOUND_UP);
turn_right0;
Wait(60);
L_LINE();
C_TIME++;
}
if(C_TIME == 4) //R左折
{ PlaySound(SOUND_UP);
ClearTimer(0);
while(FastTimer(0) < 100)
{if (SENSOR_2 < THRESHOLD -2) {
turn_left1; Black_Time++;
} else if (SENSOR_2 < THRESHOLD -1) {
turn_left0; Black_Time++;
} else if (SENSOR_2 < THRESHOLD +1) {
go_forward;
} else if (SENSOR_2 < THRESHOLD +2) {
turn_right0; Black_Time = 0;
} else {
turn_right1; Black_Time = 0;
}
Wait(1);
}
L_LINE();
C_TIME++;
}
if(C_TIME == 5) //T通過
{ PlaySound(SOUND_DOWN);
Break;
turn_right0;
Wait(90);
R_LINE();
C_TIME++;
}
if(C_TIME == 6) //T通過
{ PlaySound(SOUND_DOWN);
Break;
turn_left0;
Wait(40);
R_LINE();
C_TIME++;
}
if(C_TIME == 7) //H通過
{ PlaySound(SOUND_UP);
ClearTimer(0);
while(FastTimer(0) < 100)
{if (SENSOR_2 < THRESHOLD -2) {
turn_right1; Black_Time++;
} else if (SENSOR_2 < THRESHOLD -1) {
turn_right0; Black_Time++;
} else if (SENSOR_2 < THRESHOLD +1) {
go_forward;
} else if (SENSOR_2 < THRESHOLD +2) {
turn_left0; Black_Time = 0;
} else {
turn_left1; Black_Time = 0;
}
Wait(1);
}
R_LINE();
C_TIME++;
}
if(C_TIME == 8) //二個目のヘアピン通過
{ turn_right1;
Wait(65);
turn_right0;
Wait(145);
R_LINE();
C_TIME++;
}
if(C_TIME == 9) //G通過
{ PlaySound(SOUND_UP);
ClearTimer(0);
while(FastTimer(0) < 100)
{if (SENSOR_2 < THRESHOLD -2) {
turn_right1; Black_Time++;
} else if (SENSOR_2 < THRESHOLD -1) {
turn_right0; Black_Time++;
} else if (SENSOR_2 < THRESHOLD +1) {
go_forward;
} else if (SENSOR_2 < THRESHOLD +2) {
turn_left0; Black_Time = 0;
} else {
turn_left1; Black_Time = 0;
}
Wait(1);
}
R_LINE();
C_TIME++;
}
if(C_TIME == 10) //S左折
{
PlaySound(SOUND_DOWN);
Break;
turn_left1;
Wait(75);
go_forward;
Wait(10);
L_LINE();
C_TIME++;
}
if(C_TIME == 11) //P通過
{ PlaySound(SOUND_UP);
turn_right0;
Wait(60);
L_LINE();
C_TIME++;
}
if(C_TIME == 12) //Q左折
{ PlaySound(SOUND_UP);
turn_left0;
Wait(30);
go_forward;
Wait(30);
R_LINE();
C_TIME++;
}
if(C_TIME == 13) //F通過
{ PlaySound(SOUND_UP);
ClearTimer(0);
while(FastTimer(0) < 100)
{if (SENSOR_2 < THRESHOLD -2) {
turn_right1; Black_Time++;
} else if (SENSOR_2 < THRESHOLD -1) {
turn_right0; Black_Time++;
} else if (SENSOR_2 < THRESHOLD +1) {
go_forward;
} else if (SENSOR_2 < THRESHOLD +2) {
turn_left0; Black_Time = 0;
} else {
turn_left1; Black_Time = 0;
}
Wait(1);
}
R_LINE();
C_TIME++;
}
if(C_TIME == 14) //A到着
{ Off(OUT_AC);
PlaySound(SOUND_DOWN);
}
}
初めにC_TIMEを定義して、何回交差点と判断したかを数え上げ...
*感想 [#q4a9f14c]
最初はかなり苦労したし挫折しかけた。なにより何が原因で上...
終了行:
#contents
*課題について [#k833dc5c]
課題概要については→[[課題2:http://yakushi.shinshu-u.ac.j...
#ref(./2017a-mission2.png);
~E地点を右折するプログラムを作成した。
~・E地点右折コース
~E右折(SOUND_UP)
~P一時停止(SOUND_DOWN)&左折
~Q(SOUND_UP)&直進
~R(SOUND_UP)&左折
~T一時停止(SOUND_DOWN)&直進
~T一時停止(SOUND_DOWN)&直進
~H(SOUND_UP)
~G(SOUND_UP)
~S一時停止(SOUND_DOWN)&左折
~P直進(SOUND_UP)
~Q左折(SOUND_UP)
~F(SOUND_UP)
~E直進
~A停止(SOUND_DOWN)
*ロボットの構造について [#kefa40d7]
#ref(./DSC_0402.JPG,10%.);
ロボットの長さは16.9cm、幅は14.0cm、高さは15.5cmである。...
*プログラム [#e25666b8]
**定義部分 [#f3c42062]
#define THRESHOLD 39
#define HIPOWER 7
#define LOWPOWER 2
#define set_power_H SetPower(OUT_AC,HIPOWER);
#define set_power_L SetPower(OUT_AC,LOWPOWER);
#define go_forward set_power_H;OnFwd(OUT_AC);
#define turn_right1 set_power_L;OnFwd(OUT_C); OnRev(OUT...
#define turn_right0 set_power_L;OnFwd(OUT_C); Off(OUT_A);
#define turn_left0 set_power_L;OnFwd(OUT_A); Off(OUT_C);
#define turn_left1 set_power_L;OnFwd(OUT_A); OnRev(OUT_...
#define Break Off(OUT_AC);Wait(100);
まずは閾値(明暗を判別する際の境界の値)を計測の結果から39...
**サブルーチン [#u7d48f44]
sub L_LINE()
{int Black_Time; Black_Time=0;
while(Black_Time < 6){
if (SENSOR_2 < THRESHOLD -2) {
turn_left1; Black_Time++;
} else if (SENSOR_2 < THRESHOLD -1) {
turn_left0; Black_Time++;
} else if (SENSOR_2 < THRESHOLD +1) {
go_forward;
} else if (SENSOR_2 < THRESHOLD +2) {
turn_right0; Black_Time = 0;
} else {
turn_right1; Black_Time = 0;
}
Wait(1);}
}
sub R_LINE()
{int Black_Time; Black_Time=0;
while(Black_Time < 6){
if (SENSOR_2 < THRESHOLD -2) {
turn_right1; Black_Time++;
} else if (SENSOR_2 < THRESHOLD -1) {
turn_right0; Black_Time++;
} else if (SENSOR_2 < THRESHOLD +1) {
go_forward;
} else if (SENSOR_2 < THRESHOLD +2) {
turn_left0; Black_Time = 0;
} else {
turn_left1; Black_Time = 0;
}
Wait(1);}
}
まず黒い線の左側をトレースするプログラムと右側をトレース...
**動作プログラム [#y1433ac9]
task main()
{
SetSensor(SENSOR_2,SENSOR_LIGHT);
int C_TIME;
C_TIME = 0;
int Black_Time;
Black_Time=0;
if(C_TIME ==0) //A出発
{ R_LINE();
C_TIME++;
}
if(C_TIME == 1) //E右折
{
PlaySound(SOUND_UP);
ClearTimer(0);
while(FastTimer(0) < 100)
{if (SENSOR_2 < THRESHOLD -2) {
turn_right1; Black_Time++;
} else if (SENSOR_2 < THRESHOLD -1) {
turn_right0; Black_Time++;
} else if (SENSOR_2 < THRESHOLD +1) {
go_forward;
} else if (SENSOR_2 < THRESHOLD +2) {
turn_left0; Black_Time = 0;
} else {
turn_left1; Black_Time = 0;
}
Wait(1);
}
R_LINE();
C_TIME++;
}
if(C_TIME == 2) //P左折
{
PlaySound(SOUND_DOWN);
Break;
turn_left1;
Wait(75);
go_forward;
Wait(10);
L_LINE();
C_TIME++;
}
if(C_TIME == 3) //Q通過
{ PlaySound(SOUND_UP);
turn_right0;
Wait(60);
L_LINE();
C_TIME++;
}
if(C_TIME == 4) //R左折
{ PlaySound(SOUND_UP);
ClearTimer(0);
while(FastTimer(0) < 100)
{if (SENSOR_2 < THRESHOLD -2) {
turn_left1; Black_Time++;
} else if (SENSOR_2 < THRESHOLD -1) {
turn_left0; Black_Time++;
} else if (SENSOR_2 < THRESHOLD +1) {
go_forward;
} else if (SENSOR_2 < THRESHOLD +2) {
turn_right0; Black_Time = 0;
} else {
turn_right1; Black_Time = 0;
}
Wait(1);
}
L_LINE();
C_TIME++;
}
if(C_TIME == 5) //T通過
{ PlaySound(SOUND_DOWN);
Break;
turn_right0;
Wait(90);
R_LINE();
C_TIME++;
}
if(C_TIME == 6) //T通過
{ PlaySound(SOUND_DOWN);
Break;
turn_left0;
Wait(40);
R_LINE();
C_TIME++;
}
if(C_TIME == 7) //H通過
{ PlaySound(SOUND_UP);
ClearTimer(0);
while(FastTimer(0) < 100)
{if (SENSOR_2 < THRESHOLD -2) {
turn_right1; Black_Time++;
} else if (SENSOR_2 < THRESHOLD -1) {
turn_right0; Black_Time++;
} else if (SENSOR_2 < THRESHOLD +1) {
go_forward;
} else if (SENSOR_2 < THRESHOLD +2) {
turn_left0; Black_Time = 0;
} else {
turn_left1; Black_Time = 0;
}
Wait(1);
}
R_LINE();
C_TIME++;
}
if(C_TIME == 8) //二個目のヘアピン通過
{ turn_right1;
Wait(65);
turn_right0;
Wait(145);
R_LINE();
C_TIME++;
}
if(C_TIME == 9) //G通過
{ PlaySound(SOUND_UP);
ClearTimer(0);
while(FastTimer(0) < 100)
{if (SENSOR_2 < THRESHOLD -2) {
turn_right1; Black_Time++;
} else if (SENSOR_2 < THRESHOLD -1) {
turn_right0; Black_Time++;
} else if (SENSOR_2 < THRESHOLD +1) {
go_forward;
} else if (SENSOR_2 < THRESHOLD +2) {
turn_left0; Black_Time = 0;
} else {
turn_left1; Black_Time = 0;
}
Wait(1);
}
R_LINE();
C_TIME++;
}
if(C_TIME == 10) //S左折
{
PlaySound(SOUND_DOWN);
Break;
turn_left1;
Wait(75);
go_forward;
Wait(10);
L_LINE();
C_TIME++;
}
if(C_TIME == 11) //P通過
{ PlaySound(SOUND_UP);
turn_right0;
Wait(60);
L_LINE();
C_TIME++;
}
if(C_TIME == 12) //Q左折
{ PlaySound(SOUND_UP);
turn_left0;
Wait(30);
go_forward;
Wait(30);
R_LINE();
C_TIME++;
}
if(C_TIME == 13) //F通過
{ PlaySound(SOUND_UP);
ClearTimer(0);
while(FastTimer(0) < 100)
{if (SENSOR_2 < THRESHOLD -2) {
turn_right1; Black_Time++;
} else if (SENSOR_2 < THRESHOLD -1) {
turn_right0; Black_Time++;
} else if (SENSOR_2 < THRESHOLD +1) {
go_forward;
} else if (SENSOR_2 < THRESHOLD +2) {
turn_left0; Black_Time = 0;
} else {
turn_left1; Black_Time = 0;
}
Wait(1);
}
R_LINE();
C_TIME++;
}
if(C_TIME == 14) //A到着
{ Off(OUT_AC);
PlaySound(SOUND_DOWN);
}
}
初めにC_TIMEを定義して、何回交差点と判断したかを数え上げ...
*感想 [#q4a9f14c]
最初はかなり苦労したし挫折しかけた。なにより何が原因で上...
ページ名: