Skip to content

Commit

Permalink
min viable
Browse files Browse the repository at this point in the history
  • Loading branch information
mathbrook committed Jul 6, 2024
1 parent 0020dbb commit 248a0cf
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/KS2eCAN.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#define ID_VCU_COULOMB_COUNT 0xD3
#define ID_VCU_CALCULATED_SLIP 0xD4
#define ID_VCU_POWER_LIM_UPDATE 0xD5
#define ID_VCU_SPEED_LIM_UPDATE 0xD6
#define ID_BMS_CURRENT_LIMIT_INFO 0x6B1
#define ID_BMS_PACK_VOLTAGE_INFO 0x6B2
#define ID_ACU_RELAY 0x258
Expand Down
2 changes: 2 additions & 0 deletions include/inverter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class Inverter
current_power = pm100CurrentInfo.get_dc_bus_current()/10 * pm100Voltage.get_dc_bus_voltage()/10;
}
bool calc_and_send_current_limit(uint16_t pack_voltage, uint32_t discharge_power_limit, uint32_t charge_power_limit);
bool speedMode = false;
uint16_t angularVelocityTarget = 2000;
};

#endif
2 changes: 1 addition & 1 deletion include/parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const float accumulator_cell_maximum_voltage = 4.2;
const float bspd_trip_power = 5000;
const float bspd_current_high_threshold = bspd_trip_power/(accumulator_cell_count * accumulator_cell_nominal_voltage); // Current value where BSPD current detection should be high (5kw at nominal voltage)
const int MIN_HV_VOLTAGE = 600; // apparently this is divided by ten? yes maybe, bc getmcbusvoltage returns a can packet which is the bus voltage*10? idk
const int DISCHARGE_POWER_LIM = 40000;
const int DISCHARGE_POWER_LIM = 80000;
const int CHARGE_POWER_LIM = 9000;

const float cutoff_10hz = 10; // Hz
Expand Down
15 changes: 12 additions & 3 deletions src/inverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,22 @@ bool Inverter::command_torque(int16_t torque)
{
torque = 0;
}
uint8_t angularVelocity1 = 0, angularVelocity2 = 0;
uint16_t angularVelocity = angularVelocityTarget;
bool emraxDirection = true; // true for forward, false for reverse
bool inverterEnable = true; // go brrr
byte inverterEnable = 0x01; // go brrr
if (speedMode)
{
// This will force speed mode operation :/
inverterEnable |= 0x04;
}

uint8_t torqueCommand[] = {
0, 0, angularVelocity1, angularVelocity2, emraxDirection, inverterEnable, 0, 0};
0, 0, 0, 0, emraxDirection, inverterEnable, 0, 0};
memcpy(&torqueCommand[0], &torque, sizeof(torque));
if (speedMode)
{
memcpy(&torqueCommand[2], &angularVelocity,sizeof(angularVelocity));
}
// Send torque command if timer has fired
if (timer_motor_controller_send->check())
{
Expand Down
28 changes: 28 additions & 0 deletions src/state_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,11 @@ void StateMachine::handle_state_machine(MCU_status &mcu_status)
break;
}
// #endif
// Toggle speed mode if RTD button held for 1 second
if (dash_->get_button_held_duration(3,1000))
{
pm100->speedMode = !(pm100->speedMode);
}
// Torque calc always runs in the superloop
// Toggle launch control if button 5 held for 1 second, while brake is pressed
if (dash_->get_button_held_duration(LAUNCH_CONTROL_BUTTON, 1000))
Expand Down Expand Up @@ -643,6 +648,12 @@ void StateMachine::update_daq_can()
unpack_flexcan_message(ksu_can, rxMsg);
switch (rxMsg.id)
{
case CAN_ID_M193_READ_WRITE_PARAM_COMMAND:
{
// Forward incoming param writes so it can be done with telemetry
WriteCANToJUSTInverter(rxMsg);
break;
}
case CAN_ID_EVELOGGER_VECTORNAV_ACCELERATION:
{
decode_can_0x1f9_evelogger_vectornav_accelX(ksu_can, &vectornav_data.accel_x);
Expand All @@ -662,6 +673,7 @@ void StateMachine::update_daq_can()
case ID_VCU_POWER_LIM_UPDATE:
{
uint32_t new_lim = 80000;
// expect first 4 bytes to be the new limit
memcpy(&new_lim, rxMsg.buf, sizeof(new_lim));
if (new_lim > 80000)
{
Expand All @@ -674,6 +686,22 @@ void StateMachine::update_daq_can()
pm100->discharge_power_lim = new_lim;
break;
}
case ID_VCU_SPEED_LIM_UPDATE:
{
uint16_t new_lim = 4000;
// expect first 2 bytes to be the new limit
memcpy(&new_lim, rxMsg.buf, sizeof(new_lim));
if (new_lim > 4000)
{
new_lim = 4000;
}
else if (new_lim == 0)
{
new_lim = 1000;
}
pm100->angularVelocityTarget = new_lim;
break;
}
}
}
}
Expand Down

0 comments on commit 248a0cf

Please sign in to comment.