• R/O
  • SSH
  • HTTPS

team-ncxx-sl: Commit


Commit MetaInfo

Revision455 (tree)
Time2020-10-21 18:51:23
Authormizutani-f

Log Message

ガレージ攻略クラス更新
ブロック運び攻略クラスを一部チューニング

Change Summary

Incremental Difference

--- trunk/workspace/sample_2020/course/CarryBlock.cpp (revision 454)
+++ trunk/workspace/sample_2020/course/CarryBlock.cpp (revision 455)
@@ -89,7 +89,7 @@
8989 result = true;
9090 }
9191 }
92- return false;
92+ return result;
9393 }
9494
9595 // 現在のモードの処理を終了するか判定
@@ -119,7 +119,7 @@
119119 endCount = 730;
120120 break;
121121 case CarryBlockMode_UTurn:
122- endCount = 530;
122+ endCount = 540;
123123 break;
124124 case CarryBlockMode_AimBlueLine:
125125 endCount = 2000;
@@ -172,6 +172,7 @@
172172 // RGB値を取得
173173 rgb_raw_t RGB_val = GetColorSensorRGBRaw();
174174 if (RGB_val.b >= 120 && RGB_val.g <= 120)
175+ //if(RGB_val.b >= 100 && RGB_val.r <= 20) // ガレージクラスの値
175176 {
176177 isDetected = true;
177178 }
--- trunk/workspace/sample_2020/course/Garage.cpp (revision 454)
+++ trunk/workspace/sample_2020/course/Garage.cpp (revision 455)
@@ -1,21 +1,168 @@
11 #include "Garage.h"
2+#define GRAGE_FORWARD_DEFAULT 50
3+#define GRAGE_TURN_DEFAULT 40
24
5+#define GRAGE_DEFAULT_WHITE 33
6+#define GRAGE_DEFAULT_BLACK 0
7+
38 // OverRide
49 void Garage::Run()
510 {
11+ IsNextMode();
12+ // テストログ(カウント、モード監視用)
13+ // char log[200];
14+ // int tmp = ev3_color_sensor_get_reflect(cConst->color_sensor);
15+ // int distance = ev3_ultrasonic_sensor_get_distance(cConst->sonar_sensor);
16+ // rgb_raw_t RGB_val = GetColorSensorRGBRaw();
17+ // sprintf(log, "mode:%d color:%d r:%d g:%d b:%d" , (int)mode, tmp, (int)RGB_val.r, (int)RGB_val.g, (int)RGB_val.b);
18+ // _log(log);
19+
620 switch(mode)
721 {
8- case GarageMode_Start:
9- BaseCourse::Run();
22+ case GarageMode_BlackLineTrace: // 黒線ライントレース(ブロック運び後に入る状態)
23+ //cConst->SetColorSensorValue(GRAGE_DEFAULT_WHITE, GRAGE_DEFAULT_BLACK);
24+ SetForwardAndTurn(GRAGE_FORWARD_DEFAULT, GRAGE_TURN_DEFAULT);
1025 break;
11-
26+ case GarageMode_BlueLineTrace: // 青線ライントレース
27+ //cConst->SetColorSensorValue(GRAGE_DEFAULT_WHITE, GRAGE_DEFAULT_BLACK);
28+ SetForwardAndTurn(GRAGE_FORWARD_DEFAULT, GRAGE_TURN_DEFAULT);
29+ break;
30+ case Garagemode_AfterBlueLineTrace: // 青線終了後の黒線ライントレース
31+ //cConst->SetColorSensorValue(GRAGE_DEFAULT_WHITE, GRAGE_DEFAULT_BLACK);
32+ SetForwardAndTurn(GRAGE_FORWARD_DEFAULT, GRAGE_TURN_DEFAULT);
33+ break;
34+ case GarageMode_DecideStopPosition: // ガレージ停止位置決定(ライントレース無し)
35+ //cConst->SetColorSensorValue(GRAGE_DEFAULT_WHITE, GRAGE_DEFAULT_BLACK);
36+ SetForwardAndTurn(30, 0);
37+ break;
38+ case GarageMode_Stop: // 停止状態
39+ break;
1240 default:
1341 break;
1442 }
43+
44+ // モーター制御
45+ if(GarageMode_Stop != mode)
46+ {
47+ DecideTurnSign();
48+ BaseCourse::Run();
49+ }
50+ else
51+ {
52+ stopCount++;
53+ MotorStop();
54+ }
1555 }
1656
1757 // OverRide
1858 bool Garage::IsNextCourse()
1959 {
20- return false;
60+ bool result = false;
61+ // 停止状態で10秒停止したら次モードへ(2020年コースでは次コース無しの為走行終了)
62+ if(GarageMode_Stop == mode && stopCount > (int)(10000 / PROCESS_PERIOD))
63+ {
64+ result = true;
65+ }
66+ return result;
67+}
68+
69+// モード切り替え判定
70+void Garage::IsNextMode()
71+{
72+ bool isNextMode = false;
73+ GarageMode nextMode = mode;
74+ bool isDetectedBlue = false;
75+ int distance = BaseCourse::GetWheelAngleAverage();
76+ int sonorDistance = ev3_ultrasonic_sensor_get_distance(cConst->sonar_sensor);
77+ switch(mode)
78+ {
79+ case GarageMode_BlackLineTrace: // 黒線ライントレース(ブロック運び後に入る状態)
80+ // ブルーライン確認
81+ isDetectedBlue = DetectBlueLine();
82+ // 検知回数操作
83+ if(isDetectedBlue)
84+ {
85+ detectBlueLineCount++;
86+ }
87+ else
88+ {
89+ detectBlueLineCount = 0;
90+ }
91+ detectBlueLine = isDetectedBlue;
92+
93+ // 3回以上連続でブルーラインを検知したらモード切り替え
94+ if(detectBlueLineCount > 2)
95+ {
96+ // 青線ライントレースモードへ
97+ nextMode = GarageMode_BlueLineTrace;
98+ isNextMode = true;
99+ }
100+ // 走行距離が100以上ならば青線検知不可としてモード切り替え
101+ else if(distance - modeStartDistance > 200)
102+ {
103+ nextMode = Garagemode_AfterBlueLineTrace;
104+ isNextMode = true;
105+ }
106+ break;
107+ case GarageMode_BlueLineTrace: // 青線ライントレース
108+ // ブルーライン確認
109+ isDetectedBlue = DetectBlueLine();
110+ // 非検知回数操作
111+ if(!detectBlueLine)
112+ {
113+ nonDetectBlueLineCount++;
114+ }
115+ else
116+ {
117+ nonDetectBlueLineCount = 0;
118+ }
119+ detectBlueLine = isDetectedBlue;
120+ // 5回以上連続でブルーラインを非検知ならモード切り替え
121+ if(nonDetectBlueLineCount > 4)
122+ {
123+ // 青線終了後の黒線ライントレースモードへ
124+ nextMode = Garagemode_AfterBlueLineTrace;
125+ isNextMode = true;
126+ }
127+ break;
128+ case Garagemode_AfterBlueLineTrace: // 青線終了後の黒線ライントレース
129+ if((distance - modeStartDistance) > 100)
130+ {
131+ nextMode = GarageMode_DecideStopPosition;
132+ isNextMode = true;
133+ }
134+ break;
135+ case GarageMode_DecideStopPosition: // ガレージ停止位置決定(ライントレース無し)
136+ //if(BaseCourse::SonarAlert())
137+ if(sonorDistance < 16)
138+ {
139+ nextMode = GarageMode_Stop;
140+ isNextMode = true;
141+ }
142+ break;
143+ case GarageMode_Stop: // 停止状態
144+ break;
145+ default:
146+ break;
147+ }
148+
149+ // モード切り替え
150+ if(isNextMode)
151+ {
152+ mode = nextMode;
153+ modeStartDistance = distance;
154+ }
155+}
156+
157+bool Garage::DetectBlueLine()
158+{
159+ bool isDetected = false;
160+ // RGB値を取得
161+ rgb_raw_t RGB_val = GetColorSensorRGBRaw();
162+ if (RGB_val.b >= 100 && RGB_val.r <= 20)
163+ {
164+ isDetected = true;
165+ }
166+
167+ return isDetected;
21168 }
\ No newline at end of file
--- trunk/workspace/sample_2020/course/Garage.h (revision 454)
+++ trunk/workspace/sample_2020/course/Garage.h (revision 455)
@@ -3,23 +3,44 @@
33
44 #include "BaseCourse.h"
55
6-// コース攻略モード(仮作成)
6+// コース攻略モード
77 enum GarageMode
8-{
9- GarageMode_Start = 0,
8+{
9+ GarageMode_BlackLineTrace = 0, // 黒線ライントレース(ブロック運び後に入る状態)
10+ GarageMode_BlueLineTrace, // 青線ライントレース
11+ Garagemode_AfterBlueLineTrace, // 青線終了後の黒線ライントレース
12+ GarageMode_DecideStopPosition, // ガレージ停止位置決定(ライントレース無し)
13+ GarageMode_Stop // 停止状態
1014 };
1115
1216 class Garage : public BaseCourse
1317 {
1418 private:
15- GarageMode mode;
19+ GarageMode mode; // 攻略モード
20+ bool detectBlueLine; // ブルーラインを検知中か
21+ int detectBlueLineCount; // ブルーラインの連続検知回数(黒線ライントレースモード用)
22+ int nonDetectBlueLineCount; // ブルーラインの連続検出不可回数(青線ライントレースモード用)
23+ int stopCount; // 停止状態実行回数(停止状態用)
24+ int modeStartDistance; // モード開始時の距離
1625 public:
26+ // override
1727 void Run();
28+ // override
1829 bool IsNextCourse();
30+
31+ // モード切り替え判定
32+ void IsNextMode();
33+ // ブルーラインを検知する
34+ bool DetectBlueLine();
35+
1936 // コンストラクタ
2037 Garage()
2138 {
22- mode = GarageMode_Start;
39+ mode = GarageMode_BlackLineTrace;
40+ detectBlueLine = false;
41+ detectBlueLineCount = 0;
42+ stopCount = 0;
43+ modeStartDistance = 0;
2344 }
2445 // デストラクタ
2546 ~Garage()
Show on old repository browser