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
4 changes: 3 additions & 1 deletion include/VCF_Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ constexpr int STEERING_1_CHANNEL = 5;
// constexpr int UNUSED_CHANNEL = 7;

/* Channels on ADC_2 */
// constexpr int UNUSED_CHANNEL = 0;
constexpr int PEDAL_PRESSURE_CHANNEL = 0;
// constexpr int UNUSED_CHANNEL = 1;
constexpr int ACCEL_1_CHANNEL = 2;
constexpr int ACCEL_2_CHANNEL = 3;
Expand Down Expand Up @@ -81,6 +81,8 @@ constexpr float BRAKE_1_SCALE = 1;
constexpr float BRAKE_1_OFFSET = 0;
constexpr float BRAKE_2_SCALE = 1;
constexpr float BRAKE_2_OFFSET = 0;
constexpr float PEDAL_PRESSURE_SCALE = 1; // TODO: Figure out what these should be from calibration/ datasheet
constexpr float PEDAL_PRESSURE_OFFSET = 0; //TODO: Figure out what these should be from calibration/ datasheet



Expand Down
12 changes: 12 additions & 0 deletions lib/interfaces/include/PedalPressureInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef PEDALPRESSUREINTERFACE_H
#define PEDALPRESSUREINTERFACE_H

#include "hytech.h"
#include "VCFCANInterfaceImpl.h"
#include "SharedFirmwareTypes.h"

class PedalPressureInterface {
public:
void send_pedal_pressure_CAN(uint16_t pedal_pressure);
};
#endif // PEDALPRESSUREINTERFACE_H
37 changes: 37 additions & 0 deletions lib/interfaces/src/PedalPressureInterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "PedalPressureInterface.h"
#include "VCFCANInterfaceImpl.h"
#include <cstdint>
#include <cstring> // for memcpy

// Constants
constexpr uint32_t PEDAL_PRESSURE_CANID = 0x0CBU;
constexpr uint8_t PEDAL_PRESSURE_DLC = 2U; // 16-bit pedal pressure
constexpr uint8_t BYTE_MASK = 0xFF;
constexpr size_t CAN_MSG_SIZE = sizeof(CAN_message_t);
constexpr uint8_t PEDAL_PRESSURE_SHIFT = 8U;


void PedalPressureInterface::send_pedal_pressure_CAN(uint16_t pedal_pressure)
{
// Construct the CAN message
CAN_message_t msg{};
msg.id = PEDAL_PRESSURE_CANID;
msg.len = PEDAL_PRESSURE_DLC;
msg.flags.extended = 0;

// Encode the 16-bit pedal pressure
msg.buf[0] = static_cast<uint8_t>(pedal_pressure & BYTE_MASK); // low byte
msg.buf[1] = static_cast<uint8_t>((pedal_pressure >> PEDAL_PRESSURE_SHIFT) & BYTE_MASK); // high byte

// Copy to raw buffer for TX queue
uint8_t raw_buf[CAN_MSG_SIZE];
std::memcpy(static_cast<void*>(raw_buf), &msg, CAN_MSG_SIZE);

// Push to TX buffer using VCF helper
auto &can_objs = VCFCANInterfaceImpl::VCFCANInterfaceObjectsInstance::instance();
can_objs.main_can_tx_buffer.push_back(static_cast<uint8_t*>(raw_buf), CAN_MSG_SIZE);

// Send all messages on the main CAN interface
VCFCANInterfaceImpl::send_all_CAN_msgs(can_objs.main_can_tx_buffer, can_objs.MAIN_CAN);
}

1 change: 1 addition & 0 deletions src/VCF_Tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ HT_TASK::TaskResponse run_read_adc2_task(const unsigned long& sysMicros, const H
VCFData_sInstance::instance().interface_data.pedal_sensor_data.accel_2 = ADCsOnVCFInstance::instance().adc_2.data.conversions[ACCEL_2_CHANNEL].conversion;
VCFData_sInstance::instance().interface_data.pedal_sensor_data.brake_1 = ADCsOnVCFInstance::instance().adc_2.data.conversions[BRAKE_1_CHANNEL].conversion;
VCFData_sInstance::instance().interface_data.pedal_sensor_data.brake_2 = ADCsOnVCFInstance::instance().adc_2.data.conversions[BRAKE_2_CHANNEL].conversion;
VCFData_sInstance::instance().interface_data.pedal_sensor_data.pedal_pressure = ADCsOnVCFInstance::instance().adc_2.data.conversions[PEDAL_PRESSURE_CHANNEL].conversion;
return HT_TASK::TaskResponse::YIELD;
}

Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ void setup() {
adc_2_offsets[BRAKE_1_CHANNEL] = BRAKE_1_OFFSET;
adc_2_scales[BRAKE_2_CHANNEL] = BRAKE_2_SCALE;
adc_2_offsets[BRAKE_2_CHANNEL] = BRAKE_2_OFFSET;
adc_2_offsets[PEDAL_PRESSURE_CHANNEL] = PEDAL_PRESSURE_OFFSET;
adc_2_scales[PEDAL_PRESSURE_CHANNEL] = PEDAL_PRESSURE_SCALE;
ADCsOnVCFInstance::create(adc_1_scales, adc_1_offsets, adc_2_scales, adc_2_offsets);

EthernetIPDefsInstance::create();
Expand Down