small bug fixes

This commit is contained in:
bitscuit 2023-04-29 12:09:30 +02:00
parent abf956162a
commit 7812532dea
1 changed files with 5 additions and 1 deletions

View File

@ -16,7 +16,6 @@
/* Invertor config */
#define MC_L_ID 0x4F /* ID of the left invertor, to be used in CAN communication */
#define MC_R_ID 0x4F /* ID of the right invertor, to be used in CAN communication */
#define CAN_MC_TIMEOUT 100 /* Timeout of the invertors */
/* Invertor CAN packet IDs */
#define CAN_MC_ID_ERPM 0x03 /* Message to set ERPM */
@ -67,6 +66,7 @@ uint64_t time_last_rtd_state = 0; /* Timestamp of last message for Boo
#define RTD_TIMEOUT 200 /* If no state information is received for this time, enter safe state */
uint64_t time_last_can_mc_send_enable = 0; /* Timestamp of last enable/disable message that was sent to motorcontrollers (because they have timeout safety shit) */
#define CAN_MC_TIMEOUT 100 /* Timeout of the invertors */
uint64_t time_last_can_mc_send_erpm = 0; /* Timestamp of last erpm message that was sent to motorcontrollers (to limit amount of messages) */
#define CAN_MC_ERPM_PERIOD 25 /* Time between ERPM messages */
@ -95,6 +95,8 @@ uint32_t time_last_tc_summary = 0;
/* Fault IDs (used in 2nd data field of Critical Fault message on LV CAN) */
#define CAN_FAULT_ID 0x05 /* Fault ID for D0 field of Critical Fault message, signifies that this is a TC fault */
#define CAN_FAULT_SEND_PERIOD 50 /* Will only emit Critical Fault message on CAN is it is this time after last one */
uint32_t time_last_can_fault_send = 0;
#define FAULT_EXTERNAL_CRITICAL 0x00 /* CAN critical fault from other LVS module, will not be transmitted */
#define FAULT_INV_OVERVOLT 0x01 /* Fault from invertor: overvoltage */
#define FAULT_INV_UNDERVOLT 0x02 /* Fault from invertor: undervoltage */
@ -118,11 +120,13 @@ void enter_safe_state(char fault_id) {
/* Send information to LVS */
if (fault_id == FAULT_EXTERNAL_CRITICAL) return; /* Do not resend fault that is not ours */
if (millis() < time_last_can_fault_send + CAN_FAULT_SEND_PERIOD) return; /* Rate limiting */
CAN_message_t m;
m.id = CAN_ID_CRITICAL_FAULT | CAN_MODULE_ID;
m.buf[0] = CAN_FAULT_ID;
m.buf[1] = fault_id;
can_lv.write(m);
time_last_can_fault_send = millis();
}
/* CAN */