Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 5:5aa7223226df
- Parent:
- 4:1354e56c7dd3
- Child:
- 6:db1a62608047
diff -r 1354e56c7dd3 -r 5aa7223226df main.cpp
--- a/main.cpp Wed Nov 20 08:06:46 2019 +0000
+++ b/main.cpp Fri Nov 22 05:55:36 2019 +0000
@@ -16,10 +16,22 @@
DigitalIn thermo(p20); //焦電センサ↓
DigitalOut led(LED1);
Serial pc(USBTX,USBRX); // tx, rx 焦電センサ↑
+Serial xbee(p13, p14);
TB6612 left(p25,p17,p16);//motor
TB6612 right(p26,p19,p18);//motor
-int main() { //FET
+void JPEGCamera(void);
+void us015(void);
+void motorFoward(void);
+void motorFowardR(void);
+void motorForwardL(void);
+void motorStop(void);
+void motorReverse(void);
+ LocalFileSystem local("local");
+
+int main() {
+ printf("CanSat-B_Start!\r\n");
+ //FET
FET = 0;
SW = 1; //p21をhigh(3.3V)にする。
while(1) {
@@ -46,8 +58,8 @@
}
}
}
- }
-int main() { //以下GPS
+
+ //以下GPS
double a;
double b;
double distance;
@@ -98,13 +110,9 @@
if (distance<5){
printf("%lf\r\n",distance);
- left = 100; //左モーター100%
- right = 100;//右モーター100%
- printf("直進\n\r");
+ motorFoward();
}else{
- left = 0;
- right = 0;
- printf("停止\n\r");
+ motorStop();
pc.printf("5m clear!");
break;
}
@@ -114,10 +122,8 @@
wait(1);
}
}
- return 0; //注意!void()に変えること.このままだとここで終わる
- }
-
- int main(){
+ //GPS End
+
float th;
Timer tm;
pc.printf("start\r\n");
@@ -126,19 +132,12 @@
thermo=0; //焦電off
Ultra=1;//超音波on
- while(1) {
- hs.TrigerOut();
- wait(1);
- int distance;
- distance = hs.GetDistance();
- printf("%d\r\n",distance);//距離出力
-
+ us015();
if(distance<2000){//超音波反応
Ultra=0;//超音波off
thermo=1;//焦電on
- left = 0; //左モーター0%
- right = 0;//右モーター0%
- printf("停止\n\r");
+ motorStop();
+
if(true)
th = thermo;
if(th=1 && !detected) {//焦電反応ありの場合
@@ -147,7 +146,84 @@
tm.reset();
tm.start();
thermo=0;
- const int RESPONSE_TIMEOUT = 500;
+ JPEGCamera();
+
+ FILE *fp;
+ base64 *bs;
+ int c;
+
+ xbee.printf("charizard!!!\r\n");
+ bs = new base64();
+ bs->Encode("/local/PICT000.jpg","/local/d.txt");
+
+
+ if((fp=fopen("/local/d.txt","r"))!=NULL)
+ {
+ while ((c=fgetc(fp))!=EOF){
+ xbee.printf("%c",c);
+ }
+ fclose(fp);
+ }
+
+
+ }else{//焦電反応なしの場合
+ detected=false;
+ thermo=0;
+ Ultra=1;
+ }
+
+
+ //while(true)
+
+
+//超音波センサー反応あり
+//停止
+//超音波センサーOFF
+//焦電センサーON
+
+ //焦電センサー反応あり
+ //焦電センサーOFF
+ //カメラ起動
+ //カメラOFF
+ //XBeeによりPCへ送信
+ if(receiveOK()=true){
+ printf("Unknown Creature has been descovered!\n");
+ }
+ //"OK"受信、ミッション終了
+ else if(receiveOK()=false){
+ printf("Continue!\n");
+ }
+ //"NO"受信、ミッション再開
+
+ else if(detected=false){
+ thermo=0;
+ motorFowardR();
+ wait(3);
+ Ultra=1;
+ motorFoward();
+ }
+
+ //焦電センサー反応無し
+ //焦電センサーOFF
+ //方向転換
+ //超音波センサーON
+ //直進
+}
+else if(distance>=2000){
+ motorStop();
+ wait(2);
+ motorFowardR();
+ wait(3);
+}
+//超音波センサー反応無し
+//停止
+//方向転換
+//直進
+}
+
+
+void JPEGCamera(){
+ const int RESPONSE_TIMEOUT = 500;
const int DATA_TIMEOUT = 1000;
JPEGCamera::JPEGCamera(PinName tx, PinName rx) : Serial(tx, rx) {
@@ -280,83 +356,34 @@
return i;
}
- LocalFileSystem local("local");
-
-Serial pc(USBTX,USBRX);
-Serial xbee(p13, p14);
-int main(void){
- FILE *fp;
- base64 *bs;
- int c;
-
- xbee.printf("charizard!!!\r\n");
- bs = new base64();
- bs->Encode("/local/PICT000.jpg","/local/d.txt");
-
-
- if((fp=fopen("/local/d.txt","r"))!=NULL)
- {
- while ((c=fgetc(fp))!=EOF){
- xbee.printf("%c",c);
- }
- fclose(fp);
- }
- return 0;
-}
+void us015(){
+ hs.TrigerOut();
+ wait(1);
+ int distance;
+ distance = hs.GetDistance();
+ printf("%d\r\n",distance);//距離出力
+ }
- }else{//焦電反応なしの場合
- detected=false;
- thermo=0;
- Ultra=1;
- }
-
-}
- //while(true)
- }
- return 0;
- }
-
-//超音波センサー反応あり
-//停止
-//超音波センサーOFF
-//焦電センサーON
-
- //焦電センサー反応あり
- //焦電センサーOFF
- //カメラ起動
- //カメラOFF
- //XBeeによりPCへ送信
- if(receiveOK()=true){
- printf("Unknown Creature has been descovered!\n");
- }
- //"OK"受信、ミッション終了
- else if(receiveOK()=false){
- printf("Continue!\n");
- }
- //"NO"受信、ミッション再開
-
- else if(detected=false){
- thermo=0;
- left=100;
- wait(3.0);
- right=100;
- Ultra=1;
- }
- }
- //焦電センサー反応無し
- //焦電センサーOFF
- //方向転換
- //超音波センサーON
- //直進
-}
-else if(distance>=2000){
- left=0;
- right=0;
- left=100;
- wait(3.0);
- right=100;
-}
-//超音波センサー反応無し
-//停止
-//方向転換
-//直進
+void motorFoward(){
+ left = 100;
+ right = 100;
+ printf("直進\n\r");
+ }
+void motorFowardR(){
+ left = 100;
+ right = 20;
+ printf("右折\n\r");
+ }
+void motorForwardL(){
+ left = 20;
+ right = 100;
+ printf("左折\n\r");}
+void motorStop(){
+ left = 0;
+ right = 0;
+ printf("停止\n\r");}
+void motorReverse(){
+ left = -50;
+ right = -50;
+ printf("バック\n\r");
+ }
\ No newline at end of file