diff --git a/306-controller_interface.X/app/can_message.c b/306-controller_interface.X/app/can_message.c index 789ec16..9f4010d 100644 --- a/306-controller_interface.X/app/can_message.c +++ b/306-controller_interface.X/app/can_message.c @@ -224,7 +224,12 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, bool rtr, uint32_t data){ if(idMsg == 0xF) { // DISPLAY_ALIVE // powerMode - - - // TODO display say ALIVE - + eKart.powerMode = incomeData.separate.byte0; + if (eKart.powerMode == 0) { + CM_HEADLIGHTS(&ALWAYSFALSE); + } else { + CM_HEADLIGHTS(&ALWAYSTRUE); + } } break; @@ -441,3 +446,9 @@ void CM_SUPPLY_SETUP(void* p) { supply.separate.byte3 = KART_CST.BATTERY_ALIVE_TIME; CAN_Send(6, 0, supply.full); } + +void CM_HEADLIGHTS(void* p) { + // status - - - + bool status = *((bool*) p); + CAN_send_1_byte(0, 4, status); +} diff --git a/306-controller_interface.X/app/can_message.h b/306-controller_interface.X/app/can_message.h index 77fcb77..7d3ac5d 100644 --- a/306-controller_interface.X/app/can_message.h +++ b/306-controller_interface.X/app/can_message.h @@ -88,6 +88,12 @@ void CM_STEERING_SET(void* p); */ void CM_SUPPLY_SETUP(void* p); +/** + * Send headlights on or off + * @param p true if on, false if off; + */ +void CM_HEADLIGHTS(void* p); + #endif /* CAN_MESSAGE_H */ diff --git a/306-controller_interface.X/app/kartculator.c b/306-controller_interface.X/app/kartculator.c index d4137e1..32af8c3 100644 --- a/306-controller_interface.X/app/kartculator.c +++ b/306-controller_interface.X/app/kartculator.c @@ -14,221 +14,227 @@ void deadJoystick(void* p){ void initRamp() { rampTorque[0] = 0; - rampTorque[1] = 2; + rampTorque[1] = 3; rampTorque[2] = 5; rampTorque[3] = 7; - rampTorque[4] = 9; - rampTorque[5] = 11; - rampTorque[6] = 13; - rampTorque[7] = 14; - rampTorque[8] = 16; - rampTorque[9] = 18; - rampTorque[10] = 19; - rampTorque[11] = 21; - rampTorque[12] = 22; - rampTorque[13] = 23; - rampTorque[14] = 24; - rampTorque[15] = 26; - rampTorque[16] = 27; - rampTorque[17] = 28; - rampTorque[18] = 29; - rampTorque[19] = 29; - rampTorque[20] = 30; - rampTorque[21] = 31; - rampTorque[22] = 32; - rampTorque[23] = 32; - rampTorque[24] = 33; - rampTorque[25] = 33; - rampTorque[26] = 34; - rampTorque[27] = 34; - rampTorque[28] = 35; - rampTorque[29] = 35; - rampTorque[30] = 35; - rampTorque[31] = 36; - rampTorque[32] = 36; - rampTorque[33] = 36; - rampTorque[34] = 36; - rampTorque[35] = 37; - rampTorque[36] = 37; - rampTorque[37] = 37; - rampTorque[38] = 37; - rampTorque[39] = 37; - rampTorque[40] = 37; - rampTorque[41] = 37; - rampTorque[42] = 37; - rampTorque[43] = 37; - rampTorque[44] = 37; - rampTorque[45] = 37; - rampTorque[46] = 37; - rampTorque[47] = 37; - rampTorque[48] = 37; - rampTorque[49] = 37; - rampTorque[50] = 38; - rampTorque[51] = 38; - rampTorque[52] = 38; - rampTorque[53] = 38; - rampTorque[54] = 38; - rampTorque[55] = 38; - rampTorque[56] = 38; - rampTorque[57] = 38; - rampTorque[58] = 38; - rampTorque[59] = 39; - rampTorque[60] = 39; - rampTorque[61] = 39; - rampTorque[62] = 39; - rampTorque[63] = 40; - rampTorque[64] = 40; - rampTorque[65] = 41; - rampTorque[66] = 41; - rampTorque[67] = 42; - rampTorque[68] = 42; - rampTorque[69] = 43; - rampTorque[70] = 44; - rampTorque[71] = 44; - rampTorque[72] = 45; - rampTorque[73] = 46; - rampTorque[74] = 47; - rampTorque[75] = 48; - rampTorque[76] = 49; - rampTorque[77] = 50; - rampTorque[78] = 51; - rampTorque[79] = 52; - rampTorque[80] = 54; - rampTorque[81] = 55; - rampTorque[82] = 57; - rampTorque[83] = 58; - rampTorque[84] = 60; - rampTorque[85] = 62; - rampTorque[86] = 64; - rampTorque[87] = 65; - rampTorque[88] = 67; - rampTorque[89] = 70; - rampTorque[90] = 72; - rampTorque[91] = 74; - rampTorque[92] = 77; - rampTorque[93] = 79; - rampTorque[94] = 82; - rampTorque[95] = 85; - rampTorque[96] = 87; - rampTorque[97] = 90; - rampTorque[98] = 93; - rampTorque[99] = 97; + rampTorque[4] = 10; + rampTorque[5] = 12; + rampTorque[6] = 14; + rampTorque[7] = 16; + rampTorque[8] = 18; + rampTorque[9] = 20; + rampTorque[10] = 22; + rampTorque[11] = 24; + rampTorque[12] = 25; + rampTorque[13] = 27; + rampTorque[14] = 28; + rampTorque[15] = 30; + rampTorque[16] = 31; + rampTorque[17] = 33; + rampTorque[18] = 34; + rampTorque[19] = 36; + rampTorque[20] = 37; + rampTorque[21] = 38; + rampTorque[22] = 39; + rampTorque[23] = 40; + rampTorque[24] = 41; + rampTorque[25] = 42; + rampTorque[26] = 43; + rampTorque[27] = 44; + rampTorque[28] = 45; + rampTorque[29] = 46; + rampTorque[30] = 47; + rampTorque[31] = 47; + rampTorque[32] = 48; + rampTorque[33] = 49; + rampTorque[34] = 50; + rampTorque[35] = 50; + rampTorque[36] = 51; + rampTorque[37] = 51; + rampTorque[38] = 52; + rampTorque[39] = 53; + rampTorque[40] = 53; + rampTorque[41] = 53; + rampTorque[42] = 54; + rampTorque[43] = 54; + rampTorque[44] = 55; + rampTorque[45] = 55; + rampTorque[46] = 56; + rampTorque[47] = 56; + rampTorque[48] = 56; + rampTorque[49] = 57; + rampTorque[50] = 57; + rampTorque[51] = 58; + rampTorque[52] = 58; + rampTorque[53] = 58; + rampTorque[54] = 59; + rampTorque[55] = 59; + rampTorque[56] = 59; + rampTorque[57] = 60; + rampTorque[58] = 60; + rampTorque[59] = 60; + rampTorque[60] = 61; + rampTorque[61] = 61; + rampTorque[62] = 62; + rampTorque[63] = 62; + rampTorque[64] = 62; + rampTorque[65] = 63; + rampTorque[66] = 63; + rampTorque[67] = 64; + rampTorque[68] = 64; + rampTorque[69] = 65; + rampTorque[70] = 65; + rampTorque[71] = 66; + rampTorque[72] = 67; + rampTorque[73] = 67; + rampTorque[74] = 68; + rampTorque[75] = 69; + rampTorque[76] = 69; + rampTorque[77] = 70; + rampTorque[78] = 71; + rampTorque[79] = 72; + rampTorque[80] = 72; + rampTorque[81] = 73; + rampTorque[82] = 74; + rampTorque[83] = 75; + rampTorque[84] = 76; + rampTorque[85] = 77; + rampTorque[86] = 78; + rampTorque[87] = 80; + rampTorque[88] = 81; + rampTorque[89] = 82; + rampTorque[90] = 83; + rampTorque[91] = 85; + rampTorque[92] = 86; + rampTorque[93] = 88; + rampTorque[94] = 89; + rampTorque[95] = 91; + rampTorque[96] = 93; + rampTorque[97] = 94; + rampTorque[98] = 96; + rampTorque[99] = 98; rampTorque[100] = 100; rampPosition[0] = 0; rampPosition[1] = 0; - rampPosition[2] = 1; - rampPosition[3] = 1; - rampPosition[4] = 1; + rampPosition[2] = 0; + rampPosition[3] = 0; + rampPosition[4] = 0; rampPosition[5] = 1; - rampPosition[6] = 2; - rampPosition[7] = 2; + rampPosition[6] = 1; + rampPosition[7] = 1; rampPosition[8] = 2; - rampPosition[9] = 3; + rampPosition[9] = 2; rampPosition[10] = 3; - rampPosition[11] = 4; + rampPosition[11] = 3; rampPosition[12] = 4; - rampPosition[13] = 4; + rampPosition[13] = 5; rampPosition[14] = 5; - rampPosition[15] = 5; - rampPosition[16] = 6; - rampPosition[17] = 6; - rampPosition[18] = 7; - rampPosition[19] = 7; - rampPosition[20] = 8; - rampPosition[21] = 8; - rampPosition[22] = 9; - rampPosition[23] = 9; - rampPosition[24] = 10; - rampPosition[25] = 11; - rampPosition[26] = 11; - rampPosition[27] = 12; - rampPosition[28] = 13; - rampPosition[29] = 13; - rampPosition[30] = 14; - rampPosition[31] = 15; - rampPosition[32] = 15; - rampPosition[33] = 16; - rampPosition[34] = 17; - rampPosition[35] = 18; - rampPosition[36] = 18; - rampPosition[37] = 19; - rampPosition[38] = 20; - rampPosition[39] = 21; - rampPosition[40] = 22; - rampPosition[41] = 23; - rampPosition[42] = 23; - rampPosition[43] = 24; - rampPosition[44] = 25; - rampPosition[45] = 26; - rampPosition[46] = 27; - rampPosition[47] = 28; - rampPosition[48] = 29; - rampPosition[49] = 30; - rampPosition[50] = 31; - rampPosition[51] = 32; - rampPosition[52] = 33; - rampPosition[53] = 34; - rampPosition[54] = 35; - rampPosition[55] = 36; - rampPosition[56] = 37; - rampPosition[57] = 38; - rampPosition[58] = 39; - rampPosition[59] = 41; - rampPosition[60] = 42; - rampPosition[61] = 43; - rampPosition[62] = 44; - rampPosition[63] = 45; - rampPosition[64] = 46; - rampPosition[65] = 48; - rampPosition[66] = 49; - rampPosition[67] = 50; - rampPosition[68] = 51; - rampPosition[69] = 53; - rampPosition[70] = 54; - rampPosition[71] = 55; - rampPosition[72] = 57; - rampPosition[73] = 58; - rampPosition[74] = 59; - rampPosition[75] = 61; - rampPosition[76] = 62; - rampPosition[77] = 63; - rampPosition[78] = 65; - rampPosition[79] = 66; - rampPosition[80] = 68; - rampPosition[81] = 69; - rampPosition[82] = 71; - rampPosition[83] = 72; - rampPosition[84] = 74; - rampPosition[85] = 75; - rampPosition[86] = 77; - rampPosition[87] = 78; - rampPosition[88] = 80; - rampPosition[89] = 82; - rampPosition[90] = 83; - rampPosition[91] = 85; - rampPosition[92] = 86; - rampPosition[93] = 88; - rampPosition[94] = 90; - rampPosition[95] = 91; - rampPosition[96] = 93; - rampPosition[97] = 95; - rampPosition[98] = 97; - rampPosition[99] = 98; + rampPosition[15] = 6; + rampPosition[16] = 7; + rampPosition[17] = 8; + rampPosition[18] = 9; + rampPosition[19] = 9; + rampPosition[20] = 10; + rampPosition[21] = 11; + rampPosition[22] = 12; + rampPosition[23] = 13; + rampPosition[24] = 15; + rampPosition[25] = 16; + rampPosition[26] = 17; + rampPosition[27] = 18; + rampPosition[28] = 19; + rampPosition[29] = 20; + rampPosition[30] = 22; + rampPosition[31] = 23; + rampPosition[32] = 24; + rampPosition[33] = 25; + rampPosition[34] = 27; + rampPosition[35] = 28; + rampPosition[36] = 30; + rampPosition[37] = 31; + rampPosition[38] = 32; + rampPosition[39] = 34; + rampPosition[40] = 35; + rampPosition[41] = 37; + rampPosition[42] = 38; + rampPosition[43] = 40; + rampPosition[44] = 41; + rampPosition[45] = 43; + rampPosition[46] = 44; + rampPosition[47] = 46; + rampPosition[48] = 47; + rampPosition[49] = 49; + rampPosition[50] = 50; + rampPosition[51] = 51; + rampPosition[52] = 53; + rampPosition[53] = 54; + rampPosition[54] = 56; + rampPosition[55] = 57; + rampPosition[56] = 59; + rampPosition[57] = 60; + rampPosition[58] = 62; + rampPosition[59] = 63; + rampPosition[60] = 65; + rampPosition[61] = 66; + rampPosition[62] = 68; + rampPosition[63] = 69; + rampPosition[64] = 70; + rampPosition[65] = 72; + rampPosition[66] = 73; + rampPosition[67] = 75; + rampPosition[68] = 76; + rampPosition[69] = 77; + rampPosition[70] = 78; + rampPosition[71] = 80; + rampPosition[72] = 81; + rampPosition[73] = 82; + rampPosition[74] = 83; + rampPosition[75] = 84; + rampPosition[76] = 85; + rampPosition[77] = 87; + rampPosition[78] = 88; + rampPosition[79] = 89; + rampPosition[80] = 90; + rampPosition[81] = 91; + rampPosition[82] = 91; + rampPosition[83] = 92; + rampPosition[84] = 93; + rampPosition[85] = 94; + rampPosition[86] = 95; + rampPosition[87] = 95; + rampPosition[88] = 96; + rampPosition[89] = 97; + rampPosition[90] = 97; + rampPosition[91] = 98; + rampPosition[92] = 98; + rampPosition[93] = 99; + rampPosition[94] = 99; + rampPosition[95] = 99; + rampPosition[96] = 100; + rampPosition[97] = 100; + rampPosition[98] = 100; + rampPosition[99] = 100; rampPosition[100] = 100; + } void calcTorque(uint8_t joy_pos) { int32_t calcTorque; calcTorque = (int8_t) joy_pos; // joystick position - if(joy_pos >= 0) { - calcTorque = rampTorque[joy_pos]; - } else { - joy_pos *= -1; - calcTorque = rampTorque[joy_pos]; - calcTorque *= -1; + + // if mode race, use special curve for torque + if(eKart.powerMode == 2) { + if(calcTorque >= 0) { + calcTorque = rampTorque[calcTorque]; + } else { + calcTorque *= -1; + calcTorque = rampTorque[calcTorque]; + calcTorque *= -1; + } } + calcTorque *= KART_CST.CONTROL_POWER_FACTOR; // convert by power factor calcTorque /= 1000; // torque define by joystick eKart.torque = (int16_t) calcTorque; @@ -238,13 +244,18 @@ void calcPosition(uint8_t joy_pos){ int32_t calcPosition; calcPosition = (int8_t) joy_pos; calcPosition *= -1; // change left and right - if(joy_pos >= 0) { - calcPosition = rampPosition[joy_pos]; - } else { - joy_pos *= -1; - calcPosition = rampPosition[joy_pos]; - rampPosition *= -1; + + // if mode race, use special curve for steering + if (eKart.powerMode == 2) { + if(calcPosition >= 0) { + calcPosition = rampPosition[calcPosition]; + } else { + calcPosition *= -1; + calcPosition = rampPosition[calcPosition]; + calcPosition *= -1; + } } + calcPosition *= (int32_t) KART_CST.CONTROL_STEERING_FACTOR; calcPosition /= 1000; calcPosition += eKart.center;