diff --git a/306-controller_interface.X/app/can_message.c b/306-controller_interface.X/app/can_message.c index 3fa19b1..2075c90 100644 --- a/306-controller_interface.X/app/can_message.c +++ b/306-controller_interface.X/app/can_message.c @@ -9,6 +9,7 @@ #include "car.h" #include "../app/factory/factory.h" #include "../middleware/can_interface.h" +#include "kartculator.h" typedef union { struct { @@ -20,6 +21,14 @@ typedef union { uint32_t full; } BYTES_4; +typedef union { + struct { + uint8_t byte0; + uint8_t byte1; + } separate; + uint16_t full; +} BYTES_2; + void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){ switch(idSender){ @@ -145,6 +154,11 @@ 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); } @@ -182,7 +196,14 @@ 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); } if(idMsg == 0xF) { // DRIVE_ALIVE @@ -199,7 +220,14 @@ 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; } if(idMsg == 0x2) { // STEERING_GET_POSITION @@ -291,7 +319,12 @@ void CM_DRIVE_SETUP(void* p) { void CM_DRIVE_POWER(void* p) { // valH valL - - - // TODO + BYTES_2 torque; + BYTES_4 tmpData; + torque.full = *((int16_t*) p); + tmpData.separate.byte0 = torque.separate.byte1; + tmpData.separate.byte1 = torque.separate.byte0; + CAN_Send(4, 1, tmpData.full); } void CM_STEERING_SETUP(void* p) { diff --git a/306-controller_interface.X/app/can_message.h b/306-controller_interface.X/app/can_message.h index 64bab11..0249c07 100644 --- a/306-controller_interface.X/app/can_message.h +++ b/306-controller_interface.X/app/can_message.h @@ -75,6 +75,10 @@ void CM_DISPLAY_DIRECTION(void* p); */ void CM_DRIVE_SETUP(void* p); +/** + * Send power to the drive + * @param p the torque (int16_t*) + */ void CM_DRIVE_POWER(void* p); /** diff --git a/306-controller_interface.X/app/car.h b/306-controller_interface.X/app/car.h index 5551386..dfea2a5 100644 --- a/306-controller_interface.X/app/car.h +++ b/306-controller_interface.X/app/car.h @@ -69,9 +69,10 @@ typedef struct { KART_CST_TYPE KART_CST; typedef struct { - int32_t speed; - uint32_t center; - uint32_t position; + int16_t torque; // + uint32_t center; // + uint32_t position; // + uint8_t speed; // 100m/h } KART_VAR_TYPE; KART_VAR_TYPE eKart; diff --git a/306-controller_interface.X/app/kartculator.c b/306-controller_interface.X/app/kartculator.c new file mode 100644 index 0000000..deeecae --- /dev/null +++ b/306-controller_interface.X/app/kartculator.c @@ -0,0 +1,39 @@ +/** + * @author Rémi Heredero + * @version. 0.0.0 + * @date August 2023 + * @file kartculator.c + */ + +#include "kartculator.h" + +void calcTorque(uint8_t joy_pos) { + int32_t calcTorque; + calcTorque = 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; +} + +void calcPosition(uint8_t joy_pos){ + int32_t calcPosition; + calcPosition = joy_pos; +} + +void calcSpeed(int32_t rpm) { + +} + +int16_t getTorque() { + +} + +uint32_t getPosition() { + +} + +uint8_t getSpeed() { + +} + + diff --git a/306-controller_interface.X/app/kartculator.h b/306-controller_interface.X/app/kartculator.h new file mode 100644 index 0000000..a2ce5cb --- /dev/null +++ b/306-controller_interface.X/app/kartculator.h @@ -0,0 +1,24 @@ +/** + * @author Rémi Heredero + * @version. 0.0.0 + * @date August 2023 + * @file kartculator.h + */ + +#ifndef KARTCULATOR_H +#define KARTCULATOR_H + +#include // usage of standard types +#include // usage of boolean types +#include "../mcc_generated_files/mcc.h" +#include "car.h" + +void calcTorque(uint8_t joy_pos); +void calcPosition(uint8_t joy_pos); +void calcSpeed(int32_t rpm); +int16_t getTorque(); +uint32_t getPosition(); +uint8_t getSpeed(); + +#endif /* KARTCULATOR_H */ + diff --git a/306-controller_interface.X/middleware/eeprom.c b/306-controller_interface.X/middleware/eeprom.c index 6be123a..874f425 100644 --- a/306-controller_interface.X/middleware/eeprom.c +++ b/306-controller_interface.X/middleware/eeprom.c @@ -25,10 +25,10 @@ void MEM_init(){ KART_CST.CONTROL_STEERING_MODE = 0; KART_CST.CONTROL_ALIVE_TIME = 50; KART_CST.CONTROL_SPEED_FACTOR = 0; - KART_CST.CONTROL_POWER_FACTOR = 0; - KART_CST.CONTROL_STEERING_FACTOR = 0; - KART_CST.CONTROL_MAX_SPEED_FW = 0; - KART_CST.CONTROL_MAX_SPEED_BW = 0; + KART_CST.CONTROL_POWER_FACTOR = 10000; + KART_CST.CONTROL_STEERING_FACTOR = 400000000; + KART_CST.CONTROL_MAX_SPEED_FW = 500; + KART_CST.CONTROL_MAX_SPEED_BW = 250; KART_CST.JOYSTICK_MODE = 0; KART_CST.JOYSTICK_PARAM1 = 5; @@ -37,8 +37,8 @@ void MEM_init(){ KART_CST.DISPLAY_ALIVE_TIME = 100; - KART_CST.DRIVE_SPEED_TIME = 0; - KART_CST.DRIVE_STOP_TIME = 0; + KART_CST.DRIVE_SPEED_TIME = 5; + KART_CST.DRIVE_STOP_TIME = 20; KART_CST.DRIVE_ALIVE_TIME = 10; KART_CST.STEERING_ALIVE_TIME = 100; diff --git a/306-controller_interface.X/nbproject/configurations.xml b/306-controller_interface.X/nbproject/configurations.xml index c01e68d..70c7382 100644 --- a/306-controller_interface.X/nbproject/configurations.xml +++ b/306-controller_interface.X/nbproject/configurations.xml @@ -9,6 +9,7 @@ app/car.h app/can_message.h middleware/eeprom.h + app/kartculator.h board/led/led.h @@ -46,6 +47,7 @@ app/factory/factory.c app/can_message.c middleware/eeprom.c + app/kartculator.c board/led/led.c diff --git a/busmaster_config.cfx b/busmaster_config.cfx index 783a951..67531f2 100644 --- a/busmaster_config.cfx +++ b/busmaster_config.cfx @@ -2,7 +2,7 @@ 3.2.2 - FALSE + TRUE FALSE FALSE FALSE @@ -17,7 +17,7 @@ FALSE SHOWNORMAL - SHOWNORMAL + HIDE 655 0 874 @@ -42,21 +42,21 @@ 90 1 + + + Parameter + 1 + 200 + 1 + + + Channel 1 + 2 + 90 + 1 + + - - - Parameter - 1 - 200 - 1 - - - Channel 1 - 2 - 90 - 1 - - SHOWNORMAL RESTORETOMAXIMIZED @@ -69,7 +69,7 @@ MHS Tiny-CAN - Bus Off + Unknown 250 @@ -125,21 +125,13 @@ - notAlive + noAlive STOP 271 271 - Rx - STD - NONRTR - 0 - - - 799 - 799 ALL - STD + ALL ALL 0 @@ -147,42 +139,6 @@ 543 543 ALL - STD - ALL - 0 - - - 1055 - 1055 - ALL - STD - ALL - 0 - - - 1311 - 1311 - ALL - STD - ALL - 0 - - - - display - PASS - - 306 - 306 - ALL - STD - ALL - 0 - - - 307 - 307 - ALL ALL ALL 0 @@ -196,24 +152,16 @@ 0 - 1585 - 1585 + 1055 + 1055 ALL ALL ALL 0 - 1586 - 1586 - ALL - ALL - ALL - 0 - - - 1587 - 1587 + 1311 + 1311 ALL ALL ALL @@ -240,16 +188,16 @@ 0 - 1055 - 1055 + 1040 + 1040 ALL ALL ALL 0 - 1040 - 1040 + 1055 + 1055 ALL ALL ALL @@ -300,6 +248,66 @@ 0 + + display + PASS + + 306 + 306 + ALL + ALL + ALL + 0 + + + 307 + 307 + ALL + ALL + ALL + 0 + + + 48 + 48 + ALL + ALL + ALL + 0 + + + 799 + 799 + ALL + ALL + ALL + 0 + + + 1585 + 1585 + ALL + ALL + ALL + 0 + + + 1586 + 1586 + ALL + ALL + ALL + 0 + + + 1587 + 1587 + ALL + ALL + ALL + 0 + + joy PASS @@ -328,78 +336,29 @@ 0 - - controller - PASS - - 16 - 16 - ALL - ALL - ALL - 0 - - - 271 - 271 - ALL - ALL - ALL - 0 - - - 17 - 17 - ALL - ALL - ALL - 0 - - - 18 - 18 - ALL - ALL - ALL - 0 - - - 19 - 19 - ALL - ALL - ALL - 0 - - - 20 - 20 - ALL - ALL - ALL - 0 - - - 22 - 22 - ALL - ALL - ALL - 0 - - - 337 - SteeringPosition + 1040 + Speed + + + 321 + Power + + + 320 + resetInit + speedTime + stopTime + aliveTime 336 - SET_CENTER - HOMING RESET ALIVE_TIME + SET_CENTER + HOMING 82 @@ -412,14 +371,14 @@ SHOWNORMAL HIDE - 157 - 596 - 1086 - 387 + 150 + 608 + 1098 + 437 94 - 178 + 94 189 94 @@ -434,10 +393,10 @@ 300 - 87 - 87 - 174 - 87 + 94 + 94 + 189 + 94 @@ -450,10 +409,10 @@ 300 - 87 - 87 - 174 - 87 + 94 + 94 + 189 + 94 @@ -528,10 +487,13 @@ - 2025155376 - 24800128 - 2025155348 - notAlive + 1489464112 + 23901712 + 1489464084 + display + drive + joy + noAlive steering @@ -593,7 +555,7 @@ SYSTEM SHOWNORMAL - RESTORETOMAXIMIZED + SETMINPOSITION 0 0 810 @@ -688,12 +650,12 @@ 720 1 - 0 + 1 0 SYSTEM SHOWNORMAL - RESTORETOMAXIMIZED + SETMINPOSITION 0 0 549 @@ -773,12 +735,12 @@ 734 1 - 0 + 1 0 SYSTEM SHOWNORMAL - RESTORETOMAXIMIZED + SETMINPOSITION 0 0 549 @@ -821,7 +783,7 @@ FALSE FALSE 4 - 0,0,0,50 + 0,1,0,50 10 FALSE a @@ -875,6 +837,30 @@ a FALSE + + 1 + 321 + FALSE + FALSE + 2 + 0,0 + 10 + FALSE + a + FALSE + + + 1 + 320 + FALSE + FALSE + 4 + 1,25,0,0 + 10 + FALSE + a + FALSE +