add kartculator

This commit is contained in:
Rémi Heredero 2023-08-31 13:42:31 +02:00
parent 00130b03ee
commit dc6e4ec65a
8 changed files with 267 additions and 178 deletions

View File

@ -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) {

View File

@ -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);
/**

View File

@ -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;

View File

@ -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() {
}

View File

@ -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 <stdint.h> // usage of standard types
#include <stdbool.h> // 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 */

View File

@ -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;

View File

@ -9,6 +9,7 @@
<itemPath>app/car.h</itemPath>
<itemPath>app/can_message.h</itemPath>
<itemPath>middleware/eeprom.h</itemPath>
<itemPath>app/kartculator.h</itemPath>
</logicalFolder>
<logicalFolder name="board" displayName="board" projectFiles="true">
<itemPath>board/led/led.h</itemPath>
@ -46,6 +47,7 @@
<itemPath>app/factory/factory.c</itemPath>
<itemPath>app/can_message.c</itemPath>
<itemPath>middleware/eeprom.c</itemPath>
<itemPath>app/kartculator.c</itemPath>
</logicalFolder>
<logicalFolder name="board" displayName="board" projectFiles="true">
<itemPath>board/led/led.c</itemPath>

View File

@ -2,7 +2,7 @@
<BUSMASTER_CONFIGURATION>
<Global_Configuration>
<BUSMASTER_Version>3.2.2</BUSMASTER_Version>
<IsMsgFilterEnabled>FALSE</IsMsgFilterEnabled>
<IsMsgFilterEnabled>TRUE</IsMsgFilterEnabled>
<IsMsgFilterEnabledLin>FALSE</IsMsgFilterEnabledLin>
<IsReplayFilterEnabled>FALSE</IsReplayFilterEnabled>
<IsLogFilterEnabled>FALSE</IsLogFilterEnabled>
@ -17,7 +17,7 @@
<LogOnConnect_LIN>FALSE</LogOnConnect_LIN>
<Window_Position>
<Visibility>SHOWNORMAL</Visibility>
<WindowPlacement>SHOWNORMAL</WindowPlacement>
<WindowPlacement>HIDE</WindowPlacement>
<Top>655</Top>
<Left>0</Left>
<Bottom>874</Bottom>
@ -42,21 +42,21 @@
<Width>90</Width>
<IsVisible>1</IsVisible>
</COLUMN>
<LIN_Statistics>
<COLUMN>
<ID>Parameter</ID>
<Order>1</Order>
<Width>200</Width>
<IsVisible>1</IsVisible>
</COLUMN>
<COLUMN>
<ID>Channel 1</ID>
<Order>2</Order>
<Width>90</Width>
<IsVisible>1</IsVisible>
</COLUMN>
</LIN_Statistics>
</CAN_Statistics>
<LIN_Statistics>
<COLUMN>
<ID>Parameter</ID>
<Order>1</Order>
<Width>200</Width>
<IsVisible>1</IsVisible>
</COLUMN>
<COLUMN>
<ID>Channel 1</ID>
<Order>2</Order>
<Width>90</Width>
<IsVisible>1</IsVisible>
</COLUMN>
</LIN_Statistics>
<Window_Position>
<Visibility>SHOWNORMAL</Visibility>
<WindowPlacement>RESTORETOMAXIMIZED</WindowPlacement>
@ -69,7 +69,7 @@
<J1939_Database_Files/>
<CAN_DIL_Section>
<DriverName>MHS Tiny-CAN</DriverName>
<ControllerMode>Bus Off</ControllerMode>
<ControllerMode>Unknown</ControllerMode>
<ControllerSettings>
<Channel>
<BaudRate>250</BaudRate>
@ -125,21 +125,13 @@
</CAN_DIL_Section>
<CAN_Filters>
<Filter>
<Name>notAlive</Name>
<Name>noAlive</Name>
<Type>STOP</Type>
<FilterMessage>
<IdFrom>271</IdFrom>
<IdTo>271</IdTo>
<Direction>Rx</Direction>
<IDType>STD</IDType>
<MsgType>NONRTR</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>799</IdFrom>
<IdTo>799</IdTo>
<Direction>ALL</Direction>
<IDType>STD</IDType>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
@ -147,42 +139,6 @@
<IdFrom>543</IdFrom>
<IdTo>543</IdTo>
<Direction>ALL</Direction>
<IDType>STD</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>1055</IdFrom>
<IdTo>1055</IdTo>
<Direction>ALL</Direction>
<IDType>STD</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>1311</IdFrom>
<IdTo>1311</IdTo>
<Direction>ALL</Direction>
<IDType>STD</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
</Filter>
<Filter>
<Name>display</Name>
<Type>PASS</Type>
<FilterMessage>
<IdFrom>306</IdFrom>
<IdTo>306</IdTo>
<Direction>ALL</Direction>
<IDType>STD</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>307</IdFrom>
<IdTo>307</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
@ -196,24 +152,16 @@
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>1585</IdFrom>
<IdTo>1585</IdTo>
<IdFrom>1055</IdFrom>
<IdTo>1055</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>1586</IdFrom>
<IdTo>1586</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>1587</IdFrom>
<IdTo>1587</IdTo>
<IdFrom>1311</IdFrom>
<IdTo>1311</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
@ -240,16 +188,16 @@
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>1055</IdFrom>
<IdTo>1055</IdTo>
<IdFrom>1040</IdFrom>
<IdTo>1040</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>1040</IdFrom>
<IdTo>1040</IdTo>
<IdFrom>1055</IdFrom>
<IdTo>1055</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
@ -300,6 +248,66 @@
<Channel>0</Channel>
</FilterMessage>
</Filter>
<Filter>
<Name>display</Name>
<Type>PASS</Type>
<FilterMessage>
<IdFrom>306</IdFrom>
<IdTo>306</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>307</IdFrom>
<IdTo>307</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>48</IdFrom>
<IdTo>48</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>799</IdFrom>
<IdTo>799</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>1585</IdFrom>
<IdTo>1585</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>1586</IdFrom>
<IdTo>1586</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>1587</IdFrom>
<IdTo>1587</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
</Filter>
<Filter>
<Name>joy</Name>
<Type>PASS</Type>
@ -328,78 +336,29 @@
<Channel>0</Channel>
</FilterMessage>
</Filter>
<Filter>
<Name>controller</Name>
<Type>PASS</Type>
<FilterMessage>
<IdFrom>16</IdFrom>
<IdTo>16</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>271</IdFrom>
<IdTo>271</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>17</IdFrom>
<IdTo>17</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>18</IdFrom>
<IdTo>18</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>19</IdFrom>
<IdTo>19</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>20</IdFrom>
<IdTo>20</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
<FilterMessage>
<IdFrom>22</IdFrom>
<IdTo>22</IdTo>
<Direction>ALL</Direction>
<IDType>ALL</IDType>
<MsgType>ALL</MsgType>
<Channel>0</Channel>
</FilterMessage>
</Filter>
</CAN_Filters>
<CAN_Signal_Watch>
<Message>
<Id>337</Id>
<Signal>SteeringPosition</Signal>
<Id>1040</Id>
<Signal>Speed</Signal>
</Message>
<Message>
<Id>321</Id>
<Signal>Power</Signal>
</Message>
<Message>
<Id>320</Id>
<Signal>resetInit</Signal>
<Signal>speedTime</Signal>
<Signal>stopTime</Signal>
<Signal>aliveTime</Signal>
</Message>
<Message>
<Id>336</Id>
<Signal>SET_CENTER</Signal>
<Signal>HOMING</Signal>
<Signal>RESET</Signal>
<Signal>ALIVE_TIME</Signal>
<Signal>SET_CENTER</Signal>
<Signal>HOMING</Signal>
</Message>
<Message>
<Id>82</Id>
@ -412,14 +371,14 @@
<Window_Position>
<Visibility>SHOWNORMAL</Visibility>
<WindowPlacement>HIDE</WindowPlacement>
<Top>157</Top>
<Left>596</Left>
<Right>1086</Right>
<Bottom>387</Bottom>
<Top>150</Top>
<Left>608</Left>
<Right>1098</Right>
<Bottom>437</Bottom>
</Window_Position>
<COLUMN_WIDTH>
<MESSAGE_COLUMN>94</MESSAGE_COLUMN>
<Raw_Val_Column>178</Raw_Val_Column>
<Raw_Val_Column>94</Raw_Val_Column>
<Physical_Val_Column>189</Physical_Val_Column>
<Signal_Column>94</Signal_Column>
</COLUMN_WIDTH>
@ -434,10 +393,10 @@
<Bottom>300</Bottom>
</Window_Position>
<COLUMN_WIDTH>
<MESSAGE_COLUMN>87</MESSAGE_COLUMN>
<Raw_Val_Column>87</Raw_Val_Column>
<Physical_Val_Column>174</Physical_Val_Column>
<Signal_Column>87</Signal_Column>
<MESSAGE_COLUMN>94</MESSAGE_COLUMN>
<Raw_Val_Column>94</Raw_Val_Column>
<Physical_Val_Column>189</Physical_Val_Column>
<Signal_Column>94</Signal_Column>
</COLUMN_WIDTH>
</J1939_Signal_Watch>
<LIN_Signal_Watch>
@ -450,10 +409,10 @@
<Bottom>300</Bottom>
</Window_Position>
<COLUMN_WIDTH>
<MESSAGE_COLUMN>87</MESSAGE_COLUMN>
<Raw_Val_Column>87</Raw_Val_Column>
<Physical_Val_Column>174</Physical_Val_Column>
<Signal_Column>87</Signal_Column>
<MESSAGE_COLUMN>94</MESSAGE_COLUMN>
<Raw_Val_Column>94</Raw_Val_Column>
<Physical_Val_Column>189</Physical_Val_Column>
<Signal_Column>94</Signal_Column>
</COLUMN_WIDTH>
</LIN_Signal_Watch>
<CAN_Signal_Graph>
@ -528,10 +487,13 @@
</J1939_Simulated_Systems>
<CAN_Replay/>
<CAN_Message_Window>
<Append_Buffer_Size>2025155376</Append_Buffer_Size>
<Overwrite_Buffer_Size>24800128</Overwrite_Buffer_Size>
<Display_Update_Time>2025155348</Display_Update_Time>
<Filter IsEnabled="0">notAlive</Filter>
<Append_Buffer_Size>1489464112</Append_Buffer_Size>
<Overwrite_Buffer_Size>23901712</Overwrite_Buffer_Size>
<Display_Update_Time>1489464084</Display_Update_Time>
<Filter IsEnabled="0">display</Filter>
<Filter IsEnabled="0">drive</Filter>
<Filter IsEnabled="1">joy</Filter>
<Filter IsEnabled="1">noAlive</Filter>
<Filter IsEnabled="0">steering</Filter>
<COLUMN>
<ID/>
@ -593,7 +555,7 @@
<Time_Mode>SYSTEM</Time_Mode>
<Window_Position>
<Visibility>SHOWNORMAL</Visibility>
<WindowPlacement>RESTORETOMAXIMIZED</WindowPlacement>
<WindowPlacement>SETMINPOSITION</WindowPlacement>
<Top>0</Top>
<Left>0</Left>
<Bottom>810</Bottom>
@ -688,12 +650,12 @@
<Width>720</Width>
</COLUMN>
<IsHex>1</IsHex>
<IsAppend>0</IsAppend>
<IsAppend>1</IsAppend>
<IsInterpret>0</IsInterpret>
<Time_Mode>SYSTEM</Time_Mode>
<Window_Position>
<Visibility>SHOWNORMAL</Visibility>
<WindowPlacement>RESTORETOMAXIMIZED</WindowPlacement>
<WindowPlacement>SETMINPOSITION</WindowPlacement>
<Top>0</Top>
<Left>0</Left>
<Bottom>549</Bottom>
@ -773,12 +735,12 @@
<Width>734</Width>
</COLUMN>
<IsHex>1</IsHex>
<IsAppend>0</IsAppend>
<IsAppend>1</IsAppend>
<IsInterpret>0</IsInterpret>
<Time_Mode>SYSTEM</Time_Mode>
<Window_Position>
<Visibility>SHOWNORMAL</Visibility>
<WindowPlacement>RESTORETOMAXIMIZED</WindowPlacement>
<WindowPlacement>SETMINPOSITION</WindowPlacement>
<Top>0</Top>
<Left>0</Left>
<Bottom>549</Bottom>
@ -821,7 +783,7 @@
<IsExtended>FALSE</IsExtended>
<IsRtr>FALSE</IsRtr>
<DLC>4</DLC>
<DataBytes>0,0,0,50</DataBytes>
<DataBytes>0,1,0,50</DataBytes>
<Repetion>10</Repetion>
<Repetition_Enabled>FALSE</Repetition_Enabled>
<Key_Value>a</Key_Value>
@ -875,6 +837,30 @@
<Key_Value>a</Key_Value>
<Key_Enabled>FALSE</Key_Enabled>
</Message>
<Message>
<Channel>1</Channel>
<Message_ID>321</Message_ID>
<IsExtended>FALSE</IsExtended>
<IsRtr>FALSE</IsRtr>
<DLC>2</DLC>
<DataBytes>0,0</DataBytes>
<Repetion>10</Repetion>
<Repetition_Enabled>FALSE</Repetition_Enabled>
<Key_Value>a</Key_Value>
<Key_Enabled>FALSE</Key_Enabled>
</Message>
<Message>
<Channel>1</Channel>
<Message_ID>320</Message_ID>
<IsExtended>FALSE</IsExtended>
<IsRtr>FALSE</IsRtr>
<DLC>4</DLC>
<DataBytes>1,25,0,0</DataBytes>
<Repetion>10</Repetion>
<Repetition_Enabled>FALSE</Repetition_Enabled>
<Key_Value>a</Key_Value>
<Key_Enabled>FALSE</Key_Enabled>
</Message>
</Message_List>
</CAN_Tx_Window>
<CAN_Wave_Form_Genarator>