rainbow

Dependencies:   mbed FastPWM

Files at this revision

API Documentation at this revision

Comitter:
Lightvalve
Date:
Wed Jul 06 08:08:15 2022 +0000
Parent:
250:91d3ec3a087e
Child:
252:3ffd78cbd029
Commit message:
220706

Changed in this revision

CAN/function_CAN.cpp 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
--- a/CAN/function_CAN.cpp	Fri Jul 01 05:37:08 2022 +0000
+++ b/CAN/function_CAN.cpp	Wed Jul 06 08:08:15 2022 +0000
@@ -727,21 +727,23 @@
         int16_t temp_ref_valve_pos = (int16_t) (msg.data[0] | msg.data[1] << 8);
 
         if (((OPERATING_MODE&0b110)>>1) == 0) { //Moog Valve
-            valve_pos.ref = (double) temp_ref_valve_pos; // Unit : pulse (0~10000)
+            valve_pos.ref = (float) temp_ref_valve_pos; // Unit : pulse (0~10000)
         } else if (((OPERATING_MODE&0b110)>>1) == 1) { //KNR Valve
-            valve_pos.ref = (double) temp_ref_valve_pos; // Unit : pulse (0~30000)
+            valve_pos.ref = (float) temp_ref_valve_pos; // Unit : pulse (0~30000)
         } else { //SW Valve
-            if(temp_ref_valve_pos >= 0) {
-                valve_pos.ref = (double)VALVE_DEADZONE_PLUS + (double)temp_ref_valve_pos * ((double)VALVE_MAX_POS-(double)VALVE_DEADZONE_PLUS)/10000.0f;
-//                valve_pos.ref = (double)temp_ref_valve_pos;
+            if(temp_ref_valve_pos == 0) {
+                valve_pos.ref = ((float)VALVE_DEADZONE_PLUS + (float)VALVE_DEADZONE_MINUS) * 0.5f;
+            } else if(temp_ref_valve_pos> 0) {
+                valve_pos.ref = (float)VALVE_DEADZONE_PLUS + (float)temp_ref_valve_pos * ((float)VALVE_MAX_POS-(float)VALVE_DEADZONE_PLUS)/10000.0f;
+//                valve_pos.ref = (float)temp_ref_valve_pos;
             } else {
-                valve_pos.ref = (double)VALVE_DEADZONE_MINUS - (double)temp_ref_valve_pos * ((double)VALVE_MIN_POS-(double)VALVE_DEADZONE_MINUS)/10000.0f;
-//                valve_pos.ref = (double)temp_ref_valve_pos;
+                valve_pos.ref = (float)VALVE_DEADZONE_MINUS - (float)temp_ref_valve_pos * ((float)VALVE_MIN_POS-(float)VALVE_DEADZONE_MINUS)/10000.0f;
+//                valve_pos.ref = (float)temp_ref_valve_pos;
             }
         }
     } else if(address==CID_RX_REF_PWM) {
         int temp_ref_pwm = (int16_t) (msg.data[0] | msg.data[1] << 8);
-        Vout.ref = (double) temp_ref_pwm;
+        Vout.ref = (float) temp_ref_pwm;
     }
 
 }
--- a/main.cpp	Fri Jul 01 05:37:08 2022 +0000
+++ b/main.cpp	Wed Jul 06 08:08:15 2022 +0000
@@ -1297,10 +1297,13 @@
                             valve_pos_pulse = -10000.0f;
                         }
                     }
-                    if (valve_pos_pulse >= 0) {
-                        valve_pos.ref = valve_pos_pulse/10000.0f * (VALVE_MAX_POS-VALVE_DEADZONE_PLUS) + VALVE_DEADZONE_PLUS;
+                    float valve_control_deadzone = 5.0f;
+                    if(valve_pos_pulse < valve_control_deadzone && valve_pos_pulse > -valve_control_deadzone) {
+                        valve_pos.ref = ((float) VALVE_DEADZONE_PLUS + (float) VALVE_DEADZONE_MINUS) * 0.5f;
+                    } else if (valve_pos_pulse >= valve_control_deadzone) {
+                        valve_pos.ref = valve_pos_pulse/10000.0f * ((float) VALVE_MAX_POS - (float) VALVE_DEADZONE_PLUS) + (float) VALVE_DEADZONE_PLUS;
                     } else {
-                        valve_pos.ref = -valve_pos_pulse/10000.0f * (VALVE_MIN_POS-VALVE_DEADZONE_MINUS) + VALVE_DEADZONE_MINUS;
+                        valve_pos.ref = -valve_pos_pulse/10000.0f * ((float) VALVE_MIN_POS - (float) VALVE_DEADZONE_MINUS) + (float) VALVE_DEADZONE_MINUS;
                     }
                     VALVE_POS_CONTROL_DZ(valve_pos.ref);
                     V_out = Vout.ref;