2014 sift / Mbed 2 deprecated TVDctrller2017_brdRev1_PandA

Dependencies:   mbed

Fork of TVDctrller2017_brdRev1_ver6 by 2014 sift

Revision:
27:37a8b4f6d28d
Parent:
26:331e77bb479b
Child:
28:47e9531a3a9d
--- a/main.cpp	Sat Jul 01 07:24:50 2017 +0000
+++ b/main.cpp	Sat Jul 01 08:45:37 2017 +0000
@@ -29,8 +29,9 @@
 InterruptIn leftTirePulse2(p27);
 DigitalOut WDT(p28);
 CAN can(p30, p29);
+DigitalOut LED[] = {LED1, LED2, LED3, LED4};
 
-DigitalOut LED[] = {LED1, LED2, LED3, LED4};
+Timer timer;
 
 #define indicateSystem(x)       (indicatorLed.write(x))
 #define shutdownSystem(void)    (shutDown.write(0))
@@ -38,9 +39,16 @@
 #define isPressedRTD(void)      (!RTDSW.read())
 #define isShutdownSystem(void)  (SDState.read())
 
-Timer timer;
+//++++++++++++++++++++++++++
+//CANデータのバイト数
+#define CANDATANUM_REQTRQ 2
+#define CANDATANUM_BRAKE 1
+#define CANDATANUM_MOTORTRQ_R 2
+#define CANDATANUM_MOTORTRQ_L 2
+#define CANDATANUM_MOTORTRQ_L 1
+//++++++++++++++++++++++++++
 
-void initIO(void)
+void init(void)
 {
     indicatorLed = 0;
     shutDown = 0;
@@ -60,6 +68,8 @@
     leftTirePulse1.mode(PullNone);
     leftTirePulse2.mode(PullNone);
 
+    can.frequency(500000);      //500kHz
+
     indicateSystem(1);
     bootSystem();
 }
@@ -67,6 +77,7 @@
 int main(void)
 {
     int f_whatchdog=0;
+    char canSendData[1];
 
     wait(1);
 
@@ -75,7 +86,7 @@
     printf("\033[1;1H");        //teratermの画面クリア
     printf("\r\nVersion:TVDctrller2017_brdRev1...start!!!!!\r\n");
 
-    initIO();       //IOポート初期化
+    init();       //IOポート初期化
 
     initTVD();
 
@@ -100,7 +111,11 @@
 
         //printf("%f\n\r", 45.0/0xFFFF * calcRequestTorque());
 
-        printf("%2.2f\t%3.2f\t%1.2f\r\n", 45.0f / 0xffff * calcRequestTorque(), getVelocity(), getSteerAngle());
+        canSendData[0] = (char)(255.0f * (calcRequestTorque()-MAX_OUTPUT_TORQUE_REGENERATIVE)/(MAX_OUTPUT_TORQUE_POWER-MAX_OUTPUT_TORQUE_REGENERATIVE));
+        printf("%2.2f\t%3.2f\t%1.2f\tsend:%d\r\n", 45.0f / 0xffff * calcRequestTorque(), getVelocity(), getSteerAngle(), canSendData[0]);
+
+        can.write(CANMessage(0x0f, canSendData, 1));
+
         //printf("%1.6f\r\n", time);
         //printf("%d\r\n", eCounter.brakeOverRide);
         time = timer.read();