いからしMDCスレーブプログラム

Dependencies:   mbed SoftPWM MotorSMLAP

Files at this revision

API Documentation at this revision

Comitter:
WAT34
Date:
Tue Nov 27 08:01:19 2018 +0000
Parent:
12:3a734542a2b3
Commit message:
test added

Changed in this revision

MDC3_0pinConfig.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
diff -r 3a734542a2b3 -r 0cd5e8c91941 MDC3_0pinConfig.h
--- a/MDC3_0pinConfig.h	Tue Nov 27 06:17:21 2018 +0000
+++ b/MDC3_0pinConfig.h	Tue Nov 27 08:01:19 2018 +0000
@@ -29,8 +29,8 @@
     static PinName const BUZER = PB_7;
 
     /* Indicator LEDs */
-    static PinName const LED_0 = PA_0;
-    static PinName const LED_1 = PA_1;
+    static PinName const LED_0 = PA_1;
+    static PinName const LED_1 = PA_0;
     static PinName const LED_2 = PA_15;
     static PinName const LED_3 = PB_3;
 
diff -r 3a734542a2b3 -r 0cd5e8c91941 main.cpp
--- a/main.cpp	Tue Nov 27 06:17:21 2018 +0000
+++ b/main.cpp	Tue Nov 27 08:01:19 2018 +0000
@@ -18,6 +18,8 @@
 DigitalOut RSControl(RS485_CS);
 bool addrChecked;
 bool headerRecieved;
+DigitalIn test1(pinConfig::I2C_SDA);
+DigitalIn test2(pinConfig::I2C_SCL);
 DigitalOut debugLED0(LED_0);
 DigitalOut debugLED1(LED_1);
 BusOut debugLED(LED_2,LED_3);
@@ -35,6 +37,22 @@
 std::vector<unsigned char> buf;
 uint8_t canbuf[3];
 CANMessage msg;
+bool testing = false;
+void runTest()
+{
+    testing = true;
+    //beep = 1;
+    for(int i = 0;i < 4;i++)
+    {
+        motor[i].setFreq(1600*i);
+        motor[i].setMotorSpeed(0.1);
+        wait(0.3);
+        motor[i].setMotorSpeed(0);
+        motor[i].setFreq(20000.0);
+    }
+    testing = false;
+    //beep = 0;
+}    
 
 void canRxIt()
 {
@@ -49,6 +67,8 @@
 
 void forceStop()
 {
+    if(testing)
+        return;
     for(int i= 0; i< 4; i++)
         motor[i].setMotorSpeed(0);
     estop = true;
@@ -88,7 +108,10 @@
 int main()
 {
     for(int i= 0; i< 4; i++)
+    {
+        motor[i].setMode(SM);
         motor[i].setMotorSpeed(0);
+    }
     beep.period(1.0 / 2000.0);
     beep = 0.6;
     wait(0.1);
@@ -115,6 +138,8 @@
     rs485.baud(115200);
     serial.baud(115200);
     addr.mode(PullUp);
+    test1.mode(PullDown);
+    test2.mode(PullDown);
     RSControl = 0;
     rs485.putc((1<<addr));
     rs485.attach(&callback);
@@ -146,6 +171,8 @@
         if(estop)
             forceStop();
         beep = estop;
-        //wait(0.1);
+        
+        if(test1 && test2)
+            runTest();
     }
 }