Sungwoo Kim
/
HydraulicControlBoard_Rainbow_v1_2_copy1
2011
Diff: CAN/function_CAN.cpp
- Revision:
- 55:b25725257569
- Parent:
- 54:647072f5307a
- Child:
- 56:6f50d9d3bfee
--- a/CAN/function_CAN.cpp Tue Feb 25 12:56:39 2020 +0000 +++ b/CAN/function_CAN.cpp Wed Feb 26 12:51:52 2020 +0000 @@ -283,10 +283,6 @@ VALVE_DEADZONE_MINUS = (int16_t) (msg.data[5] | msg.data[6] << 8); ROM_RESET_DATA(); - - //spi_eeprom_write(RID_VALVE_CNETER, (int16_t) (VALVE_CENTER)); - //spi_eeprom_write(RID_VALVE_DEADZONE_PLUS, (int16_t) (VALVE_DEADZONE_PLUS)); - //spi_eeprom_write(RID_VALVE_DEADZONE_MINUS, (int16_t) (VALVE_DEADZONE_MINUS)); break; } @@ -447,11 +443,9 @@ } case CRX_SET_VALVE_LIMIT: { - VALVE_LIMIT_MINUS = (int16_t) (msg.data[1] | msg.data[2] << 8); - VALVE_LIMIT_PLUS = (int16_t) (msg.data[3] | msg.data[4] << 8); + VALVE_MIN_POS = (int16_t) (msg.data[1] | msg.data[2] << 8); + VALVE_MAX_POS = (int16_t) (msg.data[3] | msg.data[4] << 8); ROM_RESET_DATA(); - //spi_eeprom_write(RID_VALVE_LIMIT_MINUS, (int16_t) VALVE_LIMIT_MINUS); - //spi_eeprom_write(RID_VALVE_LIMIT_PLUS, (int16_t) VALVE_LIMIT_PLUS); break; } @@ -633,9 +627,8 @@ break; } case CRX_SET_VALVE_CENTER_OFFSET: { - VALVE_CENTER_OFFSET_times10 = (int16_t) (msg.data[1] | msg.data[2] << 8); - VALVE_CENTER_OFFSET = ((float) VALVE_CENTER_OFFSET_times10) * 0.1f; - DDV_CENTER = DDV_CENTER + VALVE_CENTER_OFFSET; + VALVE_CENTER_OFFSET = ((float) ((int16_t) (msg.data[1] | msg.data[2] << 8))) * 0.1f; + VALVE_CENTER = VALVE_CENTER + VALVE_CENTER_OFFSET; ROM_RESET_DATA(); break; } @@ -737,9 +730,9 @@ valve_pos.ref = (double) temp_ref_valve_pos; } else { //SW Valve if(temp_ref_valve_pos >= 0) { - valve_pos.ref = (double)DDV_CENTER + (double)temp_ref_valve_pos * ((double)VALVE_MAX_POS-(double)DDV_CENTER)/10000.0f; + valve_pos.ref = (double)VALVE_CENTER + (double)temp_ref_valve_pos * ((double)VALVE_MAX_POS-(double)VALVE_CENTER)/10000.0f; } else { - valve_pos.ref = (double)DDV_CENTER - (double)temp_ref_valve_pos * ((double)VALVE_MIN_POS-(double)DDV_CENTER)/10000.0f; + valve_pos.ref = (double)VALVE_CENTER - (double)temp_ref_valve_pos * ((double)VALVE_MIN_POS-(double)VALVE_CENTER)/10000.0f; } } } else if(address==CID_RX_REF_PWM){ @@ -927,8 +920,8 @@ temp_msg.id = CID_TX_INFO; temp_msg.len = 7; temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_DEADZONE; - temp_msg.data[1] = (uint8_t) (int) (VALVE_CENTER); - temp_msg.data[2] = (uint8_t) ((int) (VALVE_CENTER) >> 8); + temp_msg.data[1] = (uint8_t) VALVE_CENTER; + temp_msg.data[2] = (uint8_t) (VALVE_CENTER >> 8); temp_msg.data[3] = (uint8_t) (int) (VALVE_DEADZONE_PLUS); temp_msg.data[4] = (uint8_t) ((int) (VALVE_DEADZONE_PLUS) >> 8); temp_msg.data[5] = (uint8_t) (int) (VALVE_DEADZONE_MINUS); @@ -1059,10 +1052,10 @@ temp_msg.id = CID_TX_INFO; temp_msg.len = 5; temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_LIMIT; - temp_msg.data[1] = (uint8_t) VALVE_LIMIT_MINUS; - temp_msg.data[2] = (uint8_t) (VALVE_LIMIT_MINUS >> 8); - temp_msg.data[3] = (uint8_t) VALVE_LIMIT_PLUS; - temp_msg.data[4] = (uint8_t) (VALVE_LIMIT_PLUS >> 8); + temp_msg.data[1] = (uint8_t) VALVE_MIN_POS; + temp_msg.data[2] = (uint8_t) (VALVE_MIN_POS >> 8); + temp_msg.data[3] = (uint8_t) VALVE_MAX_POS; + temp_msg.data[4] = (uint8_t) (VALVE_MAX_POS >> 8); can.write(temp_msg); } @@ -1142,8 +1135,8 @@ float temp_valve_deadzone_plus = 0.0f; float temp_ddv_center = 0.0f; - temp_valve_deadzone_plus = 10000.0f*((double)VALVE_DEADZONE_PLUS-(double)DDV_CENTER)/((double)VALVE_MAX_POS-(double)DDV_CENTER); - temp_valve_deadzone_minus = -10000.0f*((double)VALVE_DEADZONE_MINUS-(double)DDV_CENTER)/((double)VALVE_MIN_POS-(double)DDV_CENTER); + temp_valve_deadzone_plus = 10000.0f*((double)VALVE_DEADZONE_PLUS-(double)VALVE_CENTER)/((double)VALVE_MAX_POS-(double)VALVE_CENTER); + temp_valve_deadzone_minus = -10000.0f*((double)VALVE_DEADZONE_MINUS-(double)VALVE_CENTER)/((double)VALVE_MIN_POS-(double)VALVE_CENTER); temp_ddv_center = 0.0f; temp_msg.id = CID_TX_INFO; @@ -1222,10 +1215,10 @@ int16_t valve_pos_vs_pwm; // valve_pos_vs_pwm = (int16_t) (VALVE_POS_VS_PWM[canindex]); - if(VALVE_POS_VS_PWM[canindex]>=DDV_CENTER) { - valve_pos_vs_pwm = 10000.0f*((double)VALVE_POS_VS_PWM[canindex]-(double)DDV_CENTER)/((double)VALVE_MAX_POS-(double)DDV_CENTER); + if(VALVE_POS_VS_PWM[canindex]>= (float) VALVE_CENTER) { + valve_pos_vs_pwm = 10000.0f*((double)VALVE_POS_VS_PWM[canindex]-(double)VALVE_CENTER)/((double)VALVE_MAX_POS-(double)VALVE_CENTER); } else { - valve_pos_vs_pwm = -10000.0f*((double)VALVE_POS_VS_PWM[canindex]-(double)DDV_CENTER)/((double)VALVE_MIN_POS-(double)DDV_CENTER); + valve_pos_vs_pwm = -10000.0f*((double)VALVE_POS_VS_PWM[canindex]-(double)VALVE_CENTER)/((double)VALVE_MIN_POS-(double)VALVE_CENTER); } int16_t PWM_VALVE_ID; @@ -1247,12 +1240,12 @@ int32_t valve_pos_vs_flowrate; valve_pos_vs_flowrate = (int32_t) (JOINT_VEL[canindex]); - int16_t VALVE_POS_VALVE_ID = ID_index_array[canindex] * 10 + (int) DDV_CENTER; + int16_t VALVE_POS_VALVE_ID = ID_index_array[canindex] * 10 + VALVE_CENTER; int16_t temp_valve_pos = 0; - if(VALVE_POS_VALVE_ID>=DDV_CENTER) { - temp_valve_pos = (int16_t) (10000.0f*((double)VALVE_POS_VALVE_ID-(double)DDV_CENTER)/((double)VALVE_MAX_POS-(double)DDV_CENTER)); + if(VALVE_POS_VALVE_ID>=VALVE_CENTER) { + temp_valve_pos = (int16_t) (10000.0f*((double)VALVE_POS_VALVE_ID-(double)VALVE_CENTER)/((double)VALVE_MAX_POS-(double)VALVE_CENTER)); } else { - temp_valve_pos = (int16_t) (-10000.0f*((double)VALVE_POS_VALVE_ID-(double)DDV_CENTER)/((double)VALVE_MIN_POS-(double)DDV_CENTER)); + temp_valve_pos = (int16_t) (-10000.0f*((double)VALVE_POS_VALVE_ID-(double)VALVE_CENTER)/((double)VALVE_MIN_POS-(double)VALVE_CENTER)); } temp_msg.id = CID_TX_INFO; @@ -1358,7 +1351,7 @@ CANMessage temp_msg; temp_msg.id = CID_TX_PRES; - temp_msg.len = 8; + temp_msg.len = 4; temp_msg.data[0] = (uint8_t) t_pres_a; temp_msg.data[1] = (uint8_t) (t_pres_a >> 8); temp_msg.data[2] = (uint8_t) t_pres_b; @@ -1370,8 +1363,8 @@ void CAN_TX_PWM(int16_t t_pwm) { CANMessage temp_msg; - temp_msg.id = CID_TX_POSITION; - temp_msg.len = 8; + temp_msg.id = CID_TX_VOUT; + temp_msg.len = 2; temp_msg.data[0] = (uint8_t) t_pwm; temp_msg.data[1] = (uint8_t) (t_pwm >> 8); @@ -1402,3 +1395,4 @@ +