Midnight Sun Firmware
Loading...
Searching...
No Matches
can_simulator.py File Reference

Main simulation script. More...

Functions

def pack (num, size)
 
def periodic_sender (bus, messages, period, stop_event)
 
def main ()
 

Variables

float RETRY_TRANSMIT_S = 0.05
 
float FAST_CYCLE_PERIOD = 0.5
 
int MEDIUM_CYCLE_PERIOD = 5
 
int SLOW_CYCLE_PERIOD = 10
 
list messages_fast = []
 
list messages_medium = []
 
list messages_slow = []
 
 can_data_cache = CanSimulatorDataCache()
 
 system_can_message_can_communication_fast_one_shot_msg
 
 system_can_message_can_communication_medium_one_shot_msg
 
 system_can_message_can_communication_slow_one_shot_msg
 
 system_can_message_front_controller_drive_status
 
 system_can_message_front_controller_motor_stats_a
 
 system_can_message_front_controller_motor_stats_b
 
 system_can_message_front_controller_fc_power_group_a
 
 system_can_message_front_controller_fc_power_group_b
 
 system_can_message_front_controller_fc_power_lights_group
 
 system_can_message_imu_gyro_data
 
 system_can_message_rear_controller_rear_controller_status
 
 system_can_message_rear_controller_battery_stats_a
 
 system_can_message_rear_controller_battery_stats_b
 
 system_can_message_rear_controller_power_input_stats
 
 system_can_message_rear_controller_afe1_status_a
 
 system_can_message_rear_controller_afe1_status_b
 
 system_can_message_rear_controller_afe1_status_c
 
 system_can_message_rear_controller_afe1_status_d
 
 system_can_message_rear_controller_afe1_status_e
 
 system_can_message_rear_controller_afe1_status_f
 
 system_can_message_rear_controller_afe2_status_a
 
 system_can_message_rear_controller_afe2_status_b
 
 system_can_message_rear_controller_afe2_status_c
 
 system_can_message_rear_controller_afe2_status_d
 
 system_can_message_rear_controller_afe2_status_e
 
 system_can_message_rear_controller_afe2_status_f
 
 system_can_message_rear_controller_afe_temperature
 
 system_can_message_imu_accel_data
 
 system_can_message_telemetry_imu_data
 

Detailed Description

Main simulation script.

Date
2025-03-09
Author
Midnight Sun Team #24 - MSXVI

Variable Documentation

◆ system_can_message_can_communication_fast_one_shot_msg

system_can_message_can_communication_fast_one_shot_msg
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_CAN_COMMUNICATION_FAST_ONE_SHOT_MSG_ID,
3data = bytearray(pack(can_data_cache.get("can_communication_fast_one_shot_msg", "sig1"), 16) + pack(can_data_cache.get("can_communication_fast_one_shot_msg", "sig2"), 16)))

◆ system_can_message_can_communication_medium_one_shot_msg

system_can_message_can_communication_medium_one_shot_msg
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_CAN_COMMUNICATION_MEDIUM_ONE_SHOT_MSG_ID,
3data = bytearray(pack(can_data_cache.get("can_communication_medium_one_shot_msg", "sig1"), 16) + pack(can_data_cache.get("can_communication_medium_one_shot_msg", "sig2"), 16)))

◆ system_can_message_can_communication_slow_one_shot_msg

system_can_message_can_communication_slow_one_shot_msg
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_CAN_COMMUNICATION_SLOW_ONE_SHOT_MSG_ID,
3data = bytearray(pack(can_data_cache.get("can_communication_slow_one_shot_msg", "sig1"), 16) + pack(can_data_cache.get("can_communication_slow_one_shot_msg", "sig2"), 16)))

◆ system_can_message_front_controller_drive_status

system_can_message_front_controller_drive_status
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_FRONT_CONTROLLER_DRIVE_STATUS_ID,
3data = bytearray(pack(can_data_cache.get("front_controller_drive_status", "pedal_percentage"), 32) + pack(can_data_cache.get("front_controller_drive_status", "state_data"), 8)))

◆ system_can_message_front_controller_fc_power_group_a

system_can_message_front_controller_fc_power_group_a
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_FRONT_CONTROLLER_FC_POWER_GROUP_A_ID,
3data = bytearray(pack(can_data_cache.get("front_controller_fc_power_group_a", "rev_cam_current"), 16) + pack(can_data_cache.get("front_controller_fc_power_group_a", "telem_current"), 16) + pack(can_data_cache.get("front_controller_fc_power_group_a", "steering_current"), 16) + pack(can_data_cache.get("front_controller_fc_power_group_a", "driver_fan_current"), 16)))

◆ system_can_message_front_controller_fc_power_group_b

system_can_message_front_controller_fc_power_group_b
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_FRONT_CONTROLLER_FC_POWER_GROUP_B_ID,
3data = bytearray(pack(can_data_cache.get("front_controller_fc_power_group_b", "horn_current"), 16) + pack(can_data_cache.get("front_controller_fc_power_group_b", "spare_current"), 16)))

◆ system_can_message_front_controller_fc_power_lights_group

system_can_message_front_controller_fc_power_lights_group
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_FRONT_CONTROLLER_FC_POWER_LIGHTS_GROUP_ID,
3data = bytearray(pack(can_data_cache.get("front_controller_fc_power_lights_group", "brake_light_sig_current"), 16) + pack(can_data_cache.get("front_controller_fc_power_lights_group", "bps_light_sig_current"), 16) + pack(can_data_cache.get("front_controller_fc_power_lights_group", "right_sig_current"), 16) + pack(can_data_cache.get("front_controller_fc_power_lights_group", "left_sig_current"), 16)))

◆ system_can_message_front_controller_motor_stats_a

system_can_message_front_controller_motor_stats_a
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_FRONT_CONTROLLER_MOTOR_STATS_A_ID,
3data = bytearray(pack(can_data_cache.get("front_controller_motor_stats_a", "bus_voltage"), 16) + pack(can_data_cache.get("front_controller_motor_stats_a", "bus_current"), 16) + pack(can_data_cache.get("front_controller_motor_stats_a", "rail_15v_supply"), 16)))

◆ system_can_message_front_controller_motor_stats_b

system_can_message_front_controller_motor_stats_b
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_FRONT_CONTROLLER_MOTOR_STATS_B_ID,
3data = bytearray(pack(can_data_cache.get("front_controller_motor_stats_b", "vehicle_velocity"), 16) + pack(can_data_cache.get("front_controller_motor_stats_b", "motor_velocity"), 16) + pack(can_data_cache.get("front_controller_motor_stats_b", "heat_sink_temp"), 16) + pack(can_data_cache.get("front_controller_motor_stats_b", "motor_temp"), 16)))

◆ system_can_message_imu_accel_data

system_can_message_imu_accel_data
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_IMU_ACCEL_DATA_ID,
3data = bytearray(pack(can_data_cache.get("imu_accel_data", "x_axis"), 16) + pack(can_data_cache.get("imu_accel_data", "y_axis"), 16) + pack(can_data_cache.get("imu_accel_data", "z_axis"), 16)))

◆ system_can_message_imu_gyro_data

system_can_message_imu_gyro_data
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_IMU_GYRO_DATA_ID,
3data = bytearray(pack(can_data_cache.get("imu_gyro_data", "x_axis"), 16) + pack(can_data_cache.get("imu_gyro_data", "y_axis"), 16) + pack(can_data_cache.get("imu_gyro_data", "z_axis"), 16)))

◆ system_can_message_rear_controller_afe1_status_a

system_can_message_rear_controller_afe1_status_a
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_REAR_CONTROLLER_AFE1_STATUS_A_ID,
3data = bytearray(pack(can_data_cache.get("rear_controller_afe1_status_a", "id"), 8) + pack(can_data_cache.get("rear_controller_afe1_status_a", "voltage_0"), 16) + pack(can_data_cache.get("rear_controller_afe1_status_a", "voltage_1"), 16) + pack(can_data_cache.get("rear_controller_afe1_status_a", "voltage_2"), 16)))

◆ system_can_message_rear_controller_afe1_status_b

system_can_message_rear_controller_afe1_status_b
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_REAR_CONTROLLER_AFE1_STATUS_B_ID,
3data = bytearray(pack(can_data_cache.get("rear_controller_afe1_status_b", "id"), 8) + pack(can_data_cache.get("rear_controller_afe1_status_b", "voltage_3"), 16) + pack(can_data_cache.get("rear_controller_afe1_status_b", "voltage_4"), 16) + pack(can_data_cache.get("rear_controller_afe1_status_b", "voltage_5"), 16)))

◆ system_can_message_rear_controller_afe1_status_c

system_can_message_rear_controller_afe1_status_c
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_REAR_CONTROLLER_AFE1_STATUS_C_ID,
3data = bytearray(pack(can_data_cache.get("rear_controller_afe1_status_c", "id"), 8) + pack(can_data_cache.get("rear_controller_afe1_status_c", "voltage_6"), 16) + pack(can_data_cache.get("rear_controller_afe1_status_c", "voltage_7"), 16) + pack(can_data_cache.get("rear_controller_afe1_status_c", "voltage_8"), 16)))

◆ system_can_message_rear_controller_afe1_status_d

system_can_message_rear_controller_afe1_status_d
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_REAR_CONTROLLER_AFE1_STATUS_D_ID,
3data = bytearray(pack(can_data_cache.get("rear_controller_afe1_status_d", "id"), 8) + pack(can_data_cache.get("rear_controller_afe1_status_d", "voltage_9"), 16) + pack(can_data_cache.get("rear_controller_afe1_status_d", "voltage_10"), 16) + pack(can_data_cache.get("rear_controller_afe1_status_d", "voltage_11"), 16)))

◆ system_can_message_rear_controller_afe1_status_e

system_can_message_rear_controller_afe1_status_e
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_REAR_CONTROLLER_AFE1_STATUS_E_ID,
3data = bytearray(pack(can_data_cache.get("rear_controller_afe1_status_e", "id"), 8) + pack(can_data_cache.get("rear_controller_afe1_status_e", "voltage_12"), 16) + pack(can_data_cache.get("rear_controller_afe1_status_e", "voltage_13"), 16) + pack(can_data_cache.get("rear_controller_afe1_status_e", "voltage_14"), 16)))

◆ system_can_message_rear_controller_afe1_status_f

system_can_message_rear_controller_afe1_status_f
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_REAR_CONTROLLER_AFE1_STATUS_F_ID,
3data = bytearray(pack(can_data_cache.get("rear_controller_afe1_status_f", "id"), 8) + pack(can_data_cache.get("rear_controller_afe1_status_f", "voltage_15"), 16) + pack(can_data_cache.get("rear_controller_afe1_status_f", "voltage_16"), 16) + pack(can_data_cache.get("rear_controller_afe1_status_f", "voltage_17"), 16)))

◆ system_can_message_rear_controller_afe2_status_a

system_can_message_rear_controller_afe2_status_a
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_REAR_CONTROLLER_AFE2_STATUS_A_ID,
3data = bytearray(pack(can_data_cache.get("rear_controller_afe2_status_a", "id"), 8) + pack(can_data_cache.get("rear_controller_afe2_status_a", "voltage_0"), 16) + pack(can_data_cache.get("rear_controller_afe2_status_a", "voltage_1"), 16) + pack(can_data_cache.get("rear_controller_afe2_status_a", "voltage_2"), 16)))

◆ system_can_message_rear_controller_afe2_status_b

system_can_message_rear_controller_afe2_status_b
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_REAR_CONTROLLER_AFE2_STATUS_B_ID,
3data = bytearray(pack(can_data_cache.get("rear_controller_afe2_status_b", "id"), 8) + pack(can_data_cache.get("rear_controller_afe2_status_b", "voltage_3"), 16) + pack(can_data_cache.get("rear_controller_afe2_status_b", "voltage_4"), 16) + pack(can_data_cache.get("rear_controller_afe2_status_b", "voltage_5"), 16)))

◆ system_can_message_rear_controller_afe2_status_c

system_can_message_rear_controller_afe2_status_c
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_REAR_CONTROLLER_AFE2_STATUS_C_ID,
3data = bytearray(pack(can_data_cache.get("rear_controller_afe2_status_c", "id"), 8) + pack(can_data_cache.get("rear_controller_afe2_status_c", "voltage_6"), 16) + pack(can_data_cache.get("rear_controller_afe2_status_c", "voltage_7"), 16) + pack(can_data_cache.get("rear_controller_afe2_status_c", "voltage_8"), 16)))

◆ system_can_message_rear_controller_afe2_status_d

system_can_message_rear_controller_afe2_status_d
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_REAR_CONTROLLER_AFE2_STATUS_D_ID,
3data = bytearray(pack(can_data_cache.get("rear_controller_afe2_status_d", "id"), 8) + pack(can_data_cache.get("rear_controller_afe2_status_d", "voltage_9"), 16) + pack(can_data_cache.get("rear_controller_afe2_status_d", "voltage_10"), 16) + pack(can_data_cache.get("rear_controller_afe2_status_d", "voltage_11"), 16)))

◆ system_can_message_rear_controller_afe2_status_e

system_can_message_rear_controller_afe2_status_e
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_REAR_CONTROLLER_AFE2_STATUS_E_ID,
3data = bytearray(pack(can_data_cache.get("rear_controller_afe2_status_e", "id"), 8) + pack(can_data_cache.get("rear_controller_afe2_status_e", "voltage_12"), 16) + pack(can_data_cache.get("rear_controller_afe2_status_e", "voltage_13"), 16) + pack(can_data_cache.get("rear_controller_afe2_status_e", "voltage_14"), 16)))

◆ system_can_message_rear_controller_afe2_status_f

system_can_message_rear_controller_afe2_status_f
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_REAR_CONTROLLER_AFE2_STATUS_F_ID,
3data = bytearray(pack(can_data_cache.get("rear_controller_afe2_status_f", "id"), 8) + pack(can_data_cache.get("rear_controller_afe2_status_f", "voltage_15"), 16) + pack(can_data_cache.get("rear_controller_afe2_status_f", "voltage_16"), 16) + pack(can_data_cache.get("rear_controller_afe2_status_f", "voltage_17"), 16)))

◆ system_can_message_rear_controller_afe_temperature

system_can_message_rear_controller_afe_temperature
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_REAR_CONTROLLER_AFE_TEMPERATURE_ID,
3data = bytearray(pack(can_data_cache.get("rear_controller_afe_temperature", "id"), 8) + pack(can_data_cache.get("rear_controller_afe_temperature", "temperature_0"), 8) + pack(can_data_cache.get("rear_controller_afe_temperature", "temperature_1"), 8) + pack(can_data_cache.get("rear_controller_afe_temperature", "temperature_2"), 8) + pack(can_data_cache.get("rear_controller_afe_temperature", "temperature_3"), 8) + pack(can_data_cache.get("rear_controller_afe_temperature", "temperature_4"), 8) + pack(can_data_cache.get("rear_controller_afe_temperature", "temperature_5"), 8) + pack(can_data_cache.get("rear_controller_afe_temperature", "temperature_6"), 8)))

◆ system_can_message_rear_controller_battery_stats_a

system_can_message_rear_controller_battery_stats_a
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_REAR_CONTROLLER_BATTERY_STATS_A_ID,
3data = bytearray(pack(can_data_cache.get("rear_controller_battery_stats_a", "pack_voltage"), 16) + pack(can_data_cache.get("rear_controller_battery_stats_a", "pack_current"), 16) + pack(can_data_cache.get("rear_controller_battery_stats_a", "pack_soc"), 16)))

◆ system_can_message_rear_controller_battery_stats_b

system_can_message_rear_controller_battery_stats_b
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_REAR_CONTROLLER_BATTERY_STATS_B_ID,
3data = bytearray(pack(can_data_cache.get("rear_controller_battery_stats_b", "max_cell_voltage"), 16) + pack(can_data_cache.get("rear_controller_battery_stats_b", "min_cell_voltage"), 16) + pack(can_data_cache.get("rear_controller_battery_stats_b", "max_temperature"), 16)))

◆ system_can_message_rear_controller_power_input_stats

system_can_message_rear_controller_power_input_stats
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_REAR_CONTROLLER_POWER_INPUT_STATS_ID,
3data = bytearray(pack(can_data_cache.get("rear_controller_power_input_stats", "input_dcdc_voltage"), 16) + pack(can_data_cache.get("rear_controller_power_input_stats", "input_dcdc_current"), 16) + pack(can_data_cache.get("rear_controller_power_input_stats", "input_aux_voltage"), 16) + pack(can_data_cache.get("rear_controller_power_input_stats", "input_aux_current"), 16)))

◆ system_can_message_rear_controller_rear_controller_status

system_can_message_rear_controller_rear_controller_status
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_REAR_CONTROLLER_REAR_CONTROLLER_STATUS_ID,
3data = bytearray(pack(can_data_cache.get("rear_controller_rear_controller_status", "triggers"), 32)))

◆ system_can_message_telemetry_imu_data

system_can_message_telemetry_imu_data
Initial value:
1= Message(
2arbitration_id = SystemCanMessageId.SYSTEM_CAN_MESSAGE_TELEMETRY_IMU_DATA_ID,
3data = bytearray(pack(can_data_cache.get("telemetry_imu_data", "g_force"), 16) + pack(can_data_cache.get("telemetry_imu_data", "roll"), 16) + pack(can_data_cache.get("telemetry_imu_data", "pitch"), 16) + pack(can_data_cache.get("telemetry_imu_data", "yaw"), 16)))