add kartculator
This commit is contained in:
@ -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) {
|
||||
|
@ -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);
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
||||
|
39
306-controller_interface.X/app/kartculator.c
Normal file
39
306-controller_interface.X/app/kartculator.c
Normal 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() {
|
||||
|
||||
}
|
||||
|
||||
|
24
306-controller_interface.X/app/kartculator.h
Normal file
24
306-controller_interface.X/app/kartculator.h
Normal 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 */
|
||||
|
@ -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;
|
||||
|
@ -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>
|
||||
|
Reference in New Issue
Block a user