diff --git a/306-controller_interface.X/app/can_message.c b/306-controller_interface.X/app/can_message.c index e32b8b2..c348e70 100644 --- a/306-controller_interface.X/app/can_message.c +++ b/306-controller_interface.X/app/can_message.c @@ -21,6 +21,8 @@ typedef union { uint32_t full; } BYTES_4; +//BYTES_4 foobar; + typedef union { struct { uint8_t byte0; @@ -30,7 +32,16 @@ typedef union { } BYTES_2; void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){ + BYTES_4 incomeData; + incomeData.full = data; + BYTES_4 revertData; + revertData.separate.byte0 = incomeData.separate.byte3; + revertData.separate.byte1 = incomeData.separate.byte2; + revertData.separate.byte2 = incomeData.separate.byte1; + revertData.separate.byte3 = incomeData.separate.byte0; + switch(idSender){ + //foobar.full = data; /********************* * BROADCAST / DEBUG * @@ -38,13 +49,11 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){ case 0: if(idMsg == 0x0) { // CONTROL_SETUP // steeringMode eraseMemory - controlAliveTime - BYTES_4 tmpData; - tmpData.full = data; - if (tmpData.separate.byte1) { + if (incomeData.separate.byte1) { MEM_reset(); } - KART_CST.CONTROL_STEERING_MODE = tmpData.separate.byte0; - KART_CST.CONTROL_ALIVE_TIME = tmpData.separate.byte3; + KART_CST.CONTROL_STEERING_MODE = incomeData.separate.byte0; + KART_CST.CONTROL_ALIVE_TIME = incomeData.separate.byte3; MEM_write_1_byte(MEMADD_CONTROL_STEERING_MODE, KART_CST.CONTROL_STEERING_MODE); MEM_write_1_byte(MEMADD_CONTROL_ALIVE_TIME, KART_CST.CONTROL_ALIVE_TIME); ALIVE_setAliveTime(ALcontroller(), KART_CST.CONTROL_ALIVE_TIME); @@ -73,10 +82,8 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){ if(idMsg == 0x4) { // CONTROL_SECURITY_PARAM // maxSpeedFw maxSpeedBw - - - BYTES_4 tmpData; - tmpData.full = data; - KART_CST.CONTROL_MAX_SPEED_FW = tmpData.separate.byte0; - KART_CST.CONTROL_MAX_SPEED_BW = tmpData.separate.byte1; + KART_CST.CONTROL_MAX_SPEED_FW = incomeData.separate.byte0; + KART_CST.CONTROL_MAX_SPEED_BW = incomeData.separate.byte1; MEM_write_1_byte(MEMADD_CONTROL_MAX_SPEED_FW, KART_CST.CONTROL_MAX_SPEED_FW); MEM_write_1_byte(MEMADD_CONTROL_MAX_SPEED_BW, KART_CST.CONTROL_MAX_SPEED_BW); @@ -84,10 +91,8 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){ if(idMsg == 0x5) { // CONTROL_SETUP_PARAM // displayAliveTime steeringAliveTime - - - BYTES_4 tmpData; - tmpData.full = data; - KART_CST.DISPLAY_ALIVE_TIME = tmpData.separate.byte0; - KART_CST.STEERING_ALIVE_TIME = tmpData.separate.byte1; + KART_CST.DISPLAY_ALIVE_TIME = incomeData.separate.byte0; + KART_CST.STEERING_ALIVE_TIME = incomeData.separate.byte1; MEM_write_1_byte(MEMADD_DISPLAY_ALIVE_TIME, KART_CST.DISPLAY_ALIVE_TIME); MEM_write_1_byte(MEMADD_STEERING_ALIVE_TIME, KART_CST.STEERING_ALIVE_TIME); // TODO set alive times @@ -97,12 +102,10 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){ if(idMsg == 0x6) { // CONTROL_SETUP_PARAM_JOY // joystickMode joystickParam1 joystickParam2 joystickAliveTime - BYTES_4 tmpData; - tmpData.full = data; - KART_CST.JOYSTICK_MODE = tmpData.separate.byte0; - KART_CST.JOYSTICK_PARAM1 = tmpData.separate.byte1; - KART_CST.JOYSTICK_PARAM2 = tmpData.separate.byte2; - KART_CST.JOYSTICK_ALIVE_TIME = tmpData.separate.byte3; + KART_CST.JOYSTICK_MODE = incomeData.separate.byte0; + KART_CST.JOYSTICK_PARAM1 = incomeData.separate.byte1; + KART_CST.JOYSTICK_PARAM2 = incomeData.separate.byte2; + KART_CST.JOYSTICK_ALIVE_TIME = incomeData.separate.byte3; MEM_write_1_byte(MEMADD_JOYSTICK_MODE, KART_CST.JOYSTICK_MODE); MEM_write_1_byte(MEMADD_JOYSTICK_PARAM1, KART_CST.JOYSTICK_PARAM1); MEM_write_1_byte(MEMADD_JOYSTICK_PARAM2, KART_CST.JOYSTICK_PARAM2); @@ -115,11 +118,9 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){ if(idMsg == 0x7) { // CONTROL_SETUP_PARAM_DRIVE // driveAliveTime driveSpeedTime driveStopTime - - BYTES_4 tmpData; - tmpData.full = data; - KART_CST.DRIVE_ALIVE_TIME = tmpData.separate.byte0; - KART_CST.DRIVE_SPEED_TIME = tmpData.separate.byte1; - KART_CST.DRIVE_STOP_TIME = tmpData.separate.byte2; + KART_CST.DRIVE_ALIVE_TIME = incomeData.separate.byte0; + KART_CST.DRIVE_SPEED_TIME = incomeData.separate.byte1; + KART_CST.DRIVE_STOP_TIME = incomeData.separate.byte2; MEM_write_1_byte(MEMADD_DRIVE_ALIVE_TIME, KART_CST.DRIVE_ALIVE_TIME); MEM_write_1_byte(MEMADD_DRIVE_SPEED_TIME, KART_CST.DRIVE_SPEED_TIME); MEM_write_1_byte(MEMADD_DRIVE_STOP_TIME, KART_CST.DRIVE_STOP_TIME); @@ -130,12 +131,10 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){ if(idMsg == 0x8) { // CONTROL_SETUP_PARAM_BATTERY // batteryVoltTime batteryCurrentTime batteryEnergyTime batteryAliveTime - BYTES_4 tmpData; - tmpData.full = data; - KART_CST.BATTERY_VOLT_TIME = tmpData.separate.byte0; - KART_CST.BATTERY_CURRENT_TIME = tmpData.separate.byte1; - KART_CST.BATTERY_ENERGY_TIME = tmpData.separate.byte2; - KART_CST.BATTERY_ALIVE_TIME = tmpData.separate.byte3; + KART_CST.BATTERY_VOLT_TIME = incomeData.separate.byte0; + KART_CST.BATTERY_CURRENT_TIME = incomeData.separate.byte1; + KART_CST.BATTERY_ENERGY_TIME = incomeData.separate.byte2; + KART_CST.BATTERY_ALIVE_TIME = incomeData.separate.byte3; MEM_write_1_byte(MEMADD_BATTERY_VOLT_TIME, KART_CST.BATTERY_VOLT_TIME); MEM_write_1_byte(MEMADD_BATTERY_CURRENT_TIME, KART_CST.BATTERY_CURRENT_TIME); MEM_write_1_byte(MEMADD_BATTERY_ENERGY_TIME, KART_CST.BATTERY_ENERGY_TIME); @@ -154,11 +153,8 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){ case 2: if(idMsg == 0x1) { // JOY_MESURE // posX posY button - - BYTES_4 tmpData; - tmpData.full = data; - - calcTorque(tmpData.separate.byte1); - calcPosition(tmpData.separate.byte0); + calcTorque(incomeData.separate.byte1); + calcPosition(incomeData.separate.byte0); } @@ -197,14 +193,7 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){ case 4: if(idMsg == 0x0) { // DRIVE_SPEED // speedHH speedH speedL speedLL - BYTES_4 tmpData; - tmpData.full = data; - BYTES_4 rpm; - rpm.separate.byte0 = tmpData.separate.byte3; - rpm.separate.byte1 = tmpData.separate.byte2; - rpm.separate.byte2 = tmpData.separate.byte1; - rpm.separate.byte3 = tmpData.separate.byte0; - calcSpeed(rpm.full); + calcSpeed(revertData.full); DRIVE_emitPollSpeed(drive()); } @@ -230,14 +219,7 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){ case 5: if(idMsg == 0x1) { // STEERING_GET_CENTER // valHH valH valL valLL - BYTES_4 tmpData; - tmpData.full = data; - BYTES_4 center; - center.separate.byte0 = tmpData.separate.byte3; - center.separate.byte1 = tmpData.separate.byte2; - center.separate.byte2 = tmpData.separate.byte1; - center.separate.byte3 = tmpData.separate.byte0; - eKart.center = center.full; + eKart.center = revertData.full; } if(idMsg == 0x2) { // STEERING_GET_POSITION diff --git a/306-controller_interface.X/app/kartculator.c b/306-controller_interface.X/app/kartculator.c index deeecae..3b271b5 100644 --- a/306-controller_interface.X/app/kartculator.c +++ b/306-controller_interface.X/app/kartculator.c @@ -9,7 +9,7 @@ void calcTorque(uint8_t joy_pos) { int32_t calcTorque; - calcTorque = joy_pos; // joystick position + calcTorque = (int8_t) joy_pos; // joystick position calcTorque *= KART_CST.CONTROL_POWER_FACTOR; // convert by power factor calcTorque /= 1000; // torque define by joystick eKart.torque = (int16_t) calcTorque; @@ -17,7 +17,7 @@ void calcTorque(uint8_t joy_pos) { void calcPosition(uint8_t joy_pos){ int32_t calcPosition; - calcPosition = joy_pos; + calcPosition = (int8_t) joy_pos; } void calcSpeed(int32_t rpm) {