rainbow

Dependencies:   mbed FastPWM

Revision:
237:c2cfe349f5c1
Parent:
232:2976cf1b4252
Child:
238:4e660aa77eb7
diff -r fd7961dfa78a -r c2cfe349f5c1 CAN/function_CAN.cpp
--- a/CAN/function_CAN.cpp	Fri Jun 25 12:21:04 2021 +0000
+++ b/CAN/function_CAN.cpp	Wed Jul 07 10:09:21 2021 +0000
@@ -649,6 +649,22 @@
         case CRX_SET_ROM: {
             break;
         }
+        
+        case CRX_ASK_BUFFER: {
+            cnt_buffer = (int16_t) (msg.data[1] | msg.data[2] << 8);
+            CAN_TX_BUFFER(cnt_buffer);
+            break;
+        }
+        case CRX_SET_STEP_TEST: {
+            cnt_step_test = 0;
+            CONTROL_UTILITY_MODE = 37;
+            break;
+        }
+        case CRX_SET_FREQ_TEST: {
+            cnt_freq_test = 0;
+            CONTROL_UTILITY_MODE = 34;
+            break;
+        }
 
         default:
             break;
@@ -720,9 +736,9 @@
             valve_pos.ref = (double) temp_ref_valve_pos; // Unit : pulse (0~30000)
         } else { //SW Valve
             if(temp_ref_valve_pos >= 0) {
-                valve_pos.ref = (double)VALVE_CENTER + (double)temp_ref_valve_pos * ((double)VALVE_MAX_POS-(double)VALVE_CENTER)/10000.0f;
+                valve_pos.ref = (double)VALVE_ELECTRIC_CENTER + (double)temp_ref_valve_pos * ((double)VALVE_MAX_POS-(double)VALVE_ELECTRIC_CENTER)/10000.0f;
             } else {
-                valve_pos.ref = (double)VALVE_CENTER - (double)temp_ref_valve_pos * ((double)VALVE_MIN_POS-(double)VALVE_CENTER)/10000.0f;
+                valve_pos.ref = (double)VALVE_ELECTRIC_CENTER - (double)temp_ref_valve_pos * ((double)VALVE_MIN_POS-(double)VALVE_ELECTRIC_CENTER)/10000.0f;
             }
         }
     } else if(address==CID_RX_REF_PWM) {
@@ -1228,10 +1244,10 @@
     CANMessage temp_msg;
     int16_t valve_pos_vs_pwm;
 
-    if(VALVE_POS_VS_PWM[canindex]>= (float) VALVE_CENTER) {
-        valve_pos_vs_pwm = 10000.0f*((double)VALVE_POS_VS_PWM[canindex]-(double)VALVE_CENTER)/((double)VALVE_MAX_POS-(double)VALVE_CENTER);
+    if(VALVE_POS_VS_PWM[canindex]>= (float) VALVE_ELECTRIC_CENTER) {
+        valve_pos_vs_pwm = 10000.0f*((double)VALVE_POS_VS_PWM[canindex]-(double)VALVE_ELECTRIC_CENTER)/((double)VALVE_MAX_POS-(double)VALVE_ELECTRIC_CENTER);
     } else {
-        valve_pos_vs_pwm = -10000.0f*((double)VALVE_POS_VS_PWM[canindex]-(double)VALVE_CENTER)/((double)VALVE_MIN_POS-(double)VALVE_CENTER);
+        valve_pos_vs_pwm = -10000.0f*((double)VALVE_POS_VS_PWM[canindex]-(double)VALVE_ELECTRIC_CENTER)/((double)VALVE_MIN_POS-(double)VALVE_ELECTRIC_CENTER);
     }
 
     int16_t PWM_VALVE_ID;
@@ -1388,6 +1404,18 @@
     can.write(temp_msg);
 }
 
+void CAN_TX_TORQUE(int16_t t_valve_pos)
+{
+    CANMessage temp_msg;
+
+    temp_msg.id = CID_TX_PWM;
+    temp_msg.len = 2;
+    temp_msg.data[0] = (uint8_t) t_valve_pos;
+    temp_msg.data[1] = (uint8_t) (t_valve_pos >> 8);
+
+    can.write(temp_msg);
+}
+
 void CAN_TX_PWM(int16_t t_pwm)
 {
     CANMessage temp_msg;
@@ -1436,4 +1464,16 @@
 
 
     can.write(temp_msg);
+}
+
+void CAN_TX_VOUT(int16_t t_vout)
+{
+    CANMessage temp_msg;
+
+    temp_msg.id = CID_TX_VOUT;
+    temp_msg.len = 2;
+    temp_msg.data[0] = (uint8_t) t_vout;
+    temp_msg.data[1] = (uint8_t) (t_vout >> 8);
+
+    can.write(temp_msg);
 }
\ No newline at end of file