Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ht07summer testing #6

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6dee9ac
Accel pedal constants update
CL16gtgh Jul 13, 2023
b97ae31
Watdog timer and accel pedal adjustment
CL16gtgh Jul 16, 2023
f8b3b29
Fixed energy meter CAN
Luke-kC Aug 15, 2023
d9506dd
Brake pedal adjusted
Luke-kC Aug 16, 2023
f76e028
fixed acu
EricGalluzzi Aug 28, 2023
cd5fb10
Merge branch 'merge_acu_to_main' into ht07summerTesting
EricGalluzzi Aug 28, 2023
61dac3a
revert brake pedal threshold
EricGalluzzi Aug 28, 2023
dce6489
Add pots reading
CL16gtgh Sep 3, 2023
927e9b1
Draft Coulomb Counting Code
FemK157 Jan 14, 2024
d85c327
made fixes
FemK157 Jan 15, 2024
096c5b4
debugged code
FemK157 Jan 17, 2024
d335bca
Solve delatching problem by attempting to suicide
CL16gtgh Mar 4, 2024
c63a923
fixed shunt readings + added CAN send for shunt
EricGalluzzi Mar 10, 2024
22ca28e
replace mode 1 with nissan mode
Dopp-IO Mar 13, 2024
b3fc871
Update EM_measurement.h
Mar 23, 2024
fcad6b1
fix offsets
siddhxrth Mar 29, 2024
4ffa8e8
debugging code so that it compiles
FemK157 Apr 5, 2024
c5049b8
Merge branch 'ht07summerTesting' into Test_coulomb_counting
FemK157 Apr 5, 2024
d23c248
change successive fault
FemK157 Apr 5, 2024
6163f86
forward raw em
CL16gtgh Apr 5, 2024
d29d79c
fix
CL16gtgh Apr 5, 2024
ad93714
Merge pull request #12 from hytech-racing/Test_coulomb_counting
FemK157 Apr 5, 2024
52eabf0
WHO DECIDED TO INITIALIZE THIS ONCE AND NEVER ASSIGN AGAIN
CL16gtgh Apr 12, 2024
740229a
current_shunt
AZhaoT Apr 12, 2024
07309c7
Merge branch 'ht07summerTesting' of https://github.com/hytech-racing/…
AZhaoT Apr 12, 2024
313fae9
current shunt
AZhaoT Apr 12, 2024
613b036
Incorporated Lookup Table
FemK157 Apr 14, 2024
e1c4ea6
fixed compiling errors
FemK157 Apr 15, 2024
12fc1f4
sent SoC to CAN
FemK157 Apr 16, 2024
97efd2f
Updated shunt measurements to send shunt current, pack, and TS
jhwang04 Apr 26, 2024
0190b51
Fixed typo
jhwang04 Apr 26, 2024
7f3dcb4
Minor text fixes
jhwang04 May 11, 2024
7a2c9f3
Lower back down to 20 to prevent draining pack too hard
CL16gtgh Jun 2, 2024
3d4c049
crank up for comp
CL16gtgh Jun 15, 2024
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
37 changes: 37 additions & 0 deletions Libraries/HyTech_CAN/ACU_shunt_measurements.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once
#include <string.h>
#include <stdint.h>
#ifdef HT_DEBUG_EN
#include "Arduino.h"
#endif

#pragma pack(push,1)

// @Parseclass @Prefix(ACU)
class ACU_shunt_measurements {

public:
ACU_shunt_measurements() = default;
ACU_shunt_measurements(uint8_t buf[]) { load(buf); }

inline void load(uint8_t buf[]) { memcpy(this, buf, sizeof(*this)); }
inline void write(uint8_t buf[]) const { memcpy(buf, this, sizeof(*this)); }

// Getters
inline uint16_t get_shunt_current() const {return shunt_current;}
inline uint16_t get_pack_filtered() const {return pack_filtered;}
inline uint16_t get_ts_out_filtered() const {return ts_out_filtered;}

// Setters
inline void set_shunt_current(uint16_t shunt_current) {this->shunt_current = (uint16_t) (shunt_current);}
inline void set_pack_filtered(uint16_t pack_filtered) {this->pack_filtered = (uint16_t) (pack_filtered);}
inline void set_ts_out_filtered(uint16_t ts_out_filtered) {this->ts_out_filtered = (uint16_t) (ts_out_filtered);}

// Member variables
private:
uint16_t shunt_current;
uint16_t pack_filtered;
uint16_t ts_out_filtered;
};

#pragma pack(pop)
5 changes: 3 additions & 2 deletions Libraries/HyTech_CAN/CAN_ID.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@
#define ID_CHARGER_CONTROL 0x1806E5F4
#define ID_CHARGER_DATA 0x18FF50E5

#define ID_EM_STATUS 0x100
#define ID_EM_MEASUREMENT 0x400
#define ID_ACU_SHUNT_MEASUREMENT 0x401
#define ID_EM_STATUS 0x400
#define ID_EM_MEASUREMENT 0x100

#define ID_IMU_ACCELEROMETER 0x90
#define ID_IMU_GYROSCOPE 0x91
Expand Down
12 changes: 8 additions & 4 deletions Libraries/HyTech_CAN/EM_measurement.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ class EM_measurement {

// Big endian byte ordering
inline void load_from_emeter(uint8_t buf[]) {
voltage = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | (buf[3]);
current = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | (buf[7]);
//voltage = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | (buf[3]);
voltage = ((buf[4] & 0x01) << 24) | (buf[5] << 16) | (buf[6] << 8) | (buf[7]); // First byte does not necessarily need & since those bits in fact appeared to be 0
//current = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | (buf[7]);
// current = ((buf[0] & 0x01) << 24) | (buf[1] << 16) | (buf[2] << 8) | (buf[3]); // Same as voltage
current = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | (buf[3]); // possible fix?
// why is there gaps between values in signal?
}

// Big endian byte ordering
Expand Down Expand Up @@ -47,8 +51,8 @@ class EM_measurement {
#endif

private:
uint32_t voltage; //@Parse @Scale(65536) @Unit(V)
uint32_t current; //@Parse @Scale(65536) @Unit(A)
int32_t voltage; //@Parse @Scale(65536) @Unit(V) // Changed into signed int per DBC file
int32_t current; //@Parse @Scale(65536) @Unit(A)
};

#pragma pack(pop)
16 changes: 11 additions & 5 deletions Libraries/HyTech_CAN/EM_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ class EM_status {
inline void load(uint8_t buf[]) { memcpy(this, buf, sizeof(*this)); }
inline void write(uint8_t buf[]) const { memcpy(buf, this, sizeof(*this)); }

inline uint8_t get_voltage_gain() const { return gain & 0xF; }
inline uint8_t get_current_gain() const { return gain >> 4; }
inline bool get_overvoltage() const { return flags & 0x1; }
inline bool get_overpower() const { return flags & 0x2; }
inline bool get_logging() const { return flags & 0x4; }
//inline uint8_t get_voltage_gain() const { return gain & 0xF; }
inline uint8_t get_voltage_gain() const { return ((gain & 0x1F) >> 1); } // Modification per DBC file, yet to be verified
//inline uint8_t get_current_gain() const { return gain >> 4; }
inline uint8_t get_current_gain() const { return (((gain & 0x01) << 3) | ((flags & 0xE0) >> 5)); }
//inline bool get_overvoltage() const { return flags & 0x1; }
inline bool get_overvoltage() const { return flags & 0x80; }
//inline bool get_overpower() const { return flags & 0x2; }
inline bool get_overpower() const { return flags & 0x40; }
//inline bool get_logging() const { return flags & 0x4; }
inline bool get_logging() const { return flags & 0x20; }

#ifdef HT_DEBUG_EN
void print() {
Expand All @@ -37,6 +42,7 @@ class EM_status {
private:
uint8_t gain;
uint8_t flags; //@Parse @Flaglist(overvoltage, overpower, logging)
uint16_t dummy; // Compensate 4-byte data frame
};

#pragma pack(pop)
2 changes: 1 addition & 1 deletion Libraries/HyTech_CAN/HyTech_CAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define BMS_STATE_BALANCING_OVERHEATED 4

#include "CAN_ID.h"

#include "ACU_shunt_measurements.h"
#include "BMS_balancing_status.h"
#include "BMS_coulomb_counts.h"
#include "BMS_detailed_temperatures.h"
Expand Down
23 changes: 13 additions & 10 deletions Libraries/LTC6811_2/LTC6811_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

// debug mode
#define DEBUG false
// SPI slave select pin, as required for Teensy 4.0
#define SS 10
// SPI alternate pin definitions (not needed unless using Teensy 3.2 alternate SPI pins)
#define MOSI 7 // pin 11 by default
#define MISO 8 // pin 12 by default
Expand All @@ -16,7 +14,7 @@
// SPI write
void LTC6811_2::spi_write_reg(uint8_t *cmd, uint8_t *cmd_pec, uint8_t *data, uint8_t *data_pec) {
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3));
digitalWrite(SS, LOW);
digitalWrite(this->chip_select, LOW);
delayMicroseconds(1);
SPI.transfer(cmd[0]);
SPI.transfer(cmd[1]);
Expand All @@ -27,7 +25,7 @@ void LTC6811_2::spi_write_reg(uint8_t *cmd, uint8_t *cmd_pec, uint8_t *data, uin
}
SPI.transfer(data_pec[0]);
SPI.transfer(data_pec[1]);
digitalWrite(SS, HIGH);
digitalWrite(this->chip_select, HIGH);
delayMicroseconds(1);
SPI.endTransaction();
#if DEBUG
Expand All @@ -37,7 +35,7 @@ void LTC6811_2::spi_write_reg(uint8_t *cmd, uint8_t *cmd_pec, uint8_t *data, uin
// SPI read; IF CODE DOES NOT WORK, THIS IS A GOOD PLACE TO START DEBUGGING
void LTC6811_2::spi_read_reg(uint8_t *cmd, uint8_t* cmd_pec, uint8_t *data_in) {
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3));
digitalWrite(SS, LOW);
digitalWrite(this->chip_select, LOW);
delayMicroseconds(1);
SPI.transfer(cmd[0]);
SPI.transfer(cmd[1]);
Expand All @@ -50,25 +48,30 @@ void LTC6811_2::spi_read_reg(uint8_t *cmd, uint8_t* cmd_pec, uint8_t *data_in) {
Serial.print("SPI in byte: "); Serial.println(data_in[i], BIN);
#endif
}
digitalWrite(SS, HIGH);
digitalWrite(this->chip_select, HIGH);
delayMicroseconds(1);
SPI.endTransaction();
}

// SPI command
void LTC6811_2::spi_cmd(uint8_t *cmd, uint8_t* cmd_pec) {
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3));
digitalWrite(SS, LOW);
digitalWrite(this->chip_select, LOW);
delayMicroseconds(1);
SPI.transfer(cmd[0]);
SPI.transfer(cmd[1]);
SPI.transfer(cmd_pec[0]);
SPI.transfer(cmd_pec[1]);
digitalWrite(SS, HIGH);
digitalWrite(this->chip_select, HIGH);
delayMicroseconds(1);
SPI.endTransaction();
}

// Set SPI chip select
void LTC6811_2::spi_set_chip_select(uint8_t cs) {
this->chip_select = cs;
}

// returns the address of the specific LTC6811-2 chip to send command to
uint8_t LTC6811_2::get_cmd_address() {
return 0x80 | (this->address << 3);
Expand Down Expand Up @@ -373,10 +376,10 @@ void LTC6811_2::stcomm() {
*/
// Wakeup LTC6811 from core SLEEP state and/ or isoSPI IDLE state to ready for ADC measurements or isoSPI comms
void LTC6811_2::wakeup() {
digitalWrite(SS, LOW);
digitalWrite(this->chip_select, LOW);
delayMicroseconds(1);
SPI.transfer(0);
digitalWrite(SS, HIGH);
digitalWrite(this->chip_select, HIGH);
delayMicroseconds(400); //t_wake is 400 microseconds; wait that long to ensure device has turned on.
}

Expand Down
2 changes: 2 additions & 0 deletions Libraries/LTC6811_2/LTC6811_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class LTC6811_2 {
void spi_write_reg(uint8_t *cmd, uint8_t *cmd_pec, uint8_t *data, uint8_t *data_pec);
void spi_read_reg(uint8_t *cmd, uint8_t* cmd_pec, uint8_t *data_in);
void spi_cmd(uint8_t *cmd, uint8_t* cmd_pec);
void spi_set_chip_select(uint8_t cs);
void write_register_group(uint16_t cmd_code, const uint8_t *buffer);
void read_register_group(uint16_t cmd_code, uint8_t *data);
void non_register_cmd(uint16_t cmd_code);
Expand All @@ -112,6 +113,7 @@ class LTC6811_2 {
bool pec_error;
uint8_t adc_mode;
uint8_t discharge_permitted;
uint8_t chip_select = 10;
uint8_t adc_state = 0; // 0: wait to begin voltage conversions; 1: adcs converting voltage values; 2: wait to begin gpio conversions; 3: adcs converting GPIO values
elapsedMillis adc_timer = 0; // timer that determines wait time for ADCs to finish their conversions
};
Loading