2011

Dependencies:   mbed FastPWM

Revision:
30:8d561f16383b
Parent:
29:69f3f5445d6d
Child:
31:66738bfecec5
diff -r 69f3f5445d6d -r 8d561f16383b main.cpp
--- a/main.cpp	Wed Oct 02 04:41:59 2019 +0000
+++ b/main.cpp	Fri Oct 04 11:58:18 2019 +0000
@@ -20,8 +20,8 @@
 
 
 // PWM ///////////////////////////////////////////
-double dtc_v=0.0;
-double dtc_w=0.0;
+float dtc_v=0.0f;
+float dtc_w=0.0f;
 
 // I2C ///////////////////////////////////////////
 I2C i2c(PC_9,PA_8); // SDA, SCL (for K22F)
@@ -62,11 +62,11 @@
 State INIT_Pos;
 State INIT_torq;
 
-double V_out=0.0;
-double V_rem=0.0; // for anti-windup
-double V_MAX = 12000.0; // Maximum Voltage : 12V = 12000mV
+float V_out=0.0f;
+float V_rem=0.0f; // for anti-windup
+float V_MAX = 12000.0f; // Maximum Voltage : 12V = 12000mV
 
-double PWM_out=0.0;
+float PWM_out=0.0f;
 
 int timer_while = 0;
 int while_index = 0;
@@ -236,7 +236,7 @@
     }
 }
 
-int DDV_JOINT_POS_FF(double REF_JOINT_VEL)
+int DDV_JOINT_POS_FF(float REF_JOINT_VEL)
 {
 
     int i = 0;
@@ -244,9 +244,9 @@
     for(i=0; i<VALVE_POS_NUM; i++) {
         if(REF_JOINT_VEL >= min(JOINT_VEL[i],JOINT_VEL[i+1]) && REF_JOINT_VEL <=  max(JOINT_VEL[i],JOINT_VEL[i+1])) {
             if(i==0) {
-                Ref_Valve_Pos_FF = ((int) 10.0/(JOINT_VEL[i+1] - JOINT_VEL[i]) * (REF_JOINT_VEL - JOINT_VEL[i])) + DDV_CENTER;
+                Ref_Valve_Pos_FF = ((int) 10/(JOINT_VEL[i+1] - JOINT_VEL[i]) * (REF_JOINT_VEL - JOINT_VEL[i])) + DDV_CENTER;
             } else {
-                Ref_Valve_Pos_FF = ((int) 10.0*(ID_index_array[i+1] - ID_index_array[i-1])/(JOINT_VEL[i+1] - JOINT_VEL[i-1]) * (REF_JOINT_VEL - JOINT_VEL[i-1])) + DDV_CENTER + 10*ID_index_array[i-1];
+                Ref_Valve_Pos_FF = ((int) 10*(ID_index_array[i+1] - ID_index_array[i-1])/(JOINT_VEL[i+1] - JOINT_VEL[i-1]) * (REF_JOINT_VEL - JOINT_VEL[i-1])) + DDV_CENTER + 10*ID_index_array[i-1];
             }
             break;
         }
@@ -257,13 +257,13 @@
         Ref_Valve_Pos_FF = VALVE_MIN_POS;
     }
     
-    //Ref_Valve_Pos_FF = DDV_CENTER;
+    Ref_Valve_Pos_FF = (int) ( (float) VELOCITY_COMP_GAIN * 0.01f * (float) (Ref_Valve_Pos_FF - DDV_CENTER) + (float) DDV_CENTER);
     
     return Ref_Valve_Pos_FF;
 }
 
 
-void VALVE_POS_CONTROL(double REF_VALVE_POS)
+void VALVE_POS_CONTROL(float REF_VALVE_POS)
 {
     int i = 0;
 
@@ -286,26 +286,26 @@
 //    if(REF_VALVE_POS >= VALVE_POS_VS_PWM[0])
 //    {
 //        if(REF_VALVE_POS <=  VALVE_POS_VS_PWM[1]) {
-//            VALVE_PWM_RAW_FF = (double) 3000.0 / (double) (VALVE_POS_VS_PWM[1] - VALVE_POS_VS_PWM[0]) * ((double) REF_VALVE_POS - VALVE_POS_VS_PWM[0]);
+//            VALVE_PWM_RAW_FF = (float) 3000.0 / (float) (VALVE_POS_VS_PWM[1] - VALVE_POS_VS_PWM[0]) * ((float) REF_VALVE_POS - VALVE_POS_VS_PWM[0]);
 //        }else if(REF_VALVE_POS <=  VALVE_POS_VS_PWM[3]) {
-//            VALVE_PWM_RAW_FF = (double) 3000.0 / (double) (VALVE_POS_VS_PWM[3] - VALVE_POS_VS_PWM[1]) * ((double) REF_VALVE_POS - VALVE_POS_VS_PWM[1]) + 3000.0* (double) ID_index_array[1];
+//            VALVE_PWM_RAW_FF = (float) 3000.0 / (float) (VALVE_POS_VS_PWM[3] - VALVE_POS_VS_PWM[1]) * ((float) REF_VALVE_POS - VALVE_POS_VS_PWM[1]) + 3000.0* (float) ID_index_array[1];
 //        }else if(REF_VALVE_POS <=  VALVE_POS_VS_PWM[5]) {
-//            VALVE_PWM_RAW_FF = (double) 3000.0 / (double) (VALVE_POS_VS_PWM[5] - VALVE_POS_VS_PWM[3]) * ((double) REF_VALVE_POS - VALVE_POS_VS_PWM[3]) + 3000.0* (double) ID_index_array[3];
+//            VALVE_PWM_RAW_FF = (float) 3000.0 / (float) (VALVE_POS_VS_PWM[5] - VALVE_POS_VS_PWM[3]) * ((float) REF_VALVE_POS - VALVE_POS_VS_PWM[3]) + 3000.0* (float) ID_index_array[3];
 //        }else if(REF_VALVE_POS <=  VALVE_POS_VS_PWM[7]) {
-//            VALVE_PWM_RAW_FF = (double) 3000.0 / (double) (VALVE_POS_VS_PWM[7] - VALVE_POS_VS_PWM[5]) * ((double) REF_VALVE_POS - VALVE_POS_VS_PWM[5]) + 3000.0* (double) ID_index_array[5];
+//            VALVE_PWM_RAW_FF = (float) 3000.0 / (float) (VALVE_POS_VS_PWM[7] - VALVE_POS_VS_PWM[5]) * ((float) REF_VALVE_POS - VALVE_POS_VS_PWM[5]) + 3000.0* (float) ID_index_array[5];
 //        }else
 //            VALVE_PWM_RAW_FF = 12000.0;
 //    }
 //    else
 //    {
 //        if(REF_VALVE_POS >= VALVE_POS_VS_PWM[2]) {
-//            VALVE_PWM_RAW_FF = (double) 3000.0 / (double) (VALVE_POS_VS_PWM[0] - VALVE_POS_VS_PWM[2]) * ((double) REF_VALVE_POS - VALVE_POS_VS_PWM[2]) + 3000.0* (double) ID_index_array[2];
+//            VALVE_PWM_RAW_FF = (float) 3000.0 / (float) (VALVE_POS_VS_PWM[0] - VALVE_POS_VS_PWM[2]) * ((float) REF_VALVE_POS - VALVE_POS_VS_PWM[2]) + 3000.0* (float) ID_index_array[2];
 //        }else if(REF_VALVE_POS >= VALVE_POS_VS_PWM[4]) {
-//            VALVE_PWM_RAW_FF = (double) 3000.0 / (double) (VALVE_POS_VS_PWM[2] - VALVE_POS_VS_PWM[4]) * ((double) REF_VALVE_POS - VALVE_POS_VS_PWM[4]) + 3000.0* (double) ID_index_array[4];
+//            VALVE_PWM_RAW_FF = (float) 3000.0 / (float) (VALVE_POS_VS_PWM[2] - VALVE_POS_VS_PWM[4]) * ((float) REF_VALVE_POS - VALVE_POS_VS_PWM[4]) + 3000.0* (float) ID_index_array[4];
 //        }else if(REF_VALVE_POS >= VALVE_POS_VS_PWM[6]) {
-//            VALVE_PWM_RAW_FF = (double) 3000.0 / (double) (VALVE_POS_VS_PWM[4] - VALVE_POS_VS_PWM[6]) * ((double) REF_VALVE_POS - VALVE_POS_VS_PWM[6]) + 3000.0* (double) ID_index_array[6];
+//            VALVE_PWM_RAW_FF = (float) 3000.0 / (float) (VALVE_POS_VS_PWM[4] - VALVE_POS_VS_PWM[6]) * ((float) REF_VALVE_POS - VALVE_POS_VS_PWM[6]) + 3000.0* (float) ID_index_array[6];
 //        }else if(REF_VALVE_POS >= VALVE_POS_VS_PWM[8]) {
-//            VALVE_PWM_RAW_FF = (double) 3000.0 / (double) (VALVE_POS_VS_PWM[6] - VALVE_POS_VS_PWM[8]) * ((double) REF_VALVE_POS - VALVE_POS_VS_PWM[8]) + 3000.0* (double) ID_index_array[8];
+//            VALVE_PWM_RAW_FF = (float) 3000.0 / (float) (VALVE_POS_VS_PWM[6] - VALVE_POS_VS_PWM[8]) * ((float) REF_VALVE_POS - VALVE_POS_VS_PWM[8]) + 3000.0* (float) ID_index_array[8];
 //        }else
 //            VALVE_PWM_RAW_FF = -12000.0;
 //    }
@@ -313,9 +313,9 @@
     for(i=0; i<24; i++) {
         if(REF_VALVE_POS >= min(VALVE_POS_VS_PWM[i],VALVE_POS_VS_PWM[i+1]) && REF_VALVE_POS <=  max(VALVE_POS_VS_PWM[i],VALVE_POS_VS_PWM[i+1])) {
             if(i==0) {
-                VALVE_PWM_RAW_FF = (double) 1000.0 / (double) (VALVE_POS_VS_PWM[i+1] - VALVE_POS_VS_PWM[i]) * ((double) REF_VALVE_POS - VALVE_POS_VS_PWM[i]);
+                VALVE_PWM_RAW_FF = (float) 1000.0 / (float) (VALVE_POS_VS_PWM[i+1] - VALVE_POS_VS_PWM[i]) * ((float) REF_VALVE_POS - VALVE_POS_VS_PWM[i]);
             } else {
-                VALVE_PWM_RAW_FF = (double) 1000.0* (double) (ID_index_array[i+1] - ID_index_array[i-1])/(VALVE_POS_VS_PWM[i+1] - VALVE_POS_VS_PWM[i-1]) * ((double) REF_VALVE_POS - VALVE_POS_VS_PWM[i-1]) + 1000.0* (double) ID_index_array[i-1];
+                VALVE_PWM_RAW_FF = (float) 1000.0* (float) (ID_index_array[i+1] - ID_index_array[i-1])/(VALVE_POS_VS_PWM[i+1] - VALVE_POS_VS_PWM[i-1]) * ((float) REF_VALVE_POS - VALVE_POS_VS_PWM[i-1]) + 1000.0* (float) ID_index_array[i-1];
             }
             break;
         }
@@ -326,35 +326,35 @@
 }
 
 #define LT_MAX_IDX  57
-double LT_PWM_duty[LT_MAX_IDX] = {-100.0, -80.0, -60.0, -50.0, -40.0, -35.0, -30.0, -25.0, -20.0,
-                                  -19.0, -18.0, -17.0, -16.0, -15.0, -14.0, -13.0, -12.0, -11.0, -10.0,
-                                  -9.0, -8.0, -7.0, -6.0, -5.0, -4.0, -3.0, -2.0, -1.0, 0.0,
-                                  1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0,
-                                  11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0,
-                                  25.0, 30.0, 35.0, 40.0, 50.0, 60.0, 80.0, 100.0
+float LT_PWM_duty[LT_MAX_IDX] = {-100.0f, -80.0f, -60.0f, -50.0f, -40.0f, -35.0f, -30.0f, -25.0f, -20.0f,
+                                  -19.0f, -18.0f, -17.0f, -16.0f, -15.0f, -14.0f, -13.0f, -12.0f, -11.0f, -10.0f,
+                                  -9.0f, -8.0f, -7.0f, -6.0f, -5.0f, -4.0f, -3.0f, -2.0f, -1.0f, 0.0f,
+                                  1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f,
+                                  11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f,
+                                  25.0f, 30.0f, 35.0f, 40.0f, 50.0f, 60.0f, 80.0f, 100.0f
                                  };  // duty
-double LT_Voltage_Output[LT_MAX_IDX] = {-321.4, -291.3, -261.5, -246.8, -231.7, -223.9, -216.1, -207.9, -198.8,
-                                        -196.9, -195.0, -192.5, -188.8, -184.5, -180.2, -175.9, -171.5, -166.3, -161.0,
-                                        -156.0, -149.5, -139.0, -126.0, -107.0, -87.5, -64.0, -38.5, -9.4, 0.0,
-                                        12.0, 43.5, 69.0, 94.0, 114.0, 132.0, 146.0, 155.5, 162.3, 168.2,
-                                        173.1, 178.2, 182.8, 187.4, 191.8, 196.0, 199.7, 201.9, 203.8, 205.6,
-                                        214.6, 222.5, 230.4, 238.2, 253.3, 268.0, 297.6, 327.7
+float LT_Voltage_Output[LT_MAX_IDX] = {-321.4f, -291.3f, -261.5f, -246.8f, -231.7f, -223.9f, -216.1f, -207.9f, -198.8f,
+                                        -196.9f, -195.0f, -192.5f, -188.8f, -184.5f, -180.2f, -175.9f, -171.5f, -166.3f, -161.0f,
+                                        -156.0f, -149.5f, -139.0f, -126.0f, -107.0f, -87.5f, -64.0f, -38.5f, -9.4f, 0.0f,
+                                        12.0f, 43.5f, 69.0f, 94.0f, 114.0f, 132.0f, 146.0f, 155.5f, 162.3f, 168.2f,
+                                        173.1f, 178.2f, 182.8f, 187.4f, 191.8f, 196.0f, 199.7f, 201.9f, 203.8f, 205.6f,
+                                        214.6f, 222.5f, 230.4f, 238.2f, 253.3f, 268.0f, 297.6f, 327.7f
                                        }; // mV
 
-double PWM_duty_byLT(double Ref_V)
+float PWM_duty_byLT(float Ref_V)
 {
-    double PWM_duty = 0.0;
+    float PWM_duty = 0.0f;
     if(Ref_V<LT_Voltage_Output[0]) {
-        PWM_duty = (Ref_V-LT_Voltage_Output[0])/1.5+LT_PWM_duty[0];
+        PWM_duty = (Ref_V-LT_Voltage_Output[0])/1.5f+LT_PWM_duty[0];
     } else if (Ref_V>=LT_Voltage_Output[LT_MAX_IDX-1]) {
-        PWM_duty = (Ref_V-LT_Voltage_Output[LT_MAX_IDX-1])/1.5+LT_PWM_duty[LT_MAX_IDX-1];
+        PWM_duty = (Ref_V-LT_Voltage_Output[LT_MAX_IDX-1])/1.5f+LT_PWM_duty[LT_MAX_IDX-1];
     } else {
         int idx = 0;
         for(idx=0; idx<LT_MAX_IDX-1; idx++) {
-            double ini_x = LT_Voltage_Output[idx];
-            double fin_x = LT_Voltage_Output[idx+1];
-            double ini_y = LT_PWM_duty[idx];
-            double fin_y = LT_PWM_duty[idx+1];
+            float ini_x = LT_Voltage_Output[idx];
+            float fin_x = LT_Voltage_Output[idx+1];
+            float ini_y = LT_PWM_duty[idx];
+            float fin_y = LT_PWM_duty[idx+1];
             if(Ref_V>=ini_x && Ref_V<fin_x) {
                 PWM_duty = (fin_y-ini_y)/(fin_x-ini_x)*(Ref_V-ini_x) + ini_y;
                 break;
@@ -370,8 +370,8 @@
 *******************************************************************************/
 
 //unsigned long CNT_TMR4 = 0;
-double FREQ_TMR4 = (double)FREQ_10k;
-double DT_TMR4 = (double)DT_10k;
+float FREQ_TMR4 = (float)FREQ_10k;
+float DT_TMR4 = (float)DT_10k;
 extern "C" void TIM4_IRQHandler(void)
 {
 
@@ -385,26 +385,26 @@
         //Using LoadCell
 //            ADC1->CR2  |= 0x40000000;                        // adc _ 12bit
 //            //while((ADC1->SR & 0b10));
-//            double alpha_update_torque = 1.0/(1.0+(FREQ_TMR4/2.0)/(2.0*3.14*1000.0));
-//            double torque_new = ((double)ADC1->DR - PRES_A_NULL)  / TORQUE_SENSOR_PULSE_PER_TORQUE + 1.0;
-//            torq.sen = torq.sen*(1.0-alpha_update_torque)+torque_new*(alpha_update_torque);
+//            float alpha_update_torque = 1.0f/(1.0f+(FREQ_TMR4/2.0f)/(2.0f*3.14f*1000.0f));
+//            float torque_new = ((float)ADC1->DR - PRES_A_NULL)  / TORQUE_SENSOR_PULSE_PER_TORQUE + 1.0f;
+//            torq.sen = torq.sen*(1.0f-alpha_update_torque)+torque_new*(alpha_update_torque);
 
 
 
         //Pressure sensor A
         ADC1->CR2  |= 0x40000000;                        // adc _ 12bit
         //while((ADC1->SR & 0b10));
-        double alpha_update_pres_A = 1.0/(1.0+(FREQ_TMR4/2.0)/(2.0*3.14*1000.0));
-        double pres_A_new = ((double)ADC1->DR - PRES_A_NULL)  / PRES_SENSOR_A_PULSE_PER_BAR;
-        pres_A.sen = pres_A.sen*(1.0-alpha_update_pres_A)+pres_A_new*(alpha_update_pres_A);
+        float alpha_update_pres_A = 1.0f/(1.0f+(FREQ_TMR4/2.0f)/(2.0f*3.14f*1000.0f));
+        float pres_A_new = ((float)ADC1->DR - PRES_A_NULL)  / PRES_SENSOR_A_PULSE_PER_BAR;
+        pres_A.sen = pres_A.sen*(1.0f-alpha_update_pres_A)+pres_A_new*(alpha_update_pres_A);
 
         //Pressure sensor 1B
         //ADC2->CR2  |= 0x40000000;                        // adc _ 12bit
         //while((ADC2->SR & 0b10));
-        double alpha_update_pres_B = 1.0/(1.0+(FREQ_TMR4/2.0)/(2.0*3.14*1000.0));
-        double pres_B_new = ((double)ADC2->DR - PRES_B_NULL)  / PRES_SENSOR_B_PULSE_PER_BAR;
-        pres_B.sen = pres_B.sen*(1.0-alpha_update_pres_B)+pres_B_new*(alpha_update_pres_B);
-        torq.sen = pres_A.sen * (double) PISTON_AREA_A - pres_B.sen * (double) PISTON_AREA_B;
+        float alpha_update_pres_B = 1.0f/(1.0f+(FREQ_TMR4/2.0f)/(2.0f*3.14f*1000.0f));
+        float pres_B_new = ((float)ADC2->DR - PRES_B_NULL)  / PRES_SENSOR_B_PULSE_PER_BAR;
+        pres_B.sen = pres_B.sen*(1.0f-alpha_update_pres_B)+pres_B_new*(alpha_update_pres_B);
+        torq.sen = pres_A.sen * (float) PISTON_AREA_A - pres_B.sen * (float) PISTON_AREA_B;
 
 
 
@@ -413,9 +413,9 @@
 //          a1=ADC2->DR;
         //int raw_cur = ADC3->DR;
         //while((ADC3->SR & 0b10));
-        double alpha_update_cur = 1.0/(1.0+(FREQ_TMR4/2.0)/(2.0*3.14*1000.0)); // f_cutoff : 500Hz
-        double cur_new = ((double)ADC3->DR-2048.0)*20.0/4096.0; // unit : mA
-        cur.sen=cur.sen*(1.0-alpha_update_cur)+cur_new*(alpha_update_cur);
+        float alpha_update_cur = 1.0f/(1.0f+(FREQ_TMR4/2.0f)/(2.0f*3.14f*1000.0f)); // f_cutoff : 500Hz
+        float cur_new = ((float)ADC3->DR-2048.0f)*20.0f/4096.0f; // unit : mA
+        cur.sen=cur.sen*(1.0f-alpha_update_cur)+cur_new*(alpha_update_cur);
         //cur.sen = raw_cur;
 
         /*******************************************************
@@ -429,10 +429,10 @@
 
 int j =0;
 //unsigned long CNT_TMR3 = 0;
-//double FREQ_TMR3 = (double)FREQ_5k;
-double FREQ_TMR3 = (double)FREQ_1k;
-//double DT_TMR3 = (double)DT_5k;
-double DT_TMR3 = (double)DT_1k;
+//float FREQ_TMR3 = (float)FREQ_5k;
+float FREQ_TMR3 = (float)FREQ_1k;
+//float DT_TMR3 = (float)DT_5k;
+float DT_TMR3 = (float)DT_1k;
 extern "C" void TIM3_IRQHandler(void)
 {
     if (TIM3->SR & TIM_SR_UIF ) {
@@ -442,12 +442,12 @@
 
         switch (CONTROL_MODE) {
             case MODE_NO_ACT: {
-                V_out = 0;
+                V_out = 0.0f;
                 break;
             }
 
             case MODE_VALVE_OPEN_LOOP: {
-                V_out = (double) Vout.ref;
+                V_out = (float) Vout.ref;
                 break;
             }
 
@@ -457,27 +457,27 @@
             }
 
             case MODE_JOINT_POSITION_TORQUE_CONTROL_PWM: {
-                double PWM_RAW_POS_FB = 0.0; // PWM by Position Feedback
-                double PWM_RAW_POS_FF = 0.0; // PWM by Position Feedforward
-                double PWM_RAW_FORCE_FB = 0.0; // PWM by Force Feedback
+                float PWM_RAW_POS_FB = 0.0f; // PWM by Position Feedback
+                float PWM_RAW_POS_FF = 0.0f; // PWM by Position Feedforward
+                float PWM_RAW_FORCE_FB = 0.0f; // PWM by Force Feedback
 
                 // feedback input for position control
-                pos.err = pos.ref - (double) pos.sen;
+                pos.err = pos.ref - (float) pos.sen;
                 pos.err_diff = pos.err - pos.err_old;
                 pos.err_old = pos.err;
                 pos.err_sum += pos.err;
                 if (pos.err_sum > 1000) pos.err_sum = 1000;
                 if (pos.err_sum<-1000) pos.err_sum = -1000;
-                //            PWM_RAW_POS_FB = (double) P_GAIN_JOINT_POSITION * pos.err + (double) I_GAIN_JOINT_POSITION * pos.err_sum + (double) D_GAIN_JOINT_POSITION * pos.err_diff;
-                PWM_RAW_POS_FB = (double) P_GAIN_JOINT_POSITION * pos.err;
-                PWM_RAW_POS_FB = PWM_RAW_POS_FB * 0.01;
+                //            PWM_RAW_POS_FB = (float) P_GAIN_JOINT_POSITION * pos.err + (float) I_GAIN_JOINT_POSITION * pos.err_sum + (float) D_GAIN_JOINT_POSITION * pos.err_diff;
+                PWM_RAW_POS_FB = (float) P_GAIN_JOINT_POSITION * pos.err;
+                PWM_RAW_POS_FB = PWM_RAW_POS_FB * 0.01f;
 
                 // feedforward input for position control
-                double Ref_Vel_Act = vel.ref/(double)ENC_PULSE_PER_POSITION; // [pulse/s] >> [deg/s]
-                double K_ff = 0.9;
-                if(Ref_Vel_Act > 0) K_ff = 0.90; // open
-                if(Ref_Vel_Act > 0) K_ff = 0.75; // close
-                PWM_RAW_POS_FF = K_ff*Ref_Vel_Act/0.50;
+                float Ref_Vel_Act = vel.ref/(float)ENC_PULSE_PER_POSITION; // [pulse/s] >> [deg/s]
+                float K_ff = 0.9f;
+                if(Ref_Vel_Act > 0) K_ff = 0.90f; // open
+                if(Ref_Vel_Act > 0) K_ff = 0.75f; // close
+                PWM_RAW_POS_FF = K_ff*Ref_Vel_Act/0.50f;
 
                 // torque feedback
                 //            torq.err = torq.ref - torq.sen;
@@ -486,10 +486,10 @@
                 //            torq.err_sum += torq.err;
                 //            if (torq.err_sum > 1000) torq.err_sum = 1000;
                 //            if (torq.err_sum<-1000) torq.err_sum = -1000;
-                //            VALVE_PWM_RAW_TORQ = (double) P_GAIN_JOINT_TORQUE * torq.err + (double) I_GAIN_JOINT_TORQUE * torq.err_sum + (double) D_GAIN_JOINT_TORQUE * torq.err_diff;
-                //            VALVE_PWM_RAW_TORQ = VALVE_PWM_RAW_TORQ * 0.01;
+                //            VALVE_PWM_RAW_TORQ = (float) P_GAIN_JOINT_TORQUE * torq.err + (float) I_GAIN_JOINT_TORQUE * torq.err_sum + (float) D_GAIN_JOINT_TORQUE * torq.err_diff;
+                //            VALVE_PWM_RAW_TORQ = VALVE_PWM_RAW_TORQ * 0.01f;
 
-                PWM_RAW_FORCE_FB = 0.0;
+                PWM_RAW_FORCE_FB = 0.0f;
 
                 V_out = PWM_RAW_POS_FF + PWM_RAW_POS_FB + PWM_RAW_FORCE_FB;
 
@@ -499,28 +499,28 @@
             case MODE_JOINT_POSITION_TORQUE_CONTROL_VALVE_POSITION: {
                 
             
-                double VALVE_POS_RAW_POS_FB = 0.0; // Valve Position by Position Feedback
-                //double VALVE_POS_RAW_POS_FF = 0.0; // Valve Position by Position Feedforward
-                double VALVE_POS_RAW_FORCE_FB = 0.0; // Valve Position by Force Feedback
+                float VALVE_POS_RAW_POS_FB = 0.0f; // Valve Position by Position Feedback
+                //float VALVE_POS_RAW_POS_FF = 0.0f; // Valve Position by Position Feedforward
+                float VALVE_POS_RAW_FORCE_FB = 0.0f; // Valve Position by Force Feedback
                 //int DDV_JOINT_CAN = 0;
                 // feedback input for position control
-                pos.err = pos.ref - (double) pos.sen;
+                pos.err = pos.ref - (float) pos.sen;
                 pos.err_diff = pos.err - pos.err_old;
                 pos.err_old = pos.err;
                 pos.err_sum += pos.err;
                 if (pos.err_sum > 1000) pos.err_sum = 1000;
                 if (pos.err_sum<-1000) pos.err_sum = -1000;
-                VALVE_POS_RAW_POS_FB = (double) P_GAIN_JOINT_POSITION * 0.01 * pos.err + (double) I_GAIN_JOINT_POSITION * pos.err_sum + (double) D_GAIN_JOINT_POSITION * pos.err_diff;
-                VALVE_POS_RAW_POS_FB = VALVE_POS_RAW_POS_FB * 0.01;
+                VALVE_POS_RAW_POS_FB = (float) P_GAIN_JOINT_POSITION * 0.01f * pos.err + (float) I_GAIN_JOINT_POSITION * pos.err_sum + (float) D_GAIN_JOINT_POSITION * pos.err_diff;
+                VALVE_POS_RAW_POS_FB = VALVE_POS_RAW_POS_FB * 0.01f;
 
 
                 //Ref_Joint_Vel =  Ref_Vel_Test;
                 // feedforward input for position control
-                //            double Ref_Joint_Vel_Act = Ref_Joint_Vel/(double)ENC_PULSE_PER_POSITION; // [pulse/s] >> [deg/s]
-                //            double K_ff = 0.9;
-                //            if(Ref_Joint_Vel_Act > 0) K_ff = 0.90; // open
-                //            if(Ref_Joint_Vel_Act > 0) K_ff = 0.75; // close
-                //            VALVE_POS_RAW_POS_FF = K_ff*Ref_Joint_Vel_Act/0.50;
+                //            float Ref_Joint_Vel_Act = Ref_Joint_Vel/(float)ENC_PULSE_PER_POSITION; // [pulse/s] >> [deg/s]
+                //            float K_ff = 0.9f;
+                //            if(Ref_Joint_Vel_Act > 0) K_ff = 0.90f; // open
+                //            if(Ref_Joint_Vel_Act > 0) K_ff = 0.75f; // close
+                //            VALVE_POS_RAW_POS_FF = K_ff*Ref_Joint_Vel_Act/0.50f;
 
                 // torque feedback
                 //            torq.err = torq.ref - torq.sen;
@@ -529,9 +529,9 @@
                 //            torq.err_sum += torq.err;
                 //            if (torq.err_sum > 1000) torq.err_sum = 1000;
                 //            if (torq.err_sum<-1000) torq.err_sum = -1000;
-                //            VALVE_PWM_RAW_TORQ = (double) P_GAIN_JOINT_TORQUE * torq.err + (double) I_GAIN_JOINT_TORQUE * torq.err_sum + (double) D_GAIN_JOINT_TORQUE * torq.err_diff;
-                //            VALVE_PWM_RAW_TORQ = VALVE_PWM_RAW_TORQ * 0.01;
-                VALVE_POS_RAW_FORCE_FB = 0.0;
+                //            VALVE_PWM_RAW_TORQ = (float) P_GAIN_JOINT_TORQUE * torq.err + (float) I_GAIN_JOINT_TORQUE * torq.err_sum + (float) D_GAIN_JOINT_TORQUE * torq.err_diff;
+                //            VALVE_PWM_RAW_TORQ = VALVE_PWM_RAW_TORQ * 0.01f;
+                VALVE_POS_RAW_FORCE_FB = 0.0f;
 
                 valve_pos.ref = VALVE_POS_RAW_POS_FB + DDV_JOINT_POS_FF(vel.ref) + VALVE_POS_RAW_FORCE_FB;
                 //valve_pos.ref = VALVE_POS_RAW_POS_FB + DDV_CENTER;
@@ -547,13 +547,13 @@
             }
 
             case MODE_JOINT_POSITION_PRES_CONTROL_PWM: {
-                pos.err = pos.ref - (double) pos.sen;
+                pos.err = pos.ref - (float) pos.sen;
                 pos.err_diff = pos.err - pos.err_old;
                 pos.err_old = pos.err;
                 pos.err_sum += pos.err;
                 if (pos.err_sum > 1000) pos.err_sum = 1000;
                 if (pos.err_sum<-1000) pos.err_sum = -1000;
-                VALVE_PWM_RAW_POS = ((double) P_GAIN_JOINT_POSITION * pos.err + (double) I_GAIN_JOINT_POSITION * pos.err_sum + (double) D_GAIN_JOINT_POSITION * pos.err_diff) * 0.01;
+                VALVE_PWM_RAW_POS = ((float) P_GAIN_JOINT_POSITION * pos.err + (float) I_GAIN_JOINT_POSITION * pos.err_sum + (float) D_GAIN_JOINT_POSITION * pos.err_diff) * 0.01f;
 
                 torq.err = torq.ref - torq.sen;
                 torq.err_diff = torq.err - torq.err_old;
@@ -561,60 +561,60 @@
                 torq.err_sum += torq.err;
                 if (torq.err_sum > 1000) torq.err_sum = 1000;
                 if (torq.err_sum<-1000) torq.err_sum = -1000;
-                VALVE_PWM_RAW_TORQ = (double) P_GAIN_JOINT_TORQUE * torq.err + (double) I_GAIN_JOINT_TORQUE * torq.err_sum + (double) D_GAIN_JOINT_TORQUE * torq.err_diff;
+                VALVE_PWM_RAW_TORQ = (float) P_GAIN_JOINT_TORQUE * torq.err + (float) I_GAIN_JOINT_TORQUE * torq.err_sum + (float) D_GAIN_JOINT_TORQUE * torq.err_diff;
 
-                VALVE_PWM_RAW_TORQ = VALVE_PWM_RAW_TORQ * 0.01;
+                VALVE_PWM_RAW_TORQ = VALVE_PWM_RAW_TORQ * 0.01f;
 
-                V_out = VALVE_PWM_RAW_POS + (double) COMPLIANCE_GAIN * 0.01 * VALVE_PWM_RAW_TORQ;
+                V_out = VALVE_PWM_RAW_POS + (float) COMPLIANCE_GAIN * 0.01f * VALVE_PWM_RAW_TORQ;
 
-                CUR_FLOWRATE = (double) CUR_VELOCITY * 0.00009587;
-                CUR_FLOWRATE = CUR_FLOWRATE * 0.5757; // 0.4791=2*pi/65536*5000(pulse/tic to rad/s) 0.5757=0.02525*0.02*0.0095*2*60*1000 (radius * area * 2 * 60(sec --> min) * 1000(m^3 --> L))
+                CUR_FLOWRATE = (float) CUR_VELOCITY * 0.00009587f;
+                CUR_FLOWRATE = CUR_FLOWRATE * 0.5757f; // 0.4791=2*pi/65536*5000(pulse/tic to rad/s) 0.5757=0.02525*0.02*0.0095*2*60*1000 (radius * area * 2 * 60(sec --> min) * 1000(m^3 --> L))
                 if (DIR_VALVE > 0) {
-                    if (CUR_FLOWRATE >= 0 && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[0]*1.0)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - 0.0) / (VALVE_GAIN_LPM_PER_V[0]*1.0 - 0.0) + 0.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[0]*1.0) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[2]*2.)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[0]*1.0) / (VALVE_GAIN_LPM_PER_V[2]*2.0 - VALVE_GAIN_LPM_PER_V[0]*1.) + 1.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[2]*2.0) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[4]*3.)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[2]*2.0) / (VALVE_GAIN_LPM_PER_V[4]*3.0 - VALVE_GAIN_LPM_PER_V[2]*2.) + 2.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[4]*3.0) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[6]*4.)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[4]*3.0) / (VALVE_GAIN_LPM_PER_V[6]*4.0 - VALVE_GAIN_LPM_PER_V[4]*3.) + 3.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[6]*4.0) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[8]*5.)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[6]*4.0) / (VALVE_GAIN_LPM_PER_V[8]*5.0 - VALVE_GAIN_LPM_PER_V[6]*4.) + 4.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[8]*5.0)) VALVE_FF_VOLTAGE = 5.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[1]*(-1.0)) && CUR_FLOWRATE < 0.0) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[1]*(-1.0)) / (0.0 - VALVE_GAIN_LPM_PER_V[1]*(-1.)) - 1.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[3]*(-2.0)) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[1]*(-1.0))) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[3]*(-2.0)) / ((VALVE_GAIN_LPM_PER_V[1]*(-1.0)) - VALVE_GAIN_LPM_PER_V[3]*(-2.)) - 2.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[5]*(-3.0)) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[3]*(-2.0))) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[5]*(-3.0)) / ((VALVE_GAIN_LPM_PER_V[3]*(-2.0)) - VALVE_GAIN_LPM_PER_V[5]*(-3.)) - 3.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[7]*(-4.0)) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[5]*(-3.0))) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[7]*(-4.0)) / ((VALVE_GAIN_LPM_PER_V[5]*(-3.0)) - VALVE_GAIN_LPM_PER_V[7]*(-4.)) - 4.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[9]*(-5.0)) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[7]*(-4.0))) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[9]*(-5.0)) / ((VALVE_GAIN_LPM_PER_V[7]*(-4.0)) - VALVE_GAIN_LPM_PER_V[9]*(-5.)) - 5.0;
-                    else if (CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[9]*(-5.0))) VALVE_FF_VOLTAGE = -5;
+                    if (CUR_FLOWRATE >= 0 && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[0]*1.0f)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - 0.0f) / (VALVE_GAIN_LPM_PER_V[0]*1.0f - 0.0f) + 0.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[0]*1.0f) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[2]*2.0f)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[0]*1.0f) / (VALVE_GAIN_LPM_PER_V[2]*2.0f - VALVE_GAIN_LPM_PER_V[0]*1.) + 1.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[2]*2.0f) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[4]*3.0f)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[2]*2.0f) / (VALVE_GAIN_LPM_PER_V[4]*3.0f - VALVE_GAIN_LPM_PER_V[2]*2.) + 2.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[4]*3.0f) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[6]*4.0f)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[4]*3.0f) / (VALVE_GAIN_LPM_PER_V[6]*4.0f - VALVE_GAIN_LPM_PER_V[4]*3.) + 3.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[6]*4.0f) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[8]*5.0f)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[6]*4.0f) / (VALVE_GAIN_LPM_PER_V[8]*5.0f - VALVE_GAIN_LPM_PER_V[6]*4.) + 4.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[8]*5.0f)) VALVE_FF_VOLTAGE = 5.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[1]*(-1.0f)) && CUR_FLOWRATE < 0.0f) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[1]*(-1.0f)) / (0.0f - VALVE_GAIN_LPM_PER_V[1]*(-1.)) - 1.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[3]*(-2.0f)) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[1]*(-1.0f))) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[3]*(-2.0f)) / ((VALVE_GAIN_LPM_PER_V[1]*(-1.0f)) - VALVE_GAIN_LPM_PER_V[3]*(-2.)) - 2.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[5]*(-3.0f)) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[3]*(-2.0f))) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[5]*(-3.0f)) / ((VALVE_GAIN_LPM_PER_V[3]*(-2.0f)) - VALVE_GAIN_LPM_PER_V[5]*(-3.)) - 3.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[7]*(-4.0f)) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[5]*(-3.0f))) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[7]*(-4.0f)) / ((VALVE_GAIN_LPM_PER_V[5]*(-3.0f)) - VALVE_GAIN_LPM_PER_V[7]*(-4.)) - 4.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[9]*(-5.0f)) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[7]*(-4.0f))) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[9]*(-5.0f)) / ((VALVE_GAIN_LPM_PER_V[7]*(-4.0f)) - VALVE_GAIN_LPM_PER_V[9]*(-5.)) - 5.0f;
+                    else if (CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[9]*(-5.0f))) VALVE_FF_VOLTAGE = -5;
                     else VALVE_FF_VOLTAGE = 0;
                 } else {
-                    if (CUR_FLOWRATE >= 0 && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[0]*1.0)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - 0.0) / (VALVE_GAIN_LPM_PER_V[0]*1.0 - 0.0) + 0.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[1]*1.0) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[2]*2.0)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[0]*1.0) / (VALVE_GAIN_LPM_PER_V[2]*2.0 - VALVE_GAIN_LPM_PER_V[0]*1.) + 1.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[3]*2.0) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[4]*3.0)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[2]*2.0) / (VALVE_GAIN_LPM_PER_V[4]*3.0 - VALVE_GAIN_LPM_PER_V[2]*2.) + 2.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[5]*3.0) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[6]*4.0)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[4]*3.0) / (VALVE_GAIN_LPM_PER_V[6]*4.0 - VALVE_GAIN_LPM_PER_V[4]*3.) + 3.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[7]*4.0) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[8]*5.0)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[6]*4.0) / (VALVE_GAIN_LPM_PER_V[8]*5.0 - VALVE_GAIN_LPM_PER_V[6]*4.) + 4.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[9]*5.0)) VALVE_FF_VOLTAGE = 5.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[0]*(-1.0)) && CUR_FLOWRATE < 0.0) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[1]*(-1.0)) / (0.0 - VALVE_GAIN_LPM_PER_V[1]*(-1.0)) - 1.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[2]*(-2.0)) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[1]*(-1.0))) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[3]*(-2.0)) / ((VALVE_GAIN_LPM_PER_V[1]*(-1.0)) - VALVE_GAIN_LPM_PER_V[3]*(-2.0)) - 2.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[4]*(-3.0)) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[3]*(-2.0))) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[5]*(-3.0)) / ((VALVE_GAIN_LPM_PER_V[3]*(-2.0)) - VALVE_GAIN_LPM_PER_V[5]*(-3.0)) - 3.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[6]*(-4.0)) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[5]*(-3.0))) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[7]*(-4.0)) / ((VALVE_GAIN_LPM_PER_V[5]*(-3.0)) - VALVE_GAIN_LPM_PER_V[7]*(-4.0)) - 4.0;
-                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[8]*(-5.0)) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[7]*(-4.0))) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[9]*(-5.0)) / ((VALVE_GAIN_LPM_PER_V[7]*(-4.0)) - VALVE_GAIN_LPM_PER_V[9]*(-5.0)) - 5.0;
-                    else if (CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[8]*(-5.0))) VALVE_FF_VOLTAGE = -5;
+                    if (CUR_FLOWRATE >= 0 && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[0]*1.0f)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - 0.0f) / (VALVE_GAIN_LPM_PER_V[0]*1.0f - 0.0f) + 0.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[1]*1.0f) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[2]*2.0f)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[0]*1.0f) / (VALVE_GAIN_LPM_PER_V[2]*2.0f - VALVE_GAIN_LPM_PER_V[0]*1.0f) + 1.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[3]*2.0f) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[4]*3.0f)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[2]*2.0f) / (VALVE_GAIN_LPM_PER_V[4]*3.0f - VALVE_GAIN_LPM_PER_V[2]*2.0f) + 2.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[5]*3.0f) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[6]*4.0f)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[4]*3.0f) / (VALVE_GAIN_LPM_PER_V[6]*4.0f - VALVE_GAIN_LPM_PER_V[4]*3.0f) + 3.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[7]*4.0f) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[8]*5.0f)) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[6]*4.0f) / (VALVE_GAIN_LPM_PER_V[8]*5.0f - VALVE_GAIN_LPM_PER_V[6]*4.0f) + 4.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[9]*5.0f)) VALVE_FF_VOLTAGE = 5.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[0]*(-1.0f)) && CUR_FLOWRATE < 0.0f) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[1]*(-1.0f)) / (0.0f - VALVE_GAIN_LPM_PER_V[1]*(-1.0f)) - 1.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[2]*(-2.0f)) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[1]*(-1.0f))) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[3]*(-2.0f)) / ((VALVE_GAIN_LPM_PER_V[1]*(-1.0f)) - VALVE_GAIN_LPM_PER_V[3]*(-2.0f)) - 2.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[4]*(-3.0f)) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[3]*(-2.0f))) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[5]*(-3.0f)) / ((VALVE_GAIN_LPM_PER_V[3]*(-2.0f)) - VALVE_GAIN_LPM_PER_V[5]*(-3.0f)) - 3.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[6]*(-4.0f)) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[5]*(-3.0f))) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[7]*(-4.0f)) / ((VALVE_GAIN_LPM_PER_V[5]*(-3.0f)) - VALVE_GAIN_LPM_PER_V[7]*(-4.0f)) - 4.0f;
+                    else if (CUR_FLOWRATE >= (VALVE_GAIN_LPM_PER_V[8]*(-5.0f)) && CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[7]*(-4.0f))) VALVE_FF_VOLTAGE = (CUR_FLOWRATE - VALVE_GAIN_LPM_PER_V[9]*(-5.0f)) / ((VALVE_GAIN_LPM_PER_V[7]*(-4.0f)) - VALVE_GAIN_LPM_PER_V[9]*(-5.0f)) - 5.0f;
+                    else if (CUR_FLOWRATE < (VALVE_GAIN_LPM_PER_V[8]*(-5.0f))) VALVE_FF_VOLTAGE = -5;
                     else VALVE_FF_VOLTAGE = 0;
                 }
-                //            VALVE_FF_VOLTAGE = CUR_FLOWRATE * 0.5;
+                //            VALVE_FF_VOLTAGE = CUR_FLOWRATE * 0.5f;
 
-                if (CUR_FLOWRATE >= 0) VALVE_FF_VOLTAGE = (double) VELOCITY_COMP_GAIN * 0.001 * VALVE_FF_VOLTAGE * sqrt((double) PRES_SUPPLY - CUR_PRES_A_BAR) * 0.0707; // 0.0707 = 1/sqrt(200.))
-                else if (CUR_FLOWRATE < 0) VALVE_FF_VOLTAGE = (double) VELOCITY_COMP_GAIN * 0.001 * VALVE_FF_VOLTAGE * sqrt((double) PRES_SUPPLY - CUR_PRES_B_BAR) * 0.0707;
+                if (CUR_FLOWRATE >= 0) VALVE_FF_VOLTAGE = (float) VELOCITY_COMP_GAIN * 0.001f * VALVE_FF_VOLTAGE * sqrt((float) PRES_SUPPLY - CUR_PRES_A_BAR) * 0.0707f; // 0.0707 = 1/sqrt(200.))
+                else if (CUR_FLOWRATE < 0) VALVE_FF_VOLTAGE = (float) VELOCITY_COMP_GAIN * 0.001f * VALVE_FF_VOLTAGE * sqrt((float) PRES_SUPPLY - CUR_PRES_B_BAR) * 0.0707f;
 
                 V_out = V_out + VALVE_FF_VOLTAGE;
                 break;
             }
 
             case MODE_JOINT_POSITION_PRES_CONTROL_VALVE_POSITION: {
-                pos.err = pos.ref - (double) pos.sen;
+                pos.err = pos.ref - (float) pos.sen;
                 pos.err_diff = pos.err - pos.err_old;
                 pos.err_old = pos.err;
                 pos.err_sum += pos.err;
                 if (pos.err_sum > 1000) pos.err_sum = 1000;
                 if (pos.err_sum<-1000) pos.err_sum = -1000;
-                VALVE_PWM_RAW_POS = ((double) P_GAIN_JOINT_POSITION * pos.err + (double) I_GAIN_JOINT_POSITION * pos.err_sum + (double) D_GAIN_JOINT_POSITION * pos.err_diff) * 0.01;
+                VALVE_PWM_RAW_POS = ((float) P_GAIN_JOINT_POSITION * pos.err + (float) I_GAIN_JOINT_POSITION * pos.err_sum + (float) D_GAIN_JOINT_POSITION * pos.err_diff) * 0.01f;
 
                 torq.err = torq.ref - torq.sen;
                 torq.err_diff = torq.err - torq.err_old;
@@ -622,7 +622,7 @@
                 torq.err_sum += torq.err;
                 if (torq.err_sum > 1000) torq.err_sum = 1000;
                 if (torq.err_sum<-1000) torq.err_sum = -1000;
-                VALVE_PWM_RAW_TORQ = (double) P_GAIN_JOINT_TORQUE * torq.err + (double) I_GAIN_JOINT_TORQUE * torq.err_sum + (double) D_GAIN_JOINT_TORQUE * torq.err_diff;
+                VALVE_PWM_RAW_TORQ = (float) P_GAIN_JOINT_TORQUE * torq.err + (float) I_GAIN_JOINT_TORQUE * torq.err_sum + (float) D_GAIN_JOINT_TORQUE * torq.err_diff;
 
                 valve_pos.ref = VALVE_PWM_RAW_POS + VALVE_PWM_RAW_TORQ;
                 VALVE_POS_CONTROL(valve_pos.ref);
@@ -643,16 +643,16 @@
                 TMR3_COUNT_IREF++;
 
                 // Set Current Reference
-                double TMR3_CNT_MAX = (double)TMR_FREQ_5k/2.0;
-                double I_REF_MID = 0.0;
+                float TMR3_CNT_MAX = (float)TMR_FREQ_5k/2.0f;
+                float I_REF_MID = 0.0f;
                 if (TMR3_COUNT_IREF < TMR3_CNT_MAX) {
-                    I_REF = I_REF_MID + 1.0;
+                    I_REF = I_REF_MID + 1.0f;
                 } else {
-                    I_REF = I_REF_MID - 1.0;
+                    I_REF = I_REF_MID - 1.0f;
                 }
-//              double T = 1.0; // wave period
-//              I_REF = (5. * sin(2. * 3.1415 * (double) TMR3_COUNT_IREF / (double)TMR_FREQ_5k/ T));
-//              I_REF = (2.0 * sin(2. * 2. * 3.14 * (double) TMR3_COUNT_IREF / 5000.)+(2.0 * sin(2. * 1. * 3.14 * (double)TMR3_COUNT_IREF/ 5000.))+(2.0 * sin(2. * 5. * 3.14 * (double)TMR3_COUNT_IREF/ 5000.))+(2.0 * sin(2. * 10. * 3.14 * (double)TMR3_COUNT_IREF/ 5000.)));
+//              float T = 1.0; // wave period
+//              I_REF = (5. * sin(2. * 3.1415 * (float) TMR3_COUNT_IREF / (float)TMR_FREQ_5k/ T));
+//              I_REF = (2.0 * sin(2. * 2. * 3.14 * (float) TMR3_COUNT_IREF / 5000.)+(2.0 * sin(2. * 1. * 3.14 * (float)TMR3_COUNT_IREF/ 5000.))+(2.0 * sin(2. * 5. * 3.14 * (float)TMR3_COUNT_IREF/ 5000.))+(2.0 * sin(2. * 10. * 3.14 * (float)TMR3_COUNT_IREF/ 5000.)));
 
                 if (TMR3_COUNT_IREF % (int) (TMR_FREQ_5k / CAN_FREQ) == 0) {
                     //CAN_TX_PRES((int16_t)(I_REF*1000.0), (int16_t) (CUR_CURRENT*1000.0)); // to check the datas
@@ -667,8 +667,8 @@
                 TMR3_COUNT_IREF++;
 
                 // Set PWM reference
-                double TMR3_CNT_MAX = (double)TMR_FREQ_5k/2.0;
-                //double I_REF_MID = 0.0;
+                float TMR3_CNT_MAX = (float)TMR_FREQ_5k/2.0f;
+                //float I_REF_MID = 0.0f;
                 if (TMR3_COUNT_IREF < TMR3_CNT_MAX) {
                     CUR_PWM = 1000;
                 } else {
@@ -676,7 +676,7 @@
                 }
 
                 if (TMR3_COUNT_IREF % (int) (TMR_FREQ_5k / CAN_FREQ) == 0) {
-                    //CAN_TX_PRES((int16_t)(u_CUR[0]*1000.0), (int16_t) (CUR_CURRENT*1000.0)); // to check the datas
+                    //CAN_TX_PRES((int16_t)(u_CUR[0]*1000.0f), (int16_t) (CUR_CURRENT*1000.0f)); // to check the datas
                 }
                 break;
             }
@@ -690,32 +690,32 @@
             }
 
             case MODE_JOINT_POSITION_TORQUE_CONTROL_CURRENT: {
-                double I_REF_POS_FB = 0.0; // I_REF by Position Feedback
-                double I_REF_POS_FF = 0.0; // I_REF by Position Feedforward
-                double I_REF_FORCE_FB = 0.0; // I_REF by Force Feedback
-                double I_REF_FORCE_FF = 0.0; // I_REF by Force Feedforward
+                float I_REF_POS_FB = 0.0f; // I_REF by Position Feedback
+                float I_REF_POS_FF = 0.0f; // I_REF by Position Feedforward
+                float I_REF_FORCE_FB = 0.0f; // I_REF by Force Feedback
+                float I_REF_FORCE_FF = 0.0f; // I_REF by Force Feedforward
 
                 // feedback input for position control
                 pos.err = pos.ref - pos.sen;
-                double alpha_update_vel = 1.0/(1.0+(double)FREQ_TMR4/(2.0*3.1415*50.0)); // f_cutoff : 50Hz
-                double err_diff = (pos.err - pos.err_old)*(double)FREQ_5k;
-                pos.err_diff = (1.0-alpha_update_vel)*pos.err_diff + alpha_update_vel*err_diff;
+                float alpha_update_vel = 1.0f/(1.0f+(float)FREQ_TMR4/(2.0f*3.1415f*50.0f)); // f_cutoff : 50Hz
+                float err_diff = (pos.err - pos.err_old)*(float)FREQ_5k;
+                pos.err_diff = (1.0f-alpha_update_vel)*pos.err_diff + alpha_update_vel*err_diff;
                 pos.err_old = pos.err;
-                I_REF_POS_FB = 0.001*((double)P_GAIN_JOINT_POSITION * pos.err + (double)D_GAIN_JOINT_POSITION * pos.err_diff * 0.1);
+                I_REF_POS_FB = 0.001f*((float)P_GAIN_JOINT_POSITION * pos.err + (float)D_GAIN_JOINT_POSITION * pos.err_diff * 0.1f);
 
                 // feedforward input for position control
-                double Vel_Act_Ref = vel.ref; // [pulse/s] >> [deg/s]
-                double K_ff = 1.3;
-                double K_v = 0.0;
-                if(Vel_Act_Ref > 0) K_v = 1.0/100.0; // open, tuning. (deg/s >> mA)
-                if(Vel_Act_Ref < 0) K_v = 1.0/100.0; // close, tuning. (deg/s >> mA)
+                float Vel_Act_Ref = vel.ref; // [pulse/s] >> [deg/s]
+                float K_ff = 1.3f;
+                float K_v = 0.0f;
+                if(Vel_Act_Ref > 0) K_v = 1.0f/100.0f; // open, tuning. (deg/s >> mA)
+                if(Vel_Act_Ref < 0) K_v = 1.0f/100.0f; // close, tuning. (deg/s >> mA)
                 I_REF_POS_FF = K_ff*K_v*Vel_Act_Ref;
 
                 // feedback input for position control
-                I_REF_FORCE_FB = 0.0;
+                I_REF_FORCE_FB = 0.0f;
 
                 // feedforward input for position control
-                I_REF_FORCE_FF = 0.0;
+                I_REF_FORCE_FF = 0.0f;
 
                 cur.ref = I_REF_POS_FF + I_REF_POS_FB + I_REF_FORCE_FB + I_REF_FORCE_FF;
 
@@ -725,79 +725,79 @@
             }
 
             case MODE_JOINT_POSITION_PRES_CONTROL_CURRENT: {
-                //double T_REF = 0.0; // Torque Reference
-                double I_REF_FORCE_FB = 0.; // I_REF by Force Feedback
-                double I_REF_VC = 0.; // I_REF for velocity compensation
+                //float T_REF = 0.0; // Torque Reference
+                float I_REF_FORCE_FB = 0.; // I_REF by Force Feedback
+                float I_REF_VC = 0.; // I_REF for velocity compensation
 
                 // feedback input for position control
-                //double Joint_Pos_Err = 34.0-(double) pos.sen/(double)ENC_PULSE_PER_POSITION; // [pulse/s] >> [deg/s]
-                //double Joint_Vel_Err = 0.0-(double) vel.sen/(double)ENC_PULSE_PER_POSITION; // [pulse/s] >> [deg/s]
-                //double K_spring = 0.7;
-                //double D_damper = 0.02;
+                //float Joint_Pos_Err = 34.0f-(float) pos.sen/(float)ENC_PULSE_PER_POSITION; // [pulse/s] >> [deg/s]
+                //float Joint_Vel_Err = 0.0f-(float) vel.sen/(float)ENC_PULSE_PER_POSITION; // [pulse/s] >> [deg/s]
+                //float K_spring = 0.7f;
+                //float D_damper = 0.02f;
 //              T_REF = K_spring * pos.err + D_damper * Joint_Vel_Err; // unit : Nm
 
                 // torque feedback
                 torq.err = torq.ref - torq.sen;
                 //            torq.err_diff = torq.err - torq.err_old;
                 //            torq.err_old = torq.err;
-                torq.err_sum = torq.err_sum + torq.err/(double)TMR_FREQ_5k;
-                I_REF_FORCE_FB = 0.001*((double)P_GAIN_JOINT_TORQUE * torq.err + (double)I_GAIN_JOINT_TORQUE * torq.err_sum);
+                torq.err_sum = torq.err_sum + torq.err/(float)TMR_FREQ_5k;
+                I_REF_FORCE_FB = 0.001f*((float)P_GAIN_JOINT_TORQUE * torq.err + (float)I_GAIN_JOINT_TORQUE * torq.err_sum);
 
                 // velocity compensation for torque control
-                double Joint_Vel_Act = vel.sen/(double)ENC_PULSE_PER_POSITION; // [pulse/s] >> [deg/s]
-                double K_vc = 1.5; // Velocity comp. gain
-                double K_v = 0.0; // Valve gain
-                if(Joint_Vel_Act > 0) K_v = 1.0/100.0; // open, tuning
-                if(Joint_Vel_Act < 0) K_v = 1.0/100.0; // close, tuning
+                float Joint_Vel_Act = vel.sen/(float)ENC_PULSE_PER_POSITION; // [pulse/s] >> [deg/s]
+                float K_vc = 1.5f; // Velocity comp. gain
+                float K_v = 0.0f; // Valve gain
+                if(Joint_Vel_Act > 0) K_v = 1.0f/100.0f; // open, tuning
+                if(Joint_Vel_Act < 0) K_v = 1.0f/100.0f; // close, tuning
                 I_REF_VC = K_vc*K_v*Joint_Vel_Act;
 
                 cur.ref = I_REF_VC + I_REF_FORCE_FB;
                 //            cur.ref = I_REF_FORCE_FB;
 
-                double I_MAX = 10.00; // Maximum Current : 10mV
-                double Ka = 1.0/I_GAIN_JOINT_TORQUE;
+                float I_MAX = 10.0f; // Maximum Current : 10mV
+                float Ka = 1.0f/I_GAIN_JOINT_TORQUE;
                 if(cur.ref > I_MAX) {
-                    double I_rem = cur.ref-I_MAX;
+                    float I_rem = cur.ref-I_MAX;
                     I_rem = Ka*I_rem;
                     cur.ref = I_MAX;
-                    torq.err_sum = torq.err_sum - I_rem/(double)TMR_FREQ_5k;
+                    torq.err_sum = torq.err_sum - I_rem/(float)TMR_FREQ_5k;
                 } else if(cur.ref < -I_MAX) {
-                    double I_rem = cur.ref-(-I_MAX);
+                    float I_rem = cur.ref-(-I_MAX);
                     I_rem = Ka*I_rem;
                     cur.ref = -I_MAX;
-                    torq.err_sum = torq.err_sum - I_rem/(double)TMR_FREQ_5k;
+                    torq.err_sum = torq.err_sum - I_rem/(float)TMR_FREQ_5k;
                 }
 
                 CurrentControl();
 
 
                 /*
-                double I_REF_POS_FB = 0.0; // I_REF by Position Feedback
-                double I_REF_POS_FF = 0.0; // I_REF by Position Feedforward
-                double I_REF_FORCE_FB = 0.0; // I_REF by Force Feedback
-                double I_REF_FORCE_FF = 0.0; // I_REF by Force Feedforward
+                float I_REF_POS_FB = 0.0f; // I_REF by Position Feedback
+                float I_REF_POS_FF = 0.0f; // I_REF by Position Feedforward
+                float I_REF_FORCE_FB = 0.0f; // I_REF by Force Feedback
+                float I_REF_FORCE_FF = 0.0f; // I_REF by Force Feedforward
 
                 // feedback input for position control
                 pos.err = pos.ref - pos.sen;
-                double alpha_update_vel = 1.0/(1.0+(double)FREQ_TMR4/(2.0*3.1415*50.0)); // f_cutoff : 50Hz
-                double err_diff = (pos.err - pos.err_old)*(double)FREQ_5k;
-                pos.err_diff = (1.0-alpha_update_vel)*pos.err_diff + alpha_update_vel*err_diff;
+                float alpha_update_vel = 1.0f/(1.0f+(float)FREQ_TMR4/(2.0f*3.1415f*50.0f)); // f_cutoff : 50Hz
+                float err_diff = (pos.err - pos.err_old)*(float)FREQ_5k;
+                pos.err_diff = (1.0f-alpha_update_vel)*pos.err_diff + alpha_update_vel*err_diff;
                 pos.err_old = pos.err;
-                I_REF_POS_FB = 0.001*((double)P_GAIN_JOINT_POSITION * pos.err + (double)D_GAIN_JOINT_POSITION * pos.err_diff * 0.1);
+                I_REF_POS_FB = 0.001f*((float)P_GAIN_JOINT_POSITION * pos.err + (float)D_GAIN_JOINT_POSITION * pos.err_diff * 0.1f);
 
                 // feedforward input for position control
-                double Vel_Act_Ref = vel.ref; // [pulse/s] >> [deg/s]
-                double K_ff = 1.3;
-                double K_v = 0.0;
-                if(Vel_Act_Ref > 0) K_v = 1.0/100.0; // open, tuning. (deg/s >> mA)
-                if(Vel_Act_Ref < 0) K_v = 1.0/100.0; // close, tuning. (deg/s >> mA)
+                float Vel_Act_Ref = vel.ref; // [pulse/s] >> [deg/s]
+                float K_ff = 1.3f;
+                float K_v = 0.0f;
+                if(Vel_Act_Ref > 0) K_v = 1.0f/100.0f; // open, tuning. (deg/s >> mA)
+                if(Vel_Act_Ref < 0) K_v = 1.0f/100.0f; // close, tuning. (deg/s >> mA)
                 I_REF_POS_FF = K_ff*K_v*Vel_Act_Ref;
 
                 // feedback input for position control
-                I_REF_FORCE_FB = 0.0;
+                I_REF_FORCE_FB = 0.0f;
 
                 // feedforward input for position control
-                I_REF_FORCE_FF = 0.0;
+                I_REF_FORCE_FF = 0.0f;
 
                 cur.ref = I_REF_POS_FF + I_REF_POS_FB + I_REF_FORCE_FB + I_REF_FORCE_FF;
 
@@ -813,18 +813,18 @@
                     CUR_TORQUE_sum += torq.sen;
 
                     if (TMR3_COUNT_TORQUE_NULL % 10 == 0) {
-                        CUR_TORQUE_mean = CUR_TORQUE_sum / 10.0;
+                        CUR_TORQUE_mean = CUR_TORQUE_sum / 10.0f;
                         CUR_TORQUE_sum = 0;
 
-                        TORQUE_VREF += 0.0001 * (TORQUE_NULL - CUR_TORQUE_mean);
+                        TORQUE_VREF += 0.0001f * (TORQUE_NULL - CUR_TORQUE_mean);
 
-                        if (TORQUE_VREF > 3.3) TORQUE_VREF = 3.3;
+                        if (TORQUE_VREF > 3.3f) TORQUE_VREF = 3.3f;
                         if (TORQUE_VREF < 0) TORQUE_VREF = 0;
 
                         ROM_RESET_DATA();
 
                         //spi_eeprom_write(RID_TORQUE_SENSOR_VREF, (int16_t) (TORQUE_VREF * 1000.0));
-                        dac_1 = TORQUE_VREF / 3.3;
+                        dac_1 = TORQUE_VREF / 3.3f;
                     }
                 } else {
                     CONTROL_MODE = MODE_NO_ACT;
@@ -837,7 +837,7 @@
                     //spi_eeprom_write(RID_TORQUE_SENSOR_VREF, (int16_t) (TORQUE_VREF * 1000.0));
 
                     //pc.printf("%f\n", TORQUE_VREF);
-                    dac_1 = TORQUE_VREF / 3.3;
+                    dac_1 = TORQUE_VREF / 3.3f;
 
                 }
                 TMR3_COUNT_TORQUE_NULL++;
@@ -850,7 +850,7 @@
                     else temp_time = 0;
                 }
                 if (need_enc_init) {
-                    if (TMR3_COUNT_DEADZONE < (int) (0.5 * (double) TMR_FREQ_5k)) {
+                    if (TMR3_COUNT_DEADZONE < (int) (0.5f * (float) TMR_FREQ_5k)) {
                         V_out = VALVE_VOLTAGE_LIMIT;
                         pos_plus_end = pos.sen;
                     } else if (TMR3_COUNT_DEADZONE < TMR_FREQ_5k) {
@@ -861,10 +861,10 @@
                 }
 
                 if (temp_time <= TMR3_COUNT_DEADZONE && TMR3_COUNT_DEADZONE < (temp_time + TMR_FREQ_5k)) {
-                    V_out = (double) P_GAIN_JOINT_POSITION * (0.5 * (double) pos_plus_end + 0.5 * (double) pos_minus_end - (double) pos.sen);
+                    V_out = (float) P_GAIN_JOINT_POSITION * (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen);
                     VALVE_CENTER = VALVE_DEADZONE_PLUS = VALVE_DEADZONE_MINUS = 0;
 
-                } else if (temp_time <= TMR3_COUNT_DEADZONE && TMR3_COUNT_DEADZONE < (temp_time + (int) (1.9 * (double) TMR_FREQ_5k))) {
+                } else if (temp_time <= TMR3_COUNT_DEADZONE && TMR3_COUNT_DEADZONE < (temp_time + (int) (1.9f * (float) TMR_FREQ_5k))) {
                     V_out = 0;
                     CUR_VELOCITY_sum += CUR_VELOCITY;
                 } else if (TMR3_COUNT_DEADZONE == (temp_time + 2 * TMR_FREQ_5k)) {
@@ -927,7 +927,7 @@
                     cnt_vel_findhome = 0;
                     //REFERENCE_MODE = MODE_REF_NO_ACT; // Stop taking reference data from PODO
                     pos.ref_home_pos = pos.sen;
-                    vel.ref_home_pos = 0.0;
+                    vel.ref_home_pos = 0.0f;
                     FINDHOME_STAGE = FINDHOME_GOTOLIMIT;
                 } else if (FINDHOME_STAGE == FINDHOME_GOTOLIMIT) {
                     int cnt_check_enc = (TMR_FREQ_5k/500);
@@ -937,7 +937,7 @@
                         FINDHOME_POSITION_OLD = FINDHOME_POSITION;
                     }
                     cnt_findhome++;
-                    if(cnt_findhome == TMR_FREQ_5k) cnt_findhome = 0;
+                    //if(cnt_findhome == TMR_FREQ_5k) cnt_findhome = 0;
 
                     if (abs(FINDHOME_VELOCITY) <= 1) {
                         cnt_vel_findhome = cnt_vel_findhome + 1;
@@ -945,22 +945,22 @@
                         cnt_vel_findhome = 0;
                     }
 
-                    if (cnt_vel_findhome < 3*TMR_FREQ_5k) { // wait for 3sec
+                    if ((cnt_vel_findhome < 3*TMR_FREQ_5k) &&  cnt_findhome <= 10*TMR_FREQ_5k) { // wait for 3sec
                         //REFERENCE_MODE = MODE_REF_NO_ACT;
-                        if (HOMEPOS_OFFSET > 0) pos.ref_home_pos = pos.ref_home_pos + 1.0;
-                        else pos.ref_home_pos = pos.ref_home_pos - 1.0;
+                        if (HOMEPOS_OFFSET > 0) pos.ref_home_pos = pos.ref_home_pos + 2.0f;
+                        else pos.ref_home_pos = pos.ref_home_pos - 2.0f;
                         pos.err = pos.ref_home_pos - pos.sen;
-                        double VALVE_POS_RAW_POS_FB = 0.0;
-                        VALVE_POS_RAW_POS_FB = (double) P_GAIN_JOINT_POSITION * 0.01 * pos.err;
-                        VALVE_POS_RAW_POS_FB = VALVE_POS_RAW_POS_FB * 0.01;
+                        float VALVE_POS_RAW_POS_FB = 0.0f;
+                        VALVE_POS_RAW_POS_FB = (float) P_GAIN_JOINT_POSITION * 0.01f * pos.err;
+                        VALVE_POS_RAW_POS_FB = VALVE_POS_RAW_POS_FB * 0.01f;
                         valve_pos.ref = VALVE_POS_RAW_POS_FB + DDV_CENTER;
                         VALVE_POS_CONTROL(valve_pos.ref);
                         
-                        //double wn_Pos = 2.0*PI*5.0; // f_cut : 10Hz Position Control
-                        //I_REF = 0.04*wn_Pos*((double)joint_pos_err/ENC_PULSE_PER_POSITION);
+                        //float wn_Pos = 2.0f*PI*5.0f; // f_cut : 10Hz Position Control
+                        //I_REF = 0.04f*wn_Pos*((float)joint_pos_err/ENC_PULSE_PER_POSITION);
                         ////       L velocity >> mA convert
-                        //if(I_REF>5.0) I_REF = 5.0;
-                        //if(I_REF<-5.0) I_REF = -5.0;
+                        //if(I_REF>5.0f) I_REF = 5.0f;
+                        //if(I_REF<-5.0f) I_REF = -5.0f;
                         //FLAG_CURRNET_CONTROL = true;
                     } else {
                         ENC_SET(HOMEPOS_OFFSET);
@@ -976,32 +976,32 @@
                     }
                 } else if (FINDHOME_STAGE == FINDHOME_ZEROPOSE) {
                     int T_move = 2*TMR_FREQ_5k;
-                    pos.ref_home_pos = (0.0 - (double)INIT_REF_POS)*0.5*(1.0 - cos(3.14159 * (double)cnt_findhome / (double)T_move)) + (double)INIT_REF_POS;
-                    vel.ref_home_pos = 0.0;
+                    pos.ref_home_pos = (0.0f - (float)INIT_REF_POS)*0.5f*(1.0f - cos(3.14159f * (float)cnt_findhome / (float)T_move)) + (float)INIT_REF_POS;
+                    vel.ref_home_pos = 0.0f;
 
                     // input for position control
-                    pos.err = (pos.ref_home_pos - (double)pos.sen) / ENC_PULSE_PER_POSITION;
-                    double VALVE_POS_RAW_POS_FB = 0.0;
-                    VALVE_POS_RAW_POS_FB = (double) P_GAIN_JOINT_POSITION * 0.01 * pos.err;
-                    VALVE_POS_RAW_POS_FB = VALVE_POS_RAW_POS_FB * 0.01;
+                    pos.err = (pos.ref_home_pos - (float)pos.sen) / ENC_PULSE_PER_POSITION;
+                    float VALVE_POS_RAW_POS_FB = 0.0f;
+                    VALVE_POS_RAW_POS_FB = (float) P_GAIN_JOINT_POSITION * 0.01f * pos.err;
+                    VALVE_POS_RAW_POS_FB = VALVE_POS_RAW_POS_FB * 0.01f;
                     valve_pos.ref = VALVE_POS_RAW_POS_FB + DDV_CENTER;
                     VALVE_POS_CONTROL(valve_pos.ref);
 
 
 //                    if((OPERATING_MODE && 0x01) == 0) { // Rotary Mode
-//                        double wn_Pos = 2.0*PI*5.0; // f_cut : 10Hz Position Control
-//                        double temp_vel = ( 0.01 * (double)P_GAIN_JOINT_POSITION * wn_Pos * pos.err)*PI/180.0; // rad/s
+//                        float wn_Pos = 2.0f*PI*5.0f; // f_cut : 10Hz Position Control
+//                        float temp_vel = ( 0.01f * (float)P_GAIN_JOINT_POSITION * wn_Pos * pos.err)*PI/180.0f; // rad/s
 //                        //                            L when P-gain = 100, f_cut = 10Hz
-//                        if (temp_vel > 0.0 ) I_REF = temp_vel*((double)PISTON_AREA_A*0.00006/(K_v*sqrt(2.0*alpha3/(alpha3+1.0))));
-//                        else I_REF = temp_vel*((double)PISTON_AREA_B*0.00006/(K_v*sqrt(2.0/(alpha3+1.0))));
+//                        if (temp_vel > 0.0f ) I_REF = temp_vel*((float)PISTON_AREA_A*0.00006f/(K_v*sqrt(2.0f*alpha3/(alpha3+1.0f))));
+//                        else I_REF = temp_vel*((float)PISTON_AREA_B*0.00006f/(K_v*sqrt(2.0f/(alpha3+1.0f))));
 //                        //                                ------------------------------------------------------------------------
 //                        //                                   L   thetadot(rad/s) >> I_ref(mA)
 //                    } else if ((OPERATING_MODE && 0x01) == 1) { // Linear Mode
-//                        double wn_Pos = 2.0*PI*5.0; // f_cut : 10Hz Position Control
-//                        double temp_vel = ( 0.01  * (double)P_GAIN_JOINT_POSITION * wn_Pos * pos.err); // mm/s
+//                        float wn_Pos = 2.0f*PI*5.0f; // f_cut : 10Hz Position Control
+//                        float temp_vel = ( 0.01f  * (float)P_GAIN_JOINT_POSITION * wn_Pos * pos.err); // mm/s
 //                        //                            L when P-gain = 100, f_cut = 10Hz
-//                        if (temp_vel > 0.0 ) I_REF = temp_vel*((double)PISTON_AREA_A*0.00006/(K_v*sqrt(2.0*alpha3/(alpha3+1.0))));
-//                        else I_REF = temp_vel*((double)PISTON_AREA_B*0.00006/(K_v*sqrt(2.0/(alpha3+1.0))));
+//                        if (temp_vel > 0.0f ) I_REF = temp_vel*((float)PISTON_AREA_A*0.00006f/(K_v*sqrt(2.0f*alpha3/(alpha3+1.0f))));
+//                        else I_REF = temp_vel*((float)PISTON_AREA_B*0.00006f/(K_v*sqrt(2.0f/(alpha3+1.0f))));
 //                        //                                ------------------------------------------------------------------------
 //                        //                                   L   xdot(mm/s) >> I_ref(mA)
 //                    }
@@ -1010,10 +1010,10 @@
                     if (cnt_findhome >= T_move) {
                         //REFERENCE_MODE = MODE_REF_DIRECT;
                         cnt_findhome = 0;
-                        pos.ref = 0.0;
-                        vel.ref = 0.0;
-                        pos.ref_home_pos = 0.0;
-                        vel.ref_home_pos = 0.0;
+                        pos.ref = 0.0f;
+                        vel.ref = 0.0f;
+                        pos.ref_home_pos = 0.0f;
+                        vel.ref_home_pos = 0.0f;
                         FINDHOME_STAGE = FINDHOME_INIT;
                         CONTROL_MODE = MODE_JOINT_POSITION_TORQUE_CONTROL_VALVE_POSITION;
                     }
@@ -1027,11 +1027,11 @@
                     if (pos_plus_end == pos_minus_end) need_enc_init = true;
                     else {
                         V_out = -VALVE_VOLTAGE_LIMIT;
-                        temp_time = (int) (0.5 * (double) TMR_FREQ_5k);
+                        temp_time = (int) (0.5f * (float) TMR_FREQ_5k);
                     }
                 }
                 if (need_enc_init) {
-                    if (TMR3_COUNT_FLOWRATE < (int) (0.5 * (double) TMR_FREQ_5k)) {
+                    if (TMR3_COUNT_FLOWRATE < (int) (0.5f * (float) TMR_FREQ_5k)) {
                         V_out = VALVE_VOLTAGE_LIMIT;
                         pos_plus_end = pos.sen;
                     } else if (TMR3_COUNT_FLOWRATE < TMR_FREQ_5k) {
@@ -1039,8 +1039,8 @@
                         pos_minus_end = pos.sen;
                     } else if (TMR3_COUNT_FLOWRATE == TMR_FREQ_5k) {
                         need_enc_init = false;
-                        check_vel_pos_init = (int) (0.9 * (double) (pos_plus_end - pos_minus_end));
-                        check_vel_pos_fin = (int) (0.95 * (double) (pos_plus_end - pos_minus_end));
+                        check_vel_pos_init = (int) (0.9f * (float) (pos_plus_end - pos_minus_end));
+                        check_vel_pos_fin = (int) (0.95f * (float) (pos_plus_end - pos_minus_end));
                         check_vel_pos_interv = check_vel_pos_fin - check_vel_pos_init;
                     }
                     temp_time = TMR_FREQ_5k;
@@ -1048,23 +1048,23 @@
                 TMR3_COUNT_FLOWRATE++;
                 if (TMR3_COUNT_FLOWRATE > temp_time) {
                     if (flag_flowrate % 2 == 0) { // (+)
-                        VALVE_VOLTAGE = 1000.0 * (double) (flag_flowrate / 2 + 1);
+                        VALVE_VOLTAGE = 1000.0f * (float) (flag_flowrate / 2 + 1);
                         V_out = VALVE_VOLTAGE;
                         if (pos.sen > (pos_minus_end + check_vel_pos_init) && pos.sen < (pos_minus_end + check_vel_pos_fin)) {
                             fl_temp_cnt++;
                         } else if (pos.sen >= (pos_minus_end + check_vel_pos_fin) && CUR_VELOCITY == 0) {
-                            VALVE_GAIN_LPM_PER_V[flag_flowrate] = 0.95873 * 0.5757 * (double) TMR_FREQ_5k / 10000.0 * (double) check_vel_pos_interv / (double) fl_temp_cnt / VALVE_VOLTAGE; // 0.9587=6*pi/65536*10000 0.5757=0.02525*0.02*0.0095*2*60*1000
-                            //                        VALVE_GAIN_LPM_PER_V[flag_flowrate] = (double) TMR_FREQ_10k * (double) check_vel_pos_interv / (double) fl_temp_cnt / VALVE_VOLTAGE; // PULSE/sec
+                            VALVE_GAIN_LPM_PER_V[flag_flowrate] = 0.95873f * 0.5757f * (float) TMR_FREQ_5k / 10000.0 * (float) check_vel_pos_interv / (float) fl_temp_cnt / VALVE_VOLTAGE; // 0.9587=6*pi/65536*10000 0.5757=0.02525*0.02*0.0095*2*60*1000
+                            //                        VALVE_GAIN_LPM_PER_V[flag_flowrate] = (float) TMR_FREQ_10k * (float) check_vel_pos_interv / (float) fl_temp_cnt / VALVE_VOLTAGE; // PULSE/sec
                             fl_temp_cnt2++;
                         }
                     } else if (flag_flowrate % 2 == 1) { // (-)
-                        VALVE_VOLTAGE = -1. * (double) (flag_flowrate / 2 + 1);
+                        VALVE_VOLTAGE = -1. * (float) (flag_flowrate / 2 + 1);
                         V_out = VALVE_VOLTAGE;
                         if (pos.sen < (pos_plus_end - check_vel_pos_init) && pos.sen > (pos_plus_end - check_vel_pos_fin)) {
                             fl_temp_cnt++;
                         } else if (pos.sen <= (pos_plus_end - check_vel_pos_fin) && CUR_VELOCITY == 0) {
-                            VALVE_GAIN_LPM_PER_V[flag_flowrate] = 0.95873 * 0.5757 * (double) TMR_FREQ_5k / 10000.0 * (double) check_vel_pos_interv / (double) fl_temp_cnt / (-VALVE_VOLTAGE);
-                            //                        VALVE_GAIN_LPM_PER_V[flag_flowrate] = (double) TMR_FREQ_10k * (double) check_vel_pos_interv / (double) fl_temp_cnt / (-VALVE_VOLTAGE); // PULSE/sec
+                            VALVE_GAIN_LPM_PER_V[flag_flowrate] = 0.95873f * 0.5757f * (float) TMR_FREQ_5k / 10000.0f * (float) check_vel_pos_interv / (float) fl_temp_cnt / (-VALVE_VOLTAGE);
+                            //                        VALVE_GAIN_LPM_PER_V[flag_flowrate] = (float) TMR_FREQ_10k * (float) check_vel_pos_interv / (float) fl_temp_cnt / (-VALVE_VOLTAGE); // PULSE/sec
                             fl_temp_cnt2++;
                         }
                     }
@@ -1072,7 +1072,7 @@
 
                         ROM_RESET_DATA();
 
-                        //spi_eeprom_write(RID_VALVE_GAIN_PLUS_1 + flag_flowrate, (int16_t) (VALVE_GAIN_LPM_PER_V[flag_flowrate] * 100.0));
+                        //spi_eeprom_write(RID_VALVE_GAIN_PLUS_1 + flag_flowrate, (int16_t) (VALVE_GAIN_LPM_PER_V[flag_flowrate] * 100.0f));
                         cur_vel_sum = 0;
                         fl_temp_cnt = 0;
                         fl_temp_cnt2 = 0;
@@ -1101,22 +1101,22 @@
                     CUR_PRES_B_sum += pres_B.sen;
 
                     if (TMR3_COUNT_PRES_NULL % 10 == 0) {
-                        CUR_PRES_A_mean = CUR_PRES_A_sum / 10.0;
-                        CUR_PRES_B_mean = CUR_PRES_B_sum / 10.0;
+                        CUR_PRES_A_mean = CUR_PRES_A_sum / 10.0f;
+                        CUR_PRES_B_mean = CUR_PRES_B_sum / 10.0f;
                         CUR_PRES_A_sum = 0;
                         CUR_PRES_B_sum = 0;
 
-                        double VREF_NullingGain = 0.003;
+                        float VREF_NullingGain = 0.003f;
                         PRES_A_VREF -= VREF_NullingGain * (PRES_A_NULL - CUR_PRES_A_mean);
                         PRES_B_VREF -= VREF_NullingGain * (PRES_B_NULL - CUR_PRES_B_mean);
 
-                        if (PRES_A_VREF > 3.3) PRES_A_VREF = 3.3;
-                        if (PRES_A_VREF < 0) PRES_A_VREF = 0;
-                        if (PRES_B_VREF > 3.3) PRES_B_VREF = 3.3;
-                        if (PRES_B_VREF < 0) PRES_B_VREF = 0;
+                        if (PRES_A_VREF > 3.3f) PRES_A_VREF = 3.3f;
+                        if (PRES_A_VREF < 0.0f) PRES_A_VREF = 0.0f;
+                        if (PRES_B_VREF > 3.3f) PRES_B_VREF = 3.3f;
+                        if (PRES_B_VREF < 0.0f) PRES_B_VREF = 0.0f;
 
-                        dac_1 = PRES_A_VREF / 3.3;
-                        dac_2 = PRES_B_VREF / 3.3;
+                        dac_1 = PRES_A_VREF / 3.3f;
+                        dac_2 = PRES_B_VREF / 3.3f;
                     }
                 } else {
                     CONTROL_MODE = MODE_NO_ACT;
@@ -1128,8 +1128,8 @@
 
                     ROM_RESET_DATA();
 
-                    dac_1 = PRES_A_VREF / 3.3;
-                    dac_2 = PRES_B_VREF / 3.3;
+                    dac_1 = PRES_A_VREF / 3.3f;
+                    dac_2 = PRES_B_VREF / 3.3f;
                     //pc.printf("nulling end");
                 }
                 TMR3_COUNT_PRES_NULL++;
@@ -1151,10 +1151,10 @@
                     CONTROL_MODE = MODE_NO_ACT;
                     TMR3_COUNT_PRES_CALIB = 0;
                     V_out = 0;
-                    PRES_SENSOR_A_PULSE_PER_BAR = CUR_PRES_A_sum / ((double) TMR_FREQ_5k - 1.0) - PRES_A_NULL;
-                    PRES_SENSOR_A_PULSE_PER_BAR = PRES_SENSOR_A_PULSE_PER_BAR / ((double) PRES_SUPPLY - 1.0);
-                    PRES_SENSOR_B_PULSE_PER_BAR = CUR_PRES_B_sum / ((double) TMR_FREQ_5k - 1.0) - PRES_B_NULL;
-                    PRES_SENSOR_B_PULSE_PER_BAR = PRES_SENSOR_B_PULSE_PER_BAR / ((double) PRES_SUPPLY - 1.0);
+                    PRES_SENSOR_A_PULSE_PER_BAR = CUR_PRES_A_sum / ((float) TMR_FREQ_5k - 1.0f) - PRES_A_NULL;
+                    PRES_SENSOR_A_PULSE_PER_BAR = PRES_SENSOR_A_PULSE_PER_BAR / ((float) PRES_SUPPLY - 1.0f);
+                    PRES_SENSOR_B_PULSE_PER_BAR = CUR_PRES_B_sum / ((float) TMR_FREQ_5k - 1.0f) - PRES_B_NULL;
+                    PRES_SENSOR_B_PULSE_PER_BAR = PRES_SENSOR_B_PULSE_PER_BAR / ((float) PRES_SUPPLY - 1.0f);
                     CUR_PRES_A_sum = 0;
                     CUR_PRES_B_sum = 0;
                     CUR_PRES_A_mean = 0;
@@ -1162,22 +1162,22 @@
 
                     ROM_RESET_DATA();
 
-                    //spi_eeprom_write(RID_PRES_SENSOR_A_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0));
-                    //spi_eeprom_write(RID_PRES_SENSOR_B_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0));
+                    //spi_eeprom_write(RID_PRES_SENSOR_A_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f));
+                    //spi_eeprom_write(RID_PRES_SENSOR_B_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f));
                 }
                 TMR3_COUNT_PRES_CALIB++;
                 break;
             }
 
             case MODE_ROTARY_FRICTION_TUNING: {
-                if (TMR3_COUNT_ROTARY_FRIC_TUNE % (5 * TMR_FREQ_5k) == 0) freq_fric_tune = 4 + 3. * sin(2 * 3.14159 * 0.5 * TMR3_COUNT_ROTARY_FRIC_TUNE * 0.0001 * 0.05);
-                V_out = PWM_out * sin(2 * 3.14159 * freq_fric_tune * TMR3_COUNT_ROTARY_FRIC_TUNE * 0.0001);
+                if (TMR3_COUNT_ROTARY_FRIC_TUNE % (5 * TMR_FREQ_5k) == 0) freq_fric_tune = 4.0f + 3.0f * sin(2 * 3.14159f * 0.5f * TMR3_COUNT_ROTARY_FRIC_TUNE * 0.0001f * 0.05f);
+                V_out = PWM_out * sin(2 * 3.14159f * freq_fric_tune * TMR3_COUNT_ROTARY_FRIC_TUNE * 0.0001f);
                 if (V_out > 0) V_out = VALVE_VOLTAGE_LIMIT;
                 else V_out = -VALVE_VOLTAGE_LIMIT;
                 TMR3_COUNT_ROTARY_FRIC_TUNE++;
                 if (TMR3_COUNT_ROTARY_FRIC_TUNE > TUNING_TIME * TMR_FREQ_5k) {
                     TMR3_COUNT_ROTARY_FRIC_TUNE = 0;
-                    V_out = 0;
+                    V_out = 0.0f;
                     CONTROL_MODE = MODE_NO_ACT;
                 }
                 break;
@@ -1187,9 +1187,9 @@
                 VALVE_ID_timer = VALVE_ID_timer + 1;
 
                 if(VALVE_ID_timer < TMR_FREQ_5k*1) {
-                    V_out = 3000.0 * sin(2*3.14*VALVE_ID_timer/TMR_FREQ_5k * 100.0);
+                    V_out = 3000.0f * sin(2*3.14f*VALVE_ID_timer/TMR_FREQ_5k * 100.0f);
                 } else if(VALVE_ID_timer < TMR_FREQ_5k*2) {
-                    V_out = 1000.0*(ID_index_array[ID_index]);
+                    V_out = 1000.0f*(ID_index_array[ID_index]);
                 } else if(VALVE_ID_timer == TMR_FREQ_5k*2) {
                     VALVE_POS_TMP = 0;
                     data_num = 0;
@@ -1228,43 +1228,43 @@
 
                 VALVE_DZ_timer = VALVE_DZ_timer + 1;
                 if(first_check == 0) {
-                    if(VALVE_DZ_timer < (int) (1.0 * (double) TMR_FREQ_5k)) {
+                    if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) {
                         V_out = VALVE_VOLTAGE_LIMIT;
-                    } else if(VALVE_DZ_timer == (int) (1.0 * (double) TMR_FREQ_5k)) {
+                    } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) {
                         V_out = VALVE_VOLTAGE_LIMIT;
                         pos_plus_end = pos.sen;
-                    } else if(VALVE_DZ_timer < (int) (2.0 * (double) TMR_FREQ_5k)) {
+                    } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) {
                         V_out = -VALVE_VOLTAGE_LIMIT;
-                    } else if(VALVE_DZ_timer == (int) (2.0 * (double) TMR_FREQ_5k)) {
+                    } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) {
                         V_out = -VALVE_VOLTAGE_LIMIT;
                         pos_minus_end = pos.sen;
-                    } else if(VALVE_DZ_timer < (int) (3.0 * (double) TMR_FREQ_5k)) {
-                        V_out = (double) P_GAIN_JOINT_POSITION * 0.01 * (0.5 * (double) pos_plus_end + 0.5 * (double) pos_minus_end - (double) pos.sen);
-                    } else if(VALVE_DZ_timer < (int) (4.0 * (double) TMR_FREQ_5k)) {
-                        V_out = (double) P_GAIN_JOINT_POSITION * 0.01 * (0.5 * (double) pos_plus_end + 0.5 * (double) pos_minus_end - (double) pos.sen);
+                    } else if(VALVE_DZ_timer < (int) (3.0f * (float) TMR_FREQ_5k)) {
+                        V_out = (float) P_GAIN_JOINT_POSITION * 0.01f * (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen);
+                    } else if(VALVE_DZ_timer < (int) (4.0f * (float) TMR_FREQ_5k)) {
+                        V_out = (float) P_GAIN_JOINT_POSITION * 0.01f * (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen);
                         data_num = data_num + 1;
                         VALVE_POS_TMP = VALVE_POS_TMP + value;
-                    } else if(VALVE_DZ_timer == (int) (4.0 * (double) TMR_FREQ_5k)) {
-                        V_out = (double) P_GAIN_JOINT_POSITION * 0.01 * (0.5 * (double) pos_plus_end + 0.5 * (double) pos_minus_end - (double) pos.sen);
+                    } else if(VALVE_DZ_timer == (int) (4.0f * (float) TMR_FREQ_5k)) {
+                        V_out = (float) P_GAIN_JOINT_POSITION * 0.01f * (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen);
                         DDV_POS_AVG = VALVE_POS_TMP / data_num;
                         START_POS = pos.sen;
                         //CAN_TX_PRES((int16_t) (DDV_POS_AVG), (int16_t) (data_num));
                         VALVE_POS_TMP = 0;
                         data_num = 0;
 
-                    } else if(VALVE_DZ_timer < (int) (5.0 * (double) TMR_FREQ_5k)) {
+                    } else if(VALVE_DZ_timer < (int) (5.0f * (float) TMR_FREQ_5k)) {
                         valve_pos.ref = DDV_POS_AVG;
                         VALVE_POS_CONTROL(valve_pos.ref);
                         //CAN_TX_PRES((int16_t) (VALVE_MAX_POS), (int16_t) (VALVE_MIN_POS));
 
-                    } else if(VALVE_DZ_timer < (int) (6.0 * (double) TMR_FREQ_5k)) {
+                    } else if(VALVE_DZ_timer < (int) (6.0f * (float) TMR_FREQ_5k)) {
                         valve_pos.ref = DDV_POS_AVG;
                         VALVE_POS_CONTROL(valve_pos.ref);
                         if(CUR_VELOCITY >= 0)
                             VEL_POINT = VEL_POINT + 1;
                         else
                             VEL_POINT = VEL_POINT - 1;
-                    } else if(VALVE_DZ_timer == (int) (6.0 * (double) TMR_FREQ_5k)) {
+                    } else if(VALVE_DZ_timer == (int) (6.0f * (float) TMR_FREQ_5k)) {
                         valve_pos.ref = DDV_POS_AVG;
                         VALVE_POS_CONTROL(valve_pos.ref);
                         FINAL_POS = pos.sen;
@@ -1301,11 +1301,11 @@
                     }
                 } else {
                     if((DZ_case == -1 && DZ_NUM == 1) | (DZ_case == 1 && DZ_NUM == 1)) {
-                        if(VALVE_DZ_timer < (int) (1.0 * (double) TMR_FREQ_5k)) {
-                            V_out = (double) P_GAIN_JOINT_POSITION * 0.01 * (0.5 * (double) pos_plus_end + 0.5 * (double) pos_minus_end - (double) pos.sen);
-                        } else if(VALVE_DZ_timer == (int) (1.0 * (double) TMR_FREQ_5k)) {
+                        if(VALVE_DZ_timer < (int) (1.0 * (float) TMR_FREQ_5k)) {
+                            V_out = (float) P_GAIN_JOINT_POSITION * 0.01f * (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen);
+                        } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) {
                             START_POS = pos.sen;
-                        } else if(VALVE_DZ_timer < (int) (2.0 * (double) TMR_FREQ_5k)) {
+                        } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) {
                             valve_pos.ref = Ref_Valve_Pos_Old  - DZ_case * DZ_DIRECTION * 64 / DZ_index;
                             if(valve_pos.ref <= VALVE_MIN_POS) {
                                 valve_pos.ref = VALVE_MIN_POS;
@@ -1317,7 +1317,7 @@
                                 VEL_POINT = VEL_POINT + 1;
                             else
                                 VEL_POINT = VEL_POINT - 1;
-                        } else if(VALVE_DZ_timer == (int) (2.0 * (double) TMR_FREQ_5k)) {
+                        } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) {
                             Ref_Valve_Pos_Old = valve_pos.ref;
                             FINAL_POS = pos.sen;
                             //                        if(VEL_POINT >= 0)
@@ -1350,11 +1350,11 @@
                             //CAN_TX_PRES((int16_t) (1), (int16_t) (DZ_index));
                         }
                     } else if((DZ_case == -1 && DZ_NUM == 2) | (DZ_case == 1 && DZ_NUM == 2)) {
-                        if(VALVE_DZ_timer < (int) (1.0 * (double) TMR_FREQ_5k)) {
-                            V_out = (double) P_GAIN_JOINT_POSITION * 0.01 * (0.5 * (double) pos_plus_end + 0.5 * (double) pos_minus_end - (double) pos.sen);
-                        } else if(VALVE_DZ_timer == (int) (1.0 * (double) TMR_FREQ_5k)) {
+                        if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) {
+                            V_out = (float) P_GAIN_JOINT_POSITION * 0.01f * (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen);
+                        } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) {
                             START_POS = pos.sen;
-                        } else if(VALVE_DZ_timer < (int) (2.0 * (double) TMR_FREQ_5k)) {
+                        } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) {
                             valve_pos.ref = Ref_Valve_Pos_Old  + DZ_DIRECTION * 64 / DZ_index;
                             if(valve_pos.ref <= VALVE_MIN_POS) {
                                 valve_pos.ref = VALVE_MIN_POS;
@@ -1366,7 +1366,7 @@
                                 VEL_POINT = VEL_POINT + 1;
                             else
                                 VEL_POINT = VEL_POINT - 1;
-                        } else if(VALVE_DZ_timer == (int) (2.0 * (double) TMR_FREQ_5k)) {
+                        } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) {
                             Ref_Valve_Pos_Old = valve_pos.ref;
                             FINAL_POS = pos.sen;
                             //                        if(VEL_POINT >= 0)
@@ -1391,7 +1391,7 @@
                             DZ_index= DZ_index *2;
                             if(DZ_index >= 128) {
                                 SECOND_DZ = valve_pos.ref;
-                                DDV_CENTER = (int) (0.5 * (double) (FIRST_DZ) + 0.5 * (double) (SECOND_DZ));
+                                DDV_CENTER = (int) (0.5f * (float) (FIRST_DZ) + 0.5f * (float) (SECOND_DZ));
                                 first_check = 0;
                                 VALVE_DEADZONE_MINUS = FIRST_DZ;
                                 VALVE_DEADZONE_PLUS = SECOND_DZ;
@@ -1409,11 +1409,11 @@
                             //CAN_TX_PRES((int16_t) (2), (int16_t) (DZ_index));
                         }
                     } else if(DZ_case == 0 && DZ_NUM ==1) {
-                        if(VALVE_DZ_timer < (int) (1.0 * (double) TMR_FREQ_5k)) {
-                            V_out = (double) P_GAIN_JOINT_POSITION * 0.01* (0.5 * (double) pos_plus_end + 0.5 * (double) pos_minus_end - (double) pos.sen);
-                        } else if(VALVE_DZ_timer == (int) (1.0 * (double) TMR_FREQ_5k)) {
+                        if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) {
+                            V_out = (float) P_GAIN_JOINT_POSITION * 0.01f* (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen);
+                        } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) {
                             START_POS = pos.sen;
-                        } else if(VALVE_DZ_timer < (int) (2.0 * (double) TMR_FREQ_5k)) {
+                        } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) {
                             valve_pos.ref = Ref_Valve_Pos_Old  - DZ_DIRECTION * 64 / DZ_index;
                             if(valve_pos.ref <= VALVE_MIN_POS) {
                                 valve_pos.ref = VALVE_MIN_POS;
@@ -1425,7 +1425,7 @@
                                 VEL_POINT = VEL_POINT + 1;
                             else
                                 VEL_POINT = VEL_POINT - 1;
-                        } else if(VALVE_DZ_timer == (int) (2.0 * (double) TMR_FREQ_5k)) {
+                        } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) {
                             Ref_Valve_Pos_Old = valve_pos.ref;
                             FINAL_POS = pos.sen;
                             //                        if(VEL_POINT >= 0)
@@ -1456,11 +1456,11 @@
                             }
                         }
                     } else {
-                        if(VALVE_DZ_timer < (int) (1.0 * (double) TMR_FREQ_5k)) {
-                            V_out = (double) P_GAIN_JOINT_POSITION * 0.01* (0.5 * (double) pos_plus_end + 0.5 * (double) pos_minus_end - (double) pos.sen);
-                        } else if(VALVE_DZ_timer == (int) (1.0 * (double) TMR_FREQ_5k)) {
+                        if(VALVE_DZ_timer < (int) (1.0f * (float) TMR_FREQ_5k)) {
+                            V_out = (float) P_GAIN_JOINT_POSITION * 0.01f* (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen);
+                        } else if(VALVE_DZ_timer == (int) (1.0f * (float) TMR_FREQ_5k)) {
                             START_POS = pos.sen;
-                        } else if(VALVE_DZ_timer < (int) (2.0 * (double) TMR_FREQ_5k)) {
+                        } else if(VALVE_DZ_timer < (int) (2.0f * (float) TMR_FREQ_5k)) {
                             valve_pos.ref = Ref_Valve_Pos_Old  + DZ_DIRECTION * 64 / DZ_index;
                             if(valve_pos.ref <= VALVE_MIN_POS) {
                                 valve_pos.ref = VALVE_MIN_POS;
@@ -1472,7 +1472,7 @@
                                 VEL_POINT = VEL_POINT + 1;
                             else
                                 VEL_POINT = VEL_POINT - 1;
-                        } else if(VALVE_DZ_timer == (int) (2.0 * (double) TMR_FREQ_5k)) {
+                        } else if(VALVE_DZ_timer == (int) (2.0f * (float) TMR_FREQ_5k)) {
                             Ref_Valve_Pos_Old = valve_pos.ref;
                             FINAL_POS = pos.sen;
                             if(VEL_POINT >= 0)
@@ -1490,7 +1490,7 @@
                             DZ_index= DZ_index *2;
                             if(DZ_index >= 128) {
                                 SECOND_DZ = valve_pos.ref;
-                                DDV_CENTER = (int) (0.5 * (double) (FIRST_DZ) + 0.5 * (double) (SECOND_DZ));
+                                DDV_CENTER = (int) (0.5f * (float) (FIRST_DZ) + 0.5f * (float) (SECOND_DZ));
                                 first_check = 0;
                                 VALVE_DEADZONE_MINUS = FIRST_DZ;
                                 //spi_eeprom_write(RID_VALVE_DEADZONE_PLUS, FIRST_DZ);
@@ -1515,16 +1515,16 @@
             case MODE_DDV_POS_VS_FLOWRATE: {
                 VALVE_FR_timer = VALVE_FR_timer + 1;
                 if(first_check == 0) {
-                    if(VALVE_FR_timer < (int) (1.0 * (double) TMR_FREQ_5k)) {
+                    if(VALVE_FR_timer < (int) (1.0f * (float) TMR_FREQ_5k)) {
                         V_out = VALVE_VOLTAGE_LIMIT;
                         //CAN_TX_PRES((int16_t) (VALVE_FR_timer), (int16_t) (6));
-                    } else if(VALVE_FR_timer == (int) (1.0 * (double) TMR_FREQ_5k)) {
+                    } else if(VALVE_FR_timer == (int) (1.0f * (float) TMR_FREQ_5k)) {
                         V_out = VALVE_VOLTAGE_LIMIT;
                         pos_plus_end = pos.sen;
                         //                    CAN_TX_PRES((int16_t) (V_out), (int16_t) (7));
-                    } else if(VALVE_FR_timer < (int) (2.0 * (double) TMR_FREQ_5k)) {
+                    } else if(VALVE_FR_timer < (int) (2.0f * (float) TMR_FREQ_5k)) {
                         V_out = -VALVE_VOLTAGE_LIMIT;
-                    } else if(VALVE_FR_timer == (int) (2.0 * (double) TMR_FREQ_5k)) {
+                    } else if(VALVE_FR_timer == (int) (2.0f * (float) TMR_FREQ_5k)) {
                         //                    CAN_TX_PRES((int16_t) (V_out), (int16_t) (8));
                         V_out = -VALVE_VOLTAGE_LIMIT;
                         pos_minus_end = pos.sen;
@@ -1536,23 +1536,23 @@
                         min_check = 0;
                     }
                 } else {
-                    if(VALVE_FR_timer < (int) (1.0 * (double) TMR_FREQ_5k)) {
-                        V_out = (double) P_GAIN_JOINT_POSITION * 0.01* (0.5 * (double) pos_plus_end + 0.5 * (double) pos_minus_end - (double) pos.sen);
-                    } else if(VALVE_FR_timer == (int) (1.0 * (double) TMR_FREQ_5k)) {
+                    if(VALVE_FR_timer < (int) (1.0f * (float) TMR_FREQ_5k)) {
+                        V_out = (float) P_GAIN_JOINT_POSITION * 0.01f* (0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen);
+                    } else if(VALVE_FR_timer == (int) (1.0f * (float) TMR_FREQ_5k)) {
                         data_num = 0;
                         valve_pos.ref = 10*(ID_index_array[ID_index]) + DDV_CENTER;
 
                         VALVE_POS_CONTROL(valve_pos.ref);
                         START_POS = pos.sen;
-                    } else if(VALVE_FR_timer < (int) (5.0 * (double) TMR_FREQ_5k)) {
+                    } else if(VALVE_FR_timer < (int) (5.0f * (float) TMR_FREQ_5k)) {
                         valve_pos.ref = 10*(ID_index_array[ID_index]) + DDV_CENTER;
                         VALVE_POS_CONTROL(valve_pos.ref);
                         data_num = data_num + 1;
-                        if(abs(0.5 * (double) pos_plus_end + 0.5 * (double) pos_minus_end - (double) pos.sen) > 20000.0) {
+                        if(abs(0.5f * (float) pos_plus_end + 0.5f * (float) pos_minus_end - (float) pos.sen) > 20000.0f) {
                             FINAL_POS = pos.sen;
                             one_period_end = 1;
                         }
-                    } else if(VALVE_FR_timer == (int) (5.0 * (double) TMR_FREQ_5k)) {
+                    } else if(VALVE_FR_timer == (int) (5.0f * (float) TMR_FREQ_5k)) {
                         FINAL_POS = pos.sen;
                         one_period_end = 1;
                     }
@@ -1573,7 +1573,7 @@
                         one_period_end = 0;
                         ID_index= ID_index +1;
                         //                    CAN_TX_PRES((int16_t) (valve_pos.ref), (int16_t) (ID_index));
-                        V_out = 0.0;
+                        V_out = 0.0f;
                     }
 
                     if(max_check == 1 && min_check == 1) {
@@ -1611,8 +1611,8 @@
             VALVE_PWM_VALVE_DZ = V_out + VALVE_CENTER;
 
             // Output Voltage Linearization and Dead Zone Cancellation (Electrical dead-zone)
-            double CUR_PWM_nonlin = VALVE_PWM_VALVE_DZ/5.0*1000.0; // convert PWM duty to mV
-            double CUR_PWM_DZ = PWM_duty_byLT(CUR_PWM_nonlin);
+            float CUR_PWM_nonlin = VALVE_PWM_VALVE_DZ/5.0f*1000.0f; // convert PWM duty to mV
+            float CUR_PWM_DZ = PWM_duty_byLT(CUR_PWM_nonlin);
 
             if (CUR_PWM_DZ > 0) V_out = (int)CUR_PWM_DZ + 143;
             else if (CUR_PWM_DZ < 0) V_out = (int)CUR_PWM_DZ - 138;
@@ -1624,11 +1624,11 @@
         /*******************************************************
         ***     PWM
         ********************************************************/
-        if (V_out >= 12000.0){
-            V_out = 12000.0;
+        if (V_out >= 12000.0f){
+            V_out = 12000.0f;
         }
-        else if(V_out<=-12000.0){
-            V_out = -12000.0;
+        else if(V_out<=-12000.0f){
+            V_out = -12000.0f;
         }
         PWM_out= V_out/SUPPLY_VOLTAGE; // Full duty : 12000.0mV
 
@@ -1637,20 +1637,20 @@
 //        else if (PWM_out < -0.41667) PWM_out=-0.41667;
 
         // Saturation of output voltage to 12.0V
-        if(PWM_out > 1.0) PWM_out=1.0;
-        else if (PWM_out < -1.0) PWM_out=-1.0;
+        if(PWM_out > 1.0f) PWM_out=1.0f;
+        else if (PWM_out < -1.0f) PWM_out=-1.0f;
 
-        if (PWM_out>0.0) {
-            dtc_v=0.0;
+        if (PWM_out>0.0f) {
+            dtc_v=0.0f;
             dtc_w=PWM_out;
         } else {
             dtc_v=-PWM_out;
-            dtc_w=0.0;
+            dtc_w=0.0f;
         }
 
         //pwm
-        TIM4->CCR2 = (PWM_ARR)*(1.0-dtc_v);
-        TIM4->CCR1 = (PWM_ARR)*(1.0-dtc_w);
+        TIM4->CCR2 = (PWM_ARR)*(1.0f-dtc_v);
+        TIM4->CCR1 = (PWM_ARR)*(1.0f-dtc_w);
 
     }
     TIM3->SR = 0x0;  // reset the status register
@@ -1660,8 +1660,8 @@
 
 
 //unsigned long CNT_TMR5 = 0;
-//double FREQ_TMR5 = (double)FREQ_500;
-//double DT_TMR5 = (double)DT_500;
+//float FREQ_TMR5 = (float)FREQ_500;
+//float DT_TMR5 = (float)DT_500;
 extern "C" void TIM2_IRQHandler(void)
 {
     if (TIM2->SR & TIM_SR_UIF ) {
@@ -1730,19 +1730,19 @@
     cur.err_diff = (cur.err - cur.err_old)*FREQ_TMR4;
     cur.err_old = cur.err;
 
-    double R_model = 150.0; // ohm
-    double L_model = 0.3;
-    double w0 = 2.0*3.14*90.0;
-    double KP_I = L_model*w0;
-    double KI_I = R_model*w0;
-    double KD_I = 0.0;
+    float R_model = 150.0f; // ohm
+    float L_model = 0.3f;
+    float w0 = 2.0f*3.14f*90.0f;
+    float KP_I = L_model*w0;
+    float KI_I = R_model*w0;
+    float KD_I = 0.0f;
 
-    double FF_gain = 0.0;
+    float FF_gain = 0.0f;
     V_out = (int) (KP_I * cur.err + KI_I * cur.err_int + KD_I * cur.err_diff);
     //          V_out = V_out + FF_gain * (R_model*I_REF); // Unit : mV
     V_out = V_out + FF_gain * (R_model*cur.ref + L_model*cur.ref_diff); // Unit : mV
 
-    double Ka = 5.0/KP_I;
+    float Ka = 5.0f/KP_I;
     if(V_out > V_MAX) {
         V_rem = V_out-V_MAX;
         V_rem = Ka*V_rem;
@@ -1757,3 +1757,4 @@
 }
 
 
+