NIT Fukui / Mbed OS 2021Arobo_YUMIPYOI

Dependencies:   Serial6050Yaw CERICA_2019

Files at this revision

API Documentation at this revision

Comitter:
konagi
Date:
Mon Apr 25 09:11:47 2022 +0000
Commit message:
a

Changed in this revision

CERICA_2019.lib Show annotated file Show diff for this revision Revisions of this file
Serial6050Yaw.lib Show annotated file Show diff for this revision Revisions of this file
Utility.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CERICA_2019.lib	Mon Apr 25 09:11:47 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/NIT-Fukui/code/CERICA_2019/#a5a5f1234eae
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Serial6050Yaw.lib	Mon Apr 25 09:11:47 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/NIT-Fukui/code/Serial6050Yaw/#413d60ebdcf2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utility.h	Mon Apr 25 09:11:47 2022 +0000
@@ -0,0 +1,43 @@
+#pragma once
+
+#define PI 3.1415926535897932384626433832795
+#define pin GPIO[9]
+RawSerial pc(USBTX,USBRX,115200);
+//Serial6050 mpu(PC_10, PC_11, PC_12);
+DigitalIn limit_pin = GPIO[0];
+PwmOut PWM(PA_8);
+DigitalOut debugLED(D13);
+DigitalIn button(PC_13);
+
+volatile int Opflag=0;
+volatile int Clflag=0;
+volatile int count=3;
+volatile int Motor[4] = {0};
+volatile double dire = 1;
+volatile char  MoveFlag = 0;
+
+
+void LEDThread()
+{
+    while(1){
+        if(MoveFlag != 0){
+            debugLED = 1;
+            wait_ms(100);
+            debugLED = 0;
+        }
+        else debugLED = 0;
+    }
+}
+
+void commArduinoThread()
+{
+    while(1){
+        cerica.Send(1);//MotorSend
+        char flag[1];
+        i2c.read(0x08 << 1,flag,1);
+
+        MoveFlag = flag[0];
+        //pc.printf("data : %u\r\n",flag[0]);
+        wait_ms(40);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Apr 25 09:11:47 2022 +0000
@@ -0,0 +1,110 @@
+#include "mbed.h"
+#include "board.h"
+#include "Serial6050.h"
+#include "Utility.h"
+
+/*void TurnAround()
+{
+    while(1) {
+        while(dire!=0)
+            dire=mpu.read();
+        if(dire<=180) {
+            cerica.Motor(3,255);
+        } else if(dire>=180) {+
+        65
+            cerica.Motor(3,-255);
+        }
+        cerica.Motor(3,0);
+    }
+}*/
+void Reload()
+{
+    //PWM.period_us(20000); //周期設定
+    pc.printf("OPEN\r\n");
+    PWM.pulsewidth_us(500);
+    wait(2);
+    pc.printf("CLOSE\r\n");
+    PWM.pulsewidth_us(2400);
+    wait(2);
+}
+
+void ReloadThread()
+{
+    while(true) {
+        if(Opflag==1) {
+            pc.printf("ReloadOP\r\n");
+            PWM.pulsewidth_us(500);
+            wait(1);
+            Opflag=0;
+        } else if(Clflag==1) {
+            pc.printf("ReloadCL\r\n");
+            PWM.pulsewidth_us(2400);
+            wait(1);
+            Clflag=0;
+        } else {
+            //Opflag=0;
+            //Clflag=0;
+        }
+    }
+}
+
+void Bow()
+{
+
+    Opflag=1;
+    cerica.Motor(0,-40);
+    wait(0.5);
+    while(limit_pin.read()==1) {
+
+        cerica.Motor(0,-40);
+        //pc.printf("BOW LOW\r\n");
+
+    }
+    pc.printf("%d\r\n",limit_pin.read());
+    while(1) {
+        cerica.Motor(0,0);
+        Clflag=1;
+        count--;
+        pc.printf("%d\r\n",count);
+        wait(0.4);
+        if(count==0) {
+            count=3;
+            pc.printf("break\r\n");
+            break;
+        }
+    }
+}
+int main()
+{
+    boardInit();
+    limit_pin.mode(PullUp);
+    Thread reload;
+    Thread led;
+    led.start(LEDThread);
+    reload.start(ReloadThread);;
+    PWM.period_us(20000); //周期設定
+    PWM.pulsewidth_us(2400);
+
+    //mpu.init();
+
+    MoveFlag = 1;
+    wait_ms(900);
+    MoveFlag = 0;
+
+    Thread comm;
+    comm.start(commArduinoThread);
+
+    while (true) {
+        if(MoveFlag==1||button.read() == 0) {
+            pc.printf("ON\r\n");
+            Bow();
+        } else {
+            //pc.printf("OFF\r\n");
+        }
+    }
+    //Reload();
+    //pc.printf("%d\n\r",SW1.read());
+    //pc.printf("aaaa\n\r");
+    //pc.printf("%d\n\r",limit_pin.read());
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Mon Apr 25 09:11:47 2022 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#c9e63f14085f5751ff5ead79a7c0382d50a813a2