Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions components/CAN/CAN_Config.hpp

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add the steering wheel message to the CAN_Rx list at the bottom of the file too so that it actually get's processed.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "etl/set.h"

// Defining the CAN_IDs & Signals
#define STEERING_WHEEL 103
#define VCU_PDM_REAR_CMD 2012
#define M173_MODULATION_AND_FLUX_INFO 173
#define M172_TORQUE_AND_TIMER_INFO 172
Expand Down Expand Up @@ -55,6 +56,8 @@
#define VCU_FRONT_WHEEL_RIGHT 2029
#define PACKINFO 1057

inline CAN_Signal DRS_Request_ID103{true, 0, 1};
inline CAN_Signal Torque_Limit_Request_ID103{true, 8, 8};
inline CAN_Signal Rear_Cmd_HSD1_ID2012{true, 0, 8};
inline CAN_Signal Rear_Cmd_HSD2_ID2012{true, 8, 8};
inline CAN_Signal Rear_Cmd_HSD3_ID2012{true, 16, 8};
Expand Down Expand Up @@ -293,6 +296,10 @@ inline CAN_Signal MaxCellVoltage_ID1057{true, 48, 16, 0.001f};
// Define the CAN Map
inline etl::map CAN_Map
{
etl::pair{STEERING_WHEEL, etl::vector<CAN_Signal*, 16>{
&DRS_Request_ID103,
&Torque_Limit_Request_ID103
}},
etl::pair{VCU_PDM_REAR_CMD, etl::vector<CAN_Signal*, 16>{
&Rear_Cmd_HSD1_ID2012,
&Rear_Cmd_HSD2_ID2012,
Expand Down
2 changes: 1 addition & 1 deletion components/Devices/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
idf_component_register(SRCS "RearECU.cpp" "BMS.cpp" "Inverter.cpp" "Pedals.cpp" "Devices.cpp" "pwm.cpp"
idf_component_register(SRCS "RearECU.cpp" "BMS.cpp" "Inverter.cpp" "Pedals.cpp" "Devices.cpp" "pwm.cpp" "DRS.cpp"
INCLUDE_DIRS "."
REQUIRES CAN IO Sensors)
34 changes: 34 additions & 0 deletions components/Devices/DRS.cpp

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't send CAN stuff raw like this. I already have a CAN abstraction that you should be using. If you send me the servo data sheet I can work it in in a way that makes sense.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "DRS.hpp"
#include "CAN_Config.hpp"
#include "esp_log.h"

static const char* TAG = "DRS";

static void send_servo(bool open) {
uint16_t position = open ? DRS::POSITION_OPEN : DRS::POSITION_CLOSED;
uint8_t lo = position & 0xFF;
uint8_t hi = (position >> 8) & 0xFF;

twai_message_t msg = {};
msg.identifier = 0;
msg.extd = 0;
msg.data_length_code = 5;
msg.data[0] = 'w';
msg.data[1] = 0;
msg.data[2] = 0x1E;
msg.data[3] = lo;
msg.data[4] = hi;

twai_transmit(&msg, pdMS_TO_TICKS(10));
}

void DRS::init() {
send_servo(false); // start closed
ESP_LOGI(TAG, "DRS initialised — wing CLOSED");
}

void DRS::update() {
bool open = DRS_Request_ID103.get_bool();
send_servo(open);
ESP_LOGD(TAG, ">DRS_open:%d", open);
}
11 changes: 11 additions & 0 deletions components/Devices/DRS.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include "driver/twai.h"

namespace DRS {
// Servo position values — calibrate to your actual wing travel
constexpr uint16_t POSITION_OPEN = 10922; // REG_POSITION_MAX_LIMIT default
constexpr uint16_t POSITION_CLOSED = 5462; // REG_POSITION_MIN_LIMIT default

void init();
void update(); // call this in the RearECU loop
}
2 changes: 1 addition & 1 deletion components/Devices/Inverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SemaphoreHandle_t Inverter::mutex = xSemaphoreCreateMutex();

Inverter::Inverter()
{
torqueLimit = 170; // get this from memory later
torqueLimit = 195; // get this from memory later
VCU_INV_Direction_Command_ID192.set(true); //flip direction cause whatever
ESP_LOGI(TAG, "Inverter Initialized");
}
Expand Down
5 changes: 5 additions & 0 deletions components/Devices/RearECU.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "RearECU.h"
#include "esp_log.h"
#include "DRS.hpp"

static const char* TAG = "RearECU"; //Used for ESP_LOGx commands. See ESP-IDF Documentation

using namespace RearECU;
Expand All @@ -22,6 +24,7 @@ void RearECU::rearECU_Task(void*)
CAN_Tx_100ms_IDs.insert(VCU_REAR_IMU_2);

pwm_init();
DRS::init();
int pump_duty_cycle = 100;


Expand Down Expand Up @@ -77,5 +80,7 @@ void RearECU::rearECU_Task(void*)

vTaskDelay(pdMS_TO_TICKS(100));

DRS::update();

}
}
Loading