I want go to sea

Dependencies:   arrc_mbed Servo air

Revision:
0:d7ecfe1f9840
Child:
1:d3985e5af20f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Mar 05 04:57:40 2022 +0000
@@ -0,0 +1,112 @@
+#include "mbed.h"
+#include "scrp_slave.hpp"
+#include "air.hpp"
+#include "Servo.h"
+ScrpSlave slave(PC_12,PD_2,PH_1,SERIAL_TX,SERIAL_RX,0x0807ffff);
+Serial pc(SERIAL_TX,SERIAL_RX);
+DigitalIn limitA(PB_6,PullUp);
+DigitalIn limitB(PB_12,PullUp);
+Air catch_no(PA_9);
+
+DigitalIn limitC(PB_4,PullUp);
+Air hassya(PA_8);
+Servo myservo(PB_0);
+Timer timer;
+int tim=-3000;
+
+
+
+void driveMotorS2(double pwm){
+    PwmOut up_pin_A(PB_13);
+    PwmOut up_pin_B(PB_14);
+    up_pin_A.period_us(2048);
+    up_pin_B.period_us(2048);
+    if (!pwm) {
+        up_pin_A = 0;
+        up_pin_B = 0;
+    } else if (0 < pwm) {
+        up_pin_A = pwm;
+        up_pin_B = 0;
+    } else {
+        up_pin_A = 0;
+        up_pin_B= -pwm;
+    }
+}
+// ↓サーボ用
+void Servo(bool data){
+    if(data==0){
+    myservo = 0;
+    }else{
+    myservo = 0.2;
+    }
+}
+//↓発射用
+bool Hassya(int rx_data,int &tx_data){
+    if(rx_data == 1 && limitC==0){
+        tim=timer.read_ms();
+    }
+    if(timer.read_ms()-tim<1000){
+            hassya.move(1);
+            driveMotorS2(0);
+            Servo(1);
+    }else if(timer.read_ms()-tim<2000){
+            hassya.move(0);
+            driveMotorS2(0);
+            Servo(0);
+            
+    }else if(timer.read_ms()-tim>2000 && limitC==1){
+            hassya.move(0);
+            driveMotorS2(0.06);
+            Servo(0);
+           
+    }else {
+            hassya.move(1);
+            driveMotorS2(0);
+            Servo(0);
+           
+    }
+    return true;
+}
+
+//↓モーター
+void driveMotorS(double pwm){
+    PwmOut up_pin_A1(PA_0);
+    PwmOut up_pin_B1(PA_1);
+    up_pin_A1.period_us(2048);
+    up_pin_B1.period_us(2048);
+    if (!pwm) {
+        up_pin_A1 = 0;
+        up_pin_B1 = 0;
+    } else if (0 < pwm) {
+        up_pin_A1 = pwm;
+        up_pin_B1 = 0;
+    } else {
+        up_pin_A1 = 0;
+        up_pin_B1= -pwm;
+    }
+}
+//↓昇降
+//速さはテキトー
+bool Up(int rx_data,int &tx_data){
+    if(rx_data==1 && !limitA){
+        driveMotorS(0.3);
+    }else if(rx_data==-1 && !limitB){
+        driveMotorS(-0.3);
+    }else{
+        driveMotorS(0);
+    }
+    return true;
+}
+//↓回収用
+bool CATCH_NO(int rx_data,int &tx_data){
+    catch_no.move(rx_data);
+    return true;
+    }
+
+int main(){
+    timer.start();
+    slave.addCMD(17,Hassya);
+    slave.addCMD(20,CATCH_NO);
+    slave.addCMD(21,Up);
+    while(true);
+}
\ No newline at end of file