From d654443621b4770e5178bd4c02ec1593a3fc5644 Mon Sep 17 00:00:00 2001 From: Valentin Dabstep Date: Mon, 26 May 2025 22:40:53 +0300 Subject: [PATCH] Fix cpp file --- controller/fw/embed/include/process_can.h | 1 + controller/fw/embed/platformio.ini | 4 +--- controller/fw/embed/src/main.cpp | 8 ++++---- controller/fw/embed/src/process_can.cpp | 13 ++++++------- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/controller/fw/embed/include/process_can.h b/controller/fw/embed/include/process_can.h index 377414d..90e4c66 100644 --- a/controller/fw/embed/include/process_can.h +++ b/controller/fw/embed/include/process_can.h @@ -18,6 +18,7 @@ void send_motor_enabled(); void send_motor_enabled(); void send_id(); void firmware_update(); +void send_pid_angle(uint8_t param_pid); // void send_motor_torque(); void send_pid(uint8_t param_pid); void setup_id(uint8_t my_id); diff --git a/controller/fw/embed/platformio.ini b/controller/fw/embed/platformio.ini index 93e6ac0..bc4316d 100644 --- a/controller/fw/embed/platformio.ini +++ b/controller/fw/embed/platformio.ini @@ -23,9 +23,7 @@ build_flags = -DSTM32F446xx -D HAL_CAN_MODULE_ENABLED -D SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH - -Wl,-T"${platformio.packages_dir}/framework-arduinoststm32/variants/STM32F4xx/F446R(C-E)T/ldscript.ld" - -Wl,--defsym=LD_FLASH_OFFSET=0x8000 - -DAPP_OFFSET=0x8000 + lib_deps = askuric/Simple FOC@^2.3.4 pazi88/STM32_CAN@^1.1.2 diff --git a/controller/fw/embed/src/main.cpp b/controller/fw/embed/src/main.cpp index b086b59..8bce7b0 100644 --- a/controller/fw/embed/src/main.cpp +++ b/controller/fw/embed/src/main.cpp @@ -63,7 +63,7 @@ volatile uint32_t ipsr_value = 0; void setup(){ // Vector table initialization (commented out) - SCB->VTOR = (uint32_t)0x08008004; + // SCB->VTOR = (uint32_t)0x08008004; Serial.setRx(HARDWARE_SERIAL_RX_PIN); Serial.setTx(HARDWARE_SERIAL_TX_PIN); @@ -92,7 +92,7 @@ volatile uint32_t ipsr_value = 0; // HAL_NVIC_EnableIRQ(CAN2_RX0_IRQn); // Default motor configuration - GPIOC->ODR |= GPIO_ODR_OD11; + GPIOC->ODR |= GPIO_ODR_OD11; //set LED motor.torque_controller = TorqueControlType::foc_current; motor.controller = MotionControlType::torque; __enable_irq(); @@ -106,8 +106,8 @@ void loop() { __enable_irq(); foc_step(&motor, &command); CAN_message_t msg; - GPIOC->ODR ^= GPIO_ODR_OD11; // Toggle status LED - delay(500); + // GPIOC->ODR ^= GPIO_ODR_OD11; // Toggle status LED + // delay(500); // // Process incoming CAN messages while (Can.read(msg)) { diff --git a/controller/fw/embed/src/process_can.cpp b/controller/fw/embed/src/process_can.cpp index 89c8b60..682253e 100644 --- a/controller/fw/embed/src/process_can.cpp +++ b/controller/fw/embed/src/process_can.cpp @@ -62,9 +62,9 @@ void send_motor_enabled() { // Error handling: logging, alerts, etc. return; } - uint8_t value = flash_rec[foc_id].value; + uint8_t value = motor_control_inputs.motor_enabled; //copy current motor state uint8_t id = flash_rec[addr_id].value; - send_can_with_id_crc(id,'F',&value); + send_can_with_id_crc(id,'M',&value); } void send_id() { @@ -90,7 +90,7 @@ void send_id() { // Can.write(CAN_TX_msg); // } -void send_pid(uint8_t param_pid){ +void send_pid_angle(uint8_t param_pid){ if (flash_rec == nullptr) { // Null check return; } @@ -148,7 +148,6 @@ void setup_pid_angle(uint8_t param_pid, float data){ } - void listen_can(const CAN_message_t &msg) { msg_id = msg.id; msg_ch = msg_id & 0xF; // Extract message channel @@ -235,9 +234,9 @@ void listen_can(const CAN_message_t &msg) { case MOTOR_ENABLED: send_motor_enabled(); break; // case MOTOR_TORQUE: send_motor_torque(); break; // case FOC_STATE: send_foc_state(); break; - case REG_MOTOR_POSPID_Kp: send_pid(pid_p); break; - case REG_MOTOR_POSPID_Ki: send_pid(pid_i); break; - case REG_MOTOR_POSPID_Kd: send_pid(pid_d); break; + case REG_MOTOR_POSPID_Kp: send_pid_angle(pid_p); break; + case REG_MOTOR_POSPID_Ki: send_pid_angle(pid_i); break; + case REG_MOTOR_POSPID_Kd: send_pid_angle(pid_d); break; default: break; } }