From 91e76a72b0ca570a435e2bee91e01069ceaaace9 Mon Sep 17 00:00:00 2001 From: XanderHayhoe Date: Thu, 15 Feb 2024 20:34:32 -0500 Subject: [PATCH 01/50] init --- can/config.py | 12 ++++++++++++ can/driver.py | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 can/config.py create mode 100644 can/driver.py diff --git a/can/config.py b/can/config.py new file mode 100644 index 0000000..9e4fd02 --- /dev/null +++ b/can/config.py @@ -0,0 +1,12 @@ +import time +import can + +BMS_ARBITRATION_ID = 100 + +class BMS_DATA: + identifier = "BMS_DATA" + arbitration_id = BMS_ARBITRATION_ID + temperature = [0,0,0,0,0,0] + error = 0 + + diff --git a/can/driver.py b/can/driver.py new file mode 100644 index 0000000..0ac8754 --- /dev/null +++ b/can/driver.py @@ -0,0 +1,24 @@ +import time +import can +bustype = 'socketcan_native' +channel = 'can0' + + +""""ID: the class of the data we are sending + This function sends a message over CAN with a specified class as labeled in config.py + +""" +def SEND_MESSAGE(message_type): + # define data object + send_data = [] + if message_type.classifer=="BMS_DATA": + send_data = [message_type.temperature[0], message_type.temperature[1], message_type.temperature[2], message_type.temperature[3],message_type.temperature[4],message_type.temperature[5], error] + # continue else if chains + bus=can.interface.Bus(channel=channel, bustype=bustype) + msg = can.Message(arbitration_id=message_type.arbitration_id, data=send_data) + bus.send(msg) + return True +def RECIEVE_MESSAGE(message_type): + return True + + From 97c02502f9706ad7cf5206f1a18ad45ca5267532 Mon Sep 17 00:00:00 2001 From: XanderHayhoe Date: Thu, 15 Feb 2024 20:36:36 -0500 Subject: [PATCH 02/50] fix typo --- can/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/config.py b/can/config.py index 9e4fd02..bc402c1 100644 --- a/can/config.py +++ b/can/config.py @@ -4,7 +4,7 @@ BMS_ARBITRATION_ID = 100 class BMS_DATA: - identifier = "BMS_DATA" + classifer = "BMS_DATA" arbitration_id = BMS_ARBITRATION_ID temperature = [0,0,0,0,0,0] error = 0 From 3b9dec25a20597874a222fe13c33552af39820d0 Mon Sep 17 00:00:00 2001 From: Ishani Munasinghe Date: Mon, 19 Feb 2024 18:07:53 -0500 Subject: [PATCH 03/50] edits need to review --- can/config.py | 25 +++++++++++++++++++++---- can/driver.py | 10 +++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/can/config.py b/can/config.py index bc402c1..8314f26 100644 --- a/can/config.py +++ b/can/config.py @@ -1,12 +1,29 @@ import time import can +import ctypes -BMS_ARBITRATION_ID = 100 - +BMS_CAN_ID = 100 +SENSORS_BOARD_CAN_ID class BMS_DATA: classifer = "BMS_DATA" - arbitration_id = BMS_ARBITRATION_ID - temperature = [0,0,0,0,0,0] + can_id = BMS_CAN_ID + temperature = [c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0)] # def these are 8 bits each error = 0 +# Define BMS instances +bms_data = BMS_DATA() +bms_data_warn = BMS_DATA() + +# Assign temp values for each instance +bms_data.temperature = [MUX1_TEMP, MUX2_TEMP, MUX3_TEMP, MUX4_TEMP, MUX5_TEMP, MUX6_TEMP] +bms_data_warn.temperature = [MUX1_TEMP_WARN, MUX2_TEMP_WARN, MUX3_TEMP_WARN, MUX4_TEMP_WARN, MUX5_TEMP_WARN, MUX6_TEMP_WARN] + + +class SENSORS_BOARD_DATA: + classifer = "SENSORS_BOARD_DATA" + can_id = SENSORS_BOARD_CAN_ID + temperature = [c_uint16(0), c_uint16(0)] + imu_data = c_uint16(0) + pressure_sensor_data = c_uint8(0) + error_code = c_uint8(0) \ No newline at end of file diff --git a/can/driver.py b/can/driver.py index 0ac8754..e253e0c 100644 --- a/can/driver.py +++ b/can/driver.py @@ -1,5 +1,12 @@ import time import can +import config +import ctypes +import struct + +# struct justification +# Python interpreter will sometimes add padding. we need to serialize into a string of bytes and then send to network + bustype = 'socketcan_native' channel = 'can0' @@ -13,7 +20,7 @@ def SEND_MESSAGE(message_type): send_data = [] if message_type.classifer=="BMS_DATA": send_data = [message_type.temperature[0], message_type.temperature[1], message_type.temperature[2], message_type.temperature[3],message_type.temperature[4],message_type.temperature[5], error] - # continue else if chains + # continue else-if chain bus=can.interface.Bus(channel=channel, bustype=bustype) msg = can.Message(arbitration_id=message_type.arbitration_id, data=send_data) bus.send(msg) @@ -22,3 +29,4 @@ def RECIEVE_MESSAGE(message_type): return True + From ccab0688e9d66b7d2515b6bef783f8f89cfc41b5 Mon Sep 17 00:00:00 2001 From: XanderHayhoe Date: Fri, 12 Apr 2024 18:47:23 -0400 Subject: [PATCH 04/50] minor fixes --- can/config.py | 24 ++++++++++-------------- can/driver.py | 3 ++- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/can/config.py b/can/config.py index 8314f26..2b2a8a9 100644 --- a/can/config.py +++ b/can/config.py @@ -2,28 +2,24 @@ import can import ctypes -BMS_CAN_ID = 100 -SENSORS_BOARD_CAN_ID class BMS_DATA: classifer = "BMS_DATA" - can_id = BMS_CAN_ID + can_id = 0 temperature = [c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0)] # def these are 8 bits each error = 0 -# Define BMS instances -bms_data = BMS_DATA() -bms_data_warn = BMS_DATA() - -# Assign temp values for each instance -bms_data.temperature = [MUX1_TEMP, MUX2_TEMP, MUX3_TEMP, MUX4_TEMP, MUX5_TEMP, MUX6_TEMP] -bms_data_warn.temperature = [MUX1_TEMP_WARN, MUX2_TEMP_WARN, MUX3_TEMP_WARN, MUX4_TEMP_WARN, MUX5_TEMP_WARN, MUX6_TEMP_WARN] - - class SENSORS_BOARD_DATA: classifer = "SENSORS_BOARD_DATA" - can_id = SENSORS_BOARD_CAN_ID + can_id = 0 temperature = [c_uint16(0), c_uint16(0)] imu_data = c_uint16(0) pressure_sensor_data = c_uint8(0) - error_code = c_uint8(0) \ No newline at end of file + error_code = c_uint8(0) + + + +class GLOBAL: + def GLOBAL(self): + self.BMS_CAN_ID=100 + self.SENSORS_BOARD_CAN_ID=50 \ No newline at end of file diff --git a/can/driver.py b/can/driver.py index e253e0c..e2227bc 100644 --- a/can/driver.py +++ b/can/driver.py @@ -3,7 +3,7 @@ import config import ctypes import struct - +from config import GLOBAL, BMS_DATA, SENSORS_BOARD_DATA # struct justification # Python interpreter will sometimes add padding. we need to serialize into a string of bytes and then send to network @@ -15,6 +15,7 @@ This function sends a message over CAN with a specified class as labeled in config.py """ + def SEND_MESSAGE(message_type): # define data object send_data = [] From c409f096622ab4fe833c79d6631ed918c2ee222f Mon Sep 17 00:00:00 2001 From: Mahesh Chandrasekhar Date: Fri, 12 Apr 2024 20:01:21 -0400 Subject: [PATCH 05/50] Completed config.py --- can/config.py | 110 ++++++++++++++++++++++++++++++++++++++++++++++---- can/driver.py | 8 +--- 2 files changed, 105 insertions(+), 13 deletions(-) diff --git a/can/config.py b/can/config.py index 2b2a8a9..a8c8c2b 100644 --- a/can/config.py +++ b/can/config.py @@ -1,13 +1,12 @@ import time import can -import ctypes +from ctypes import c_uint8, c_uint16, c_uint32 class BMS_DATA: classifer = "BMS_DATA" can_id = 0 - temperature = [c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0)] # def these are 8 bits each - error = 0 - + temperature = [c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0)] # def these are 8 bits each + error_code = 0 class SENSORS_BOARD_DATA: classifer = "SENSORS_BOARD_DATA" @@ -17,9 +16,106 @@ class SENSORS_BOARD_DATA: pressure_sensor_data = c_uint8(0) error_code = c_uint8(0) +class MOTOR_CONTROLLER_DATA: + classifier = "MOTOR_CONTROLLER_DATA" + can_id = 0 + battery_voltage = c_uint16(0) + battery_current = c_uint16(0) + motor_speed = c_uint16(0) + motor_controller_temp = c_uint8(0) + driving_direction = c_uint16(0) + error_code = c_uint8(0) + +class KELLY_DATA_FRAME1: + driving_direction_kelly = c_uint8(0) + motor_speed_kelly = c_uint16(0) + motor_error_code_kelly = c_uint8(0) +class KELLY_DATA_FRAME2: + battery_voltage_kelly = c_uint16(0) + battery_current_kelly = c_uint16(0) + motor_temp_kelly = c_uint16(0) + motor_controller_temp_kelly = c_uint16(0) class GLOBAL: - def GLOBAL(self): - self.BMS_CAN_ID=100 - self.SENSORS_BOARD_CAN_ID=50 \ No newline at end of file + def __init__(self): + # GENERAL DEFINES + MAX_CAN_PAYLOAD_BYTES = 8 + BUFF_SIZE = 32 + WARN_OFFSET = 0xFF + + # MOTOR CONTROLLER + MOTOR_CONTROLLER_1 = 0x10F8109A + MOTOR_CONTROLLER_2 = 0x10F8108D + MOTOR_CONTROLLER = 0xFF + MOTOR_CONTROLLER_WARN = MOTOR_CONTROLLER - WARN_OFFSET + + # BMS + BMS_BOARD = 0xFF + BMS_TEMP = BMS_BOARD + BMS_BOARD_WARN = BMS_TEMP - WARN_OFFSET + + # SENSORS + SENSOR_BOARD = 0xFF + SENSOR_BOARD_WARN = SENSOR_BOARD - WARN_OFFSET + +# THIS IS CONFIG.H FOR CROSS REFERENCE + +# #pragma once +# #include "can_driver.h" + +# // GENERAL DEFINES +# #define MAX_CAN_PAYLOAD_BTYES 8 +# #define BUFF_SIZE 32 +# #define WARN_OFFSET 0xFF + +# // MOTOR CONTROLLER +# #define MOTOR_CONTROLLER_1 0x10F8109A +# #define MOTOR_CONTROLLER_2 0x10F8108D +# #define MOTOR_CONTROLLER 0xFF +# #define MOTOR_CONTROLLER_WARN MOTOR_CONTROLLER - WARN_OFFSET +# // BMS +# #define BMS_BOARD 0xFF +# #define BMS_BOARD_WARN BMS_TEMP - WARN_OFFSET +# // SENSORS +# #define SENSOR_BOARD 0xFF +# #define SENSOR_BOARD_WARN SENSOR_BOARD - WARN_OFFSET + +# // BEGIN KELLY DEFS +# // FRAME 1 +# const DataSegment DRIVING_DIRECTION_K = {MOTOR_CONTROLLER_1, 1, 1}; +# const DataSegment MOTOR_SPEED_K = {MOTOR_CONTROLLER_1, 2, 3}; +# const DataSegment MOTOR_ERROR_CODE_K = {MOTOR_CONTROLLER_1, 4, 4}; +# // FRAME 2 +# const DataSegment BATTERY_VOLTAGE_K = {MOTOR_CONTROLLER_2, 1, 2}; +# const DataSegment BATTERY_CURRENT_K = {MOTOR_CONTROLLER_2, 3, 4}; +# const DataSegment MOTOR_TEMP_K = {MOTOR_CONTROLLER_2, 5, 6}; +# const DataSegment MOTOR_CONTROLLER_TEMP_K = {MOTOR_CONTROLLER_2, 7, 8}; +# // END KELLY DEFS + +# // BEGIN MOTOR CONTROLLER DEFS +# const DataSegment BATTERY_VOLTAGE = {MOTOR_CONTROLLER, 1, 2}; +# const DataSegment BATTERY_CURRENT = {MOTOR_CONTROLLER, 3, 4}; +# const DataSegment MOTOR_SPEED = {MOTOR_CONTROLLER, 5, 6}; +# const DataSegment MOTOR_CONTROLLER_TEMP = {MOTOR_CONTROLLER, 7, 7}; +# const DataSegment DRIVING_DIRECTION = {MOTOR_CONTROLLER, 8, 8}; +# const DataSegment MOTOR_ERROR_CODE = {MOTOR_CONTROLLER, 8, 8}; +# // END MOTOR CONTROLLER DEFS + +# // BEGIN BMS DEFS +# const DataSegment MUX1_TEMP = {BMS_BOARD, 1, 1}; +# const DataSegment MUX2_TEMP = {BMS_BOARD, 2, 2}; +# const DataSegment MUX3_TEMP = {BMS_BOARD, 3, 3}; +# const DataSegment MUX4_TEMP = {BMS_BOARD, 4, 4}; +# const DataSegment MUX5_TEMP = {BMS_BOARD, 5, 5}; +# const DataSegment MUX6_TEMP = {BMS_BOARD, 6, 6}; +# const DataSegment BMS_ERROR_CODE = {BMS_BOARD, 7, 7}; +# // END BMS DEFS + +# // BEGIN SENSORS BOARD DEFS +# const DataSegment PRESSURE_SENSOR_DATA = {SENSOR_BOARD, 1, 1}; +# const DataSegment IMU_DATA = {SENSOR_BOARD, 2, 3}; +# const DataSegment LIM_ONE_TEMP = {SENSOR_BOARD, 4, 5}; +# const DataSegment LIM_TWO_TEMP = {SENSOR_BOARD, 6, 7}; +# const DataSegment SENSORS_ERROR_CODE = {SENSOR_BOARD, 8, 8}; +# // END SENSORS BOARD DEFS \ No newline at end of file diff --git a/can/driver.py b/can/driver.py index e2227bc..a582e2c 100644 --- a/can/driver.py +++ b/can/driver.py @@ -1,19 +1,17 @@ import time import can import config -import ctypes +from ctypes import c_uint8, c_uint16, c_uint32 import struct -from config import GLOBAL, BMS_DATA, SENSORS_BOARD_DATA +from config import GLOBAL, BMS_DATA, SENSORS_BOARD_DATA, MOTOR_CONTROLLER_DATA, KELLY_DATA_FRAME1, KELLY_DATA_FRAME2 # struct justification # Python interpreter will sometimes add padding. we need to serialize into a string of bytes and then send to network bustype = 'socketcan_native' channel = 'can0' - """"ID: the class of the data we are sending This function sends a message over CAN with a specified class as labeled in config.py - """ def SEND_MESSAGE(message_type): @@ -29,5 +27,3 @@ def SEND_MESSAGE(message_type): def RECIEVE_MESSAGE(message_type): return True - - From 669e7489455feb5a51cae4685929112ce8371a32 Mon Sep 17 00:00:00 2001 From: Mahesh Chandrasekhar Date: Fri, 12 Apr 2024 20:13:06 -0400 Subject: [PATCH 06/50] added identifiers for kelly frames --- can/config.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/can/config.py b/can/config.py index a8c8c2b..4037520 100644 --- a/can/config.py +++ b/can/config.py @@ -27,11 +27,13 @@ class MOTOR_CONTROLLER_DATA: error_code = c_uint8(0) class KELLY_DATA_FRAME1: + classifier = "KELLY_DATA_FRAME_1" driving_direction_kelly = c_uint8(0) motor_speed_kelly = c_uint16(0) motor_error_code_kelly = c_uint8(0) class KELLY_DATA_FRAME2: + classifier = "KELLY_DATA_FRAME_2" battery_voltage_kelly = c_uint16(0) battery_current_kelly = c_uint16(0) motor_temp_kelly = c_uint16(0) From 76fc004d1b8f041add4810bb3630d3d4429fe314 Mon Sep 17 00:00:00 2001 From: Mahesh Chandrasekhar Date: Fri, 12 Apr 2024 22:53:21 -0400 Subject: [PATCH 07/50] okay Xander --- can/config.py | 7 ++----- can/driver.py | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/can/config.py b/can/config.py index 4037520..6b8edf6 100644 --- a/can/config.py +++ b/can/config.py @@ -3,13 +3,11 @@ from ctypes import c_uint8, c_uint16, c_uint32 class BMS_DATA: - classifer = "BMS_DATA" can_id = 0 temperature = [c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0)] # def these are 8 bits each error_code = 0 class SENSORS_BOARD_DATA: - classifer = "SENSORS_BOARD_DATA" can_id = 0 temperature = [c_uint16(0), c_uint16(0)] imu_data = c_uint16(0) @@ -17,7 +15,6 @@ class SENSORS_BOARD_DATA: error_code = c_uint8(0) class MOTOR_CONTROLLER_DATA: - classifier = "MOTOR_CONTROLLER_DATA" can_id = 0 battery_voltage = c_uint16(0) battery_current = c_uint16(0) @@ -27,13 +24,13 @@ class MOTOR_CONTROLLER_DATA: error_code = c_uint8(0) class KELLY_DATA_FRAME1: - classifier = "KELLY_DATA_FRAME_1" + can_id = 0 driving_direction_kelly = c_uint8(0) motor_speed_kelly = c_uint16(0) motor_error_code_kelly = c_uint8(0) class KELLY_DATA_FRAME2: - classifier = "KELLY_DATA_FRAME_2" + can_id = 0 battery_voltage_kelly = c_uint16(0) battery_current_kelly = c_uint16(0) motor_temp_kelly = c_uint16(0) diff --git a/can/driver.py b/can/driver.py index a582e2c..838d45c 100644 --- a/can/driver.py +++ b/can/driver.py @@ -18,7 +18,8 @@ def SEND_MESSAGE(message_type): # define data object send_data = [] if message_type.classifer=="BMS_DATA": - send_data = [message_type.temperature[0], message_type.temperature[1], message_type.temperature[2], message_type.temperature[3],message_type.temperature[4],message_type.temperature[5], error] + send_data = [message_type.temperature[0], message_type.temperature[1], message_type.temperature[2], message_type.temperature[3],message_type.temperature[4],message_type.temperature[5], message_type.error_code] + # continue else-if chain bus=can.interface.Bus(channel=channel, bustype=bustype) msg = can.Message(arbitration_id=message_type.arbitration_id, data=send_data) From e55c42907cb4e817117f584db2eef7ae33a6fa00 Mon Sep 17 00:00:00 2001 From: Mahesh Chandrasekhar Date: Mon, 22 Apr 2024 16:25:57 -0400 Subject: [PATCH 08/50] Preliminary CAN driver --- can/config.py | 25 ++++++++++++++++--------- can/driver.py | 41 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/can/config.py b/can/config.py index 6b8edf6..555ffb9 100644 --- a/can/config.py +++ b/can/config.py @@ -1,21 +1,28 @@ import time import can -from ctypes import c_uint8, c_uint16, c_uint32 +from ctypes import c_uint8, c_uint16 + +#assign CAN IDs to make code cleaner here +BMS_DATA_CAN_ID = 0 +SENSORS_BOARD_CAN_ID = 0 +MOTOR_CONTROLLER_CAN_ID = 0 +KELLY_DATA_FRAME1_CAN_ID = 0 +KELLY_DATA_FRAME2_CAN_ID = 0 class BMS_DATA: - can_id = 0 + can_id = BMS_DATA_CAN_ID temperature = [c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0)] # def these are 8 bits each error_code = 0 class SENSORS_BOARD_DATA: - can_id = 0 + can_id = SENSORS_BOARD_CAN_ID temperature = [c_uint16(0), c_uint16(0)] imu_data = c_uint16(0) pressure_sensor_data = c_uint8(0) error_code = c_uint8(0) class MOTOR_CONTROLLER_DATA: - can_id = 0 + can_id = MOTOR_CONTROLLER_CAN_ID battery_voltage = c_uint16(0) battery_current = c_uint16(0) motor_speed = c_uint16(0) @@ -24,13 +31,13 @@ class MOTOR_CONTROLLER_DATA: error_code = c_uint8(0) class KELLY_DATA_FRAME1: - can_id = 0 + can_id = KELLY_DATA_FRAME1_CAN_ID driving_direction_kelly = c_uint8(0) motor_speed_kelly = c_uint16(0) motor_error_code_kelly = c_uint8(0) class KELLY_DATA_FRAME2: - can_id = 0 + can_id = KELLY_DATA_FRAME2_CAN_ID battery_voltage_kelly = c_uint16(0) battery_current_kelly = c_uint16(0) motor_temp_kelly = c_uint16(0) @@ -44,18 +51,18 @@ def __init__(self): WARN_OFFSET = 0xFF # MOTOR CONTROLLER - MOTOR_CONTROLLER_1 = 0x10F8109A + MOTOR_CONTROLLER_1 = 0x10F8109A #make this either MOTOR_CONTROLLER_CAN_ID or KELLY_DATA_FRAME1_CAN_ID ?? MOTOR_CONTROLLER_2 = 0x10F8108D MOTOR_CONTROLLER = 0xFF MOTOR_CONTROLLER_WARN = MOTOR_CONTROLLER - WARN_OFFSET # BMS - BMS_BOARD = 0xFF + BMS_BOARD = BMS_DATA_CAN_ID BMS_TEMP = BMS_BOARD BMS_BOARD_WARN = BMS_TEMP - WARN_OFFSET # SENSORS - SENSOR_BOARD = 0xFF + SENSOR_BOARD = SENSORS_BOARD_CAN_ID SENSOR_BOARD_WARN = SENSOR_BOARD - WARN_OFFSET # THIS IS CONFIG.H FOR CROSS REFERENCE diff --git a/can/driver.py b/can/driver.py index 838d45c..4e62e2a 100644 --- a/can/driver.py +++ b/can/driver.py @@ -1,6 +1,5 @@ import time import can -import config from ctypes import c_uint8, c_uint16, c_uint32 import struct from config import GLOBAL, BMS_DATA, SENSORS_BOARD_DATA, MOTOR_CONTROLLER_DATA, KELLY_DATA_FRAME1, KELLY_DATA_FRAME2 @@ -17,10 +16,44 @@ def SEND_MESSAGE(message_type): # define data object send_data = [] - if message_type.classifer=="BMS_DATA": - send_data = [message_type.temperature[0], message_type.temperature[1], message_type.temperature[2], message_type.temperature[3],message_type.temperature[4],message_type.temperature[5], message_type.error_code] + if message_type.can_id == BMS_DATA.can_id: + send_data = [message_type.temperature[0], + message_type.temperature[1], + message_type.temperature[2], + message_type.temperature[3], + message_type.temperature[4], + message_type.temperature[5], + message_type.error_code] + + elif message_type.can_id == SENSORS_BOARD_DATA.can_id: + send_data = [message_type.temperature[0], + message_type.temperature[1], + message_type.imu_data, + message_type.pressure_sensor_data, + message_type.error_code] + + elif message_type.can_id == MOTOR_CONTROLLER_DATA.can_id: + send_data = [message_type.battery_voltage, + message_type.battery_current, + message_type.motor_speed, + message_type.motor_controller_temp, + message_type.driving_direction, + message_type.error_code] + + elif message_type.can_id == KELLY_DATA_FRAME1.can_id: + send_data = [message_type.driving_direction_kelly, + message_type.motor_speed_kelly, + message_type.motor_error_code_kelly] + + elif message_type.can_id == KELLY_DATA_FRAME2.can_id: + send_data = [message_type.battery_voltage_kelly, + message_type.battery_current_kelly, + message_type.motor_temp_kelly, + message_type.motor_controller_temp_kelly] + + else: + send_data = [] - # continue else-if chain bus=can.interface.Bus(channel=channel, bustype=bustype) msg = can.Message(arbitration_id=message_type.arbitration_id, data=send_data) bus.send(msg) From a874e5eb9def1118f975e8312762fdd5dff3648d Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Sat, 27 Apr 2024 11:08:02 -0400 Subject: [PATCH 09/50] Preliminary commit --- can/__pycache__/config.cpython-312.pyc | Bin 0 -> 2986 bytes can/__pycache__/driver.cpython-312.pyc | Bin 0 -> 2841 bytes can/config.py | 11 +++------ can/driver.py | 31 +++++++++++++++++++------ can/main.py | 26 +++++++++++++++++++++ 5 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 can/__pycache__/config.cpython-312.pyc create mode 100644 can/__pycache__/driver.cpython-312.pyc create mode 100644 can/main.py diff --git a/can/__pycache__/config.cpython-312.pyc b/can/__pycache__/config.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..98deb1fc1106037a7cfbe257cc7faf22c9eb0320 GIT binary patch literal 2986 zcmb_eO-vg{6rQ!$_WBQF{%pVrkdg*B2`-Tu+N4cuf=Ls=rZ#EI_GjyOH)I?CF}ox( z#S)crK&pD;5L7Nixg^RZ*Q%FRy;SYRs28(2v{FyGC8ZKoF711}i!lZ@Idr7?{N|gt zv+M7@c{9Iwy)FXH_Ve+p11*I7frFjKn#R^cFm4l(h)kC7#xKJ&Ft%hZIV*3?u{_HF z&)cBep*x^+(47`?fr!>yL}VXWjMaFT&e?#o*EqM%Ie_D8oJZ%Jz`1IiSLfWod1_pf z&Ut}rs&T#&6ZSpE7skUD&5;r2<-Gd3#u>)Y>5TC$26Egr=t|*iHA9j6NG#^CkcY)5`~l?K~x%kH&?IqnbUF&I__gt+0sZR;64~qG@%WN}5Zev_OSSL6q*3E&LzP-ilmS zB&tMm>1&d5Eix)8*VRHXax<+;G+O}c!s(OAv{JkRkCskO$q`sQk}2e`%Cm#T61Bq` zI(WcP-T=5os@~Aj*k<7H>fFl0o#A^!chB6v`Ec&R!necU4}Ev$hnqjm{kX7^;wvA0 z{A=oyO2?;5h52S7FUX8Aty~Ew}-*s17PArXY`U0!WS6?i> zyV-qYeQ51Wg$-`{gRB0Pt{qu%u|2Y4a$wsk0{oY(2g+Et4|on_bk@lVTe^Oq@a~3r zk1lijWMVpz6wW8&)5*ldL@Zgaw6{^|z&`Iru{Gb7v^NLN+T=0e6e$7pZ(h&d&;>Or?w}7xMI=00lrfiV%dZybXW> z>W2VzVD4XEO6(dfU8_SY$01Uom)4_emnv-MX0UhNzviy6?G2&A6%P*8J23OyP&w*C zfuX4nl~b4AKOUQyn9=nX#*)#=*pOLoT#d2^_j#H%#z=C^AuX^^EaAG8&6e~np!w@G zH+ZeXpms}<>EDq4J+L@M=!32t1weI=g1U!~uBX>Nudv;95+3Sbe{YT7V7rVBgwGwU z;S|g~SHpVEuxiwgUr^IiFRbaQJ(^`~l2Cdn3-o?XR7<`&_t zdLG&@Oe9946PX=P@FRHeVOnjy4*<6erp$Lh%MfTLHpe zja8)VRjqw8`k@}9sp!l^B04IJ%uL5pnsemx*qD&I$j3DI2hn6)NQ{l8V$)j7zFIYO z0C!4jZuEl}HP%F27hVL{0{t{HZV1z{$tkU=Mhd!<$2f~jKY#s5cTli`_0~6vrwraO zTV%%TC(+!L>EC%vC%4*2gzGBg;*|22U(|s-b~XCv0&3) zgqIQYON@Tp>LneEhrT29_ceUTGww~}9(In7fFI_rA_F|JG7R&GxE~SMZ=@dtYHeHc z!M&zJ+NxdM6%wd+hbkm!;5KVzI-e4NZI_J+JtY9!O%AjGwp&&}LaW)*o7!mbPJ=Xd9LkBrGH=jombDoJ7~o zP^4B0(j+!s#@mF11P?q6ZIAo`yz_#~q*QlELjoT97UNG#>tkn@mjDrAe1! zEa8i4qg=J7iO>bfNf%w5hy_UC+Cp|Vy+DN7#k@M7UQUydd}b-1&E?hEY&tjJ<>bZe zayF;VWtWz7*@cBnu1gQUpIKP=*um<1x%6TtNnW5PNW`oaH*~95sH)Y1RlcPY4)BE{ z)7uv+c=)mK+fz8YMG5!cI;z>avDi-46}>`7oxc$$lVec8pH1oo&k1YiyKz~(vbBkPn4 zkFq+ue->t*cD+0a>={pU5wKAgd$Pnr1^u4?>#kql3K9_Ytn1}TVBhdG7Xb@*=I{Xa z?ZX_LOb+Vu(YtAlyVmvdF7o7h(!(yYCic-gE_%d2?A_)qpA~o6^+^|b66%@uG#70$ zkA(dQ?51!1vTO0=Ci}40XBgBJW5Fd%Q|?l3*Fm)F?9z6z>xaLX4;toLp<2}|gkNcx zR=vW98@A|XpR>Nk08y=sCJWih-q5E)u2SeA~P>aAMEDwK4OC^j(Gs}>0vH4CPg zbzRqp+*OLTs)cKnijGxU0vXnD`Bu4FQnfPHi?nDQq|r~lz^fa2rP3tB&jsyKC%Tlk ziY|{sG?09#%-)=Rx>szEj&wuO(t6A*N7mglvaqK_gm;#XR|`d*u(J&l)2ohUnwwvQ z&4aDM^qvzAwor?4WWeaMDt%%^q-=MyS$K+sHO!JpA957Nvv(68nmRTUMqy1i*Anx( zxnb4niBAiVu~GwcZ8DxKnDrG{d^7$*IROPF=+^1@e7#8q-~~CaE@txi^tBAW2vLXN zXZ{Iis)c@wjI?g-@GrIbQ#OC<>$PucU)8qx_>TNqTaMdu{6WE%FYHLswlr=_;}34y zQsRGUW41Kb2?yl(7h)%Zf+yPIXmM%HK2`X}O z{I1v;crNIrb~I&2Q`=(737WL!q~m|Vmb^7N%%m+%I$*+pF9J_2>mBc+49uE)Ja?FmY1@nREKBfE6#G{lXt{FgwVb4 z-EdnNwT02|-uz+eXJPag;c{#4*I@YG*xj*jKWU%4YM;CMWAkzFW@~PT<3GRt+4Vd5 z+lxD)p*?uo=)l(tC7iDpdc^J{`2O-OEq{+<45r=Dq|GLZX#*rfxy;;+%tx91<1+

`qK8E{S7-u4T3iwByxc>maGFTh{ literal 0 HcmV?d00001 diff --git a/can/config.py b/can/config.py index 555ffb9..5acf97e 100644 --- a/can/config.py +++ b/can/config.py @@ -2,17 +2,11 @@ import can from ctypes import c_uint8, c_uint16 -#assign CAN IDs to make code cleaner here -BMS_DATA_CAN_ID = 0 -SENSORS_BOARD_CAN_ID = 0 -MOTOR_CONTROLLER_CAN_ID = 0 -KELLY_DATA_FRAME1_CAN_ID = 0 -KELLY_DATA_FRAME2_CAN_ID = 0 class BMS_DATA: can_id = BMS_DATA_CAN_ID - temperature = [c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0)] # def these are 8 bits each - error_code = 0 + temperature = [c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0)] + error_code = c_uint8(0) class SENSORS_BOARD_DATA: can_id = SENSORS_BOARD_CAN_ID @@ -21,6 +15,7 @@ class SENSORS_BOARD_DATA: pressure_sensor_data = c_uint8(0) error_code = c_uint8(0) +#this is going to be a problem. The 'data' part of a CAN message is a bytearray between 0 and 8 bytes. class MOTOR_CONTROLLER_DATA: can_id = MOTOR_CONTROLLER_CAN_ID battery_voltage = c_uint16(0) diff --git a/can/driver.py b/can/driver.py index 4e62e2a..a01abce 100644 --- a/can/driver.py +++ b/can/driver.py @@ -2,16 +2,33 @@ import can from ctypes import c_uint8, c_uint16, c_uint32 import struct -from config import GLOBAL, BMS_DATA, SENSORS_BOARD_DATA, MOTOR_CONTROLLER_DATA, KELLY_DATA_FRAME1, KELLY_DATA_FRAME2 -# struct justification -# Python interpreter will sometimes add padding. we need to serialize into a string of bytes and then send to network +from config import * -bustype = 'socketcan_native' -channel = 'can0' +#instantiate objects of all classes +global_vars = GLOBAL() +bms_data = BMS_DATA() +sensors_board_data = SENSORS_BOARD_DATA() +motor_controller_data = MOTOR_CONTROLLER_DATA() +kelly_data_frame1 = KELLY_DATA_FRAME1() +kelly_data_frame2 = KELLY_DATA_FRAME2() -""""ID: the class of the data we are sending - This function sends a message over CAN with a specified class as labeled in config.py +#assign CAN_IDs to all instantiated objects +bms_data.can_id = global_vars. +sensors_board_data.can_id = global_vars. +motor_controller_data.can_id = global_vars. +kelly_data_frame1.can_id = global_vars. +kelly_data_frame2.can_id = global_vars. + +#define send and receive functions +""" +FUNCTION: message receive routine +@ARG can_bus: passed can object +RETURN: none """ +def msg_rx_routine(can_bus): + rx_msg = can_bus.Message + print(rx_msg) + def SEND_MESSAGE(message_type): # define data object diff --git a/can/main.py b/can/main.py new file mode 100644 index 0000000..d60877b --- /dev/null +++ b/can/main.py @@ -0,0 +1,26 @@ +import can +import time +import os +from config import * +from driver import * + +def main(): + + #CANBUS init + os.system("sudo /sbin/ip link set can0 up type can bitrate 500000") #bring up can0 interface at 500kbps + time.sleep(0.05) + try: + CAN1 = can.interface.Bus(channel='can0', bustype='socketcan') #instance CAN object + except OSError: + print('Cannot find PiCAN board.') + exit() + print('Ready') + + #create listener and notifier + #(TODO: configure CAN connection (masks, etc)) + CAN1_listener = msg_rx_routine + CAN1_notifier = can.Notifier(CAN1, [CAN1_listener]) #assign listener to notifier + + +if __name__ == "__main__": + main() \ No newline at end of file From 43002d953deae297ee58a266a75df1082f1abe9d Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Sat, 27 Apr 2024 12:26:25 -0400 Subject: [PATCH 10/50] second commit --- can/config.py | 33 +++++++-------- can/driver.py | 114 ++++++++++++++++++++++++++++++-------------------- can/main.py | 6 ++- 3 files changed, 88 insertions(+), 65 deletions(-) diff --git a/can/config.py b/can/config.py index 5acf97e..75aa118 100644 --- a/can/config.py +++ b/can/config.py @@ -2,41 +2,40 @@ import can from ctypes import c_uint8, c_uint16 - class BMS_DATA: - can_id = BMS_DATA_CAN_ID + can_id = 0 temperature = [c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0)] error_code = c_uint8(0) class SENSORS_BOARD_DATA: - can_id = SENSORS_BOARD_CAN_ID - temperature = [c_uint16(0), c_uint16(0)] - imu_data = c_uint16(0) + can_id = 0 + temperature = [c_uint8(0), c_uint8(0)] + imu_data = c_uint8(0) pressure_sensor_data = c_uint8(0) error_code = c_uint8(0) #this is going to be a problem. The 'data' part of a CAN message is a bytearray between 0 and 8 bytes. class MOTOR_CONTROLLER_DATA: - can_id = MOTOR_CONTROLLER_CAN_ID - battery_voltage = c_uint16(0) - battery_current = c_uint16(0) - motor_speed = c_uint16(0) + can_id = 0 + battery_voltage = c_uint8(0) + battery_current = c_uint8(0) + motor_speed = c_uint8(0) motor_controller_temp = c_uint8(0) - driving_direction = c_uint16(0) + driving_direction = c_uint8(0) error_code = c_uint8(0) class KELLY_DATA_FRAME1: - can_id = KELLY_DATA_FRAME1_CAN_ID + can_id = 0 driving_direction_kelly = c_uint8(0) - motor_speed_kelly = c_uint16(0) + motor_speed_kelly = c_uint8(0) motor_error_code_kelly = c_uint8(0) class KELLY_DATA_FRAME2: - can_id = KELLY_DATA_FRAME2_CAN_ID - battery_voltage_kelly = c_uint16(0) - battery_current_kelly = c_uint16(0) - motor_temp_kelly = c_uint16(0) - motor_controller_temp_kelly = c_uint16(0) + can_id = 0 + battery_voltage_kelly = c_uint8(0) + battery_current_kelly = c_uint8(0) + motor_temp_kelly = c_uint8(0) + motor_controller_temp_kelly = c_uint8(0) class GLOBAL: def __init__(self): diff --git a/can/driver.py b/can/driver.py index a01abce..d9bf468 100644 --- a/can/driver.py +++ b/can/driver.py @@ -13,68 +13,90 @@ kelly_data_frame2 = KELLY_DATA_FRAME2() #assign CAN_IDs to all instantiated objects -bms_data.can_id = global_vars. -sensors_board_data.can_id = global_vars. -motor_controller_data.can_id = global_vars. -kelly_data_frame1.can_id = global_vars. -kelly_data_frame2.can_id = global_vars. +bms_data.can_id = global_vars.BMS_BOARD +sensors_board_data.can_id = global_vars.SENSOR_BOARD +motor_controller_data.can_id = global_vars.MOTOR_CONTROLLER: #CHECK this might be wrong +kelly_data_frame1.can_id = global_vars.MOTOR_CONTROLLER_1 +kelly_data_frame2.can_id = global_vars.MOTOR_CONTROLLER_2 #define send and receive functions """ -FUNCTION: message receive routine +FUNCTION: RECEIVE_MESSAGE @ARG can_bus: passed can object RETURN: none +WHAT IT DO? receives a message on the bus. Writes message data to the correct + instantiated object based on the message's arbitration ID """ -def msg_rx_routine(can_bus): +def RECEIVE_MESSAGE(can_bus): rx_msg = can_bus.Message print(rx_msg) + if rx_msg.arbitration_id == global_vars.BMS_BOARD: + -def SEND_MESSAGE(message_type): +""" +FUNCTION: CREATE_SEND_DATA +@ARG can_bus: +RETURN: data packet. Bytearray. +WHAT IT DO? Creates 'data' based on the arbitrationID + of the frame we wish to send. Reveals the current state of + the instantiated objects. +""" +def CREATE_SEND_DATA(arbitrationID): # define data object - send_data = [] - if message_type.can_id == BMS_DATA.can_id: - send_data = [message_type.temperature[0], - message_type.temperature[1], - message_type.temperature[2], - message_type.temperature[3], - message_type.temperature[4], - message_type.temperature[5], - message_type.error_code] + data = [] + if arbitrationID == global_vars.BMS_BOARD: + data = [bms_data.temperature[0], + bms_data.temperature[1], + bms_data.temperature[2], + bms_data.temperature[3], + bms_data.temperature[4], + bms_data.temperature[5], + bms_data.error_code, + 0] - elif message_type.can_id == SENSORS_BOARD_DATA.can_id: - send_data = [message_type.temperature[0], - message_type.temperature[1], - message_type.imu_data, - message_type.pressure_sensor_data, - message_type.error_code] + elif arbitrationID == global_vars.SENSOR_BOARD: + data = [sensors_board_data.temperature[0], + sensors_board_data.temperature[1], + sensors_board_data.imu_data, + sensors_board_data.pressure_sensor_data, + sensors_board_data.error_code, + 0, + 0, + 0] - elif message_type.can_id == MOTOR_CONTROLLER_DATA.can_id: - send_data = [message_type.battery_voltage, - message_type.battery_current, - message_type.motor_speed, - message_type.motor_controller_temp, - message_type.driving_direction, - message_type.error_code] + elif arbitrationID == global_vars.MOTOR_CONTROLLER: #CHECK this might be wrong + data = [motor_controller_data.battery_voltage, + motor_controller_data.battery_current, + motor_controller_data.motor_speed, + motor_controller_data.motor_controller_temp, + motor_controller_data.driving_direction, + motor_controller_data.error_code, + 0, + 0] - elif message_type.can_id == KELLY_DATA_FRAME1.can_id: - send_data = [message_type.driving_direction_kelly, - message_type.motor_speed_kelly, - message_type.motor_error_code_kelly] + elif arbitrationID == global_vars.MOTOR_CONTROLLER_1: + data = [kelly_data_frame1.driving_direction_kelly, + kelly_data_frame1.motor_speed_kelly, + kelly_data_frame1.motor_error_code_kelly, + 0, + 0, + 0, + 0] - elif message_type.can_id == KELLY_DATA_FRAME2.can_id: - send_data = [message_type.battery_voltage_kelly, - message_type.battery_current_kelly, - message_type.motor_temp_kelly, - message_type.motor_controller_temp_kelly] + elif arbitrationID == global_vars.MOTOR_CONTROLLER_2: + data = [kelly_data_frame2.battery_voltage_kelly, + kelly_data_frame2.battery_current_kelly, + kelly_data_frame2.motor_temp_kelly, + kelly_data_frame2.motor_controller_temp_kelly, + 0, + 0, + 0, + 0] else: - send_data = [] + data = [0, 0, 0, 0, 0, 0, 0, 0] + + return data - bus=can.interface.Bus(channel=channel, bustype=bustype) - msg = can.Message(arbitration_id=message_type.arbitration_id, data=send_data) - bus.send(msg) - return True -def RECIEVE_MESSAGE(message_type): - return True diff --git a/can/main.py b/can/main.py index d60877b..d65fd11 100644 --- a/can/main.py +++ b/can/main.py @@ -18,9 +18,11 @@ def main(): #create listener and notifier #(TODO: configure CAN connection (masks, etc)) - CAN1_listener = msg_rx_routine - CAN1_notifier = can.Notifier(CAN1, [CAN1_listener]) #assign listener to notifier + CAN1_listener = RECEIVE_MESSAGE + CAN1_notifier = can.Notifier(CAN1, [CAN1_listener]) #assign listener to notifier + #send and receive messages + msg_data = if __name__ == "__main__": main() \ No newline at end of file From 816b1b28d12ee67358dc33034710788557e157e5 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Sat, 27 Apr 2024 12:41:02 -0400 Subject: [PATCH 11/50] 95% done --- can/config.py | 6 +++--- can/driver.py | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/can/config.py b/can/config.py index 75aa118..ce805a0 100644 --- a/can/config.py +++ b/can/config.py @@ -51,12 +51,12 @@ def __init__(self): MOTOR_CONTROLLER_WARN = MOTOR_CONTROLLER - WARN_OFFSET # BMS - BMS_BOARD = BMS_DATA_CAN_ID - BMS_TEMP = BMS_BOARD + BMS_BOARD = 0 + BMS_TEMP = 0 BMS_BOARD_WARN = BMS_TEMP - WARN_OFFSET # SENSORS - SENSOR_BOARD = SENSORS_BOARD_CAN_ID + SENSOR_BOARD = 0 SENSOR_BOARD_WARN = SENSOR_BOARD - WARN_OFFSET # THIS IS CONFIG.H FOR CROSS REFERENCE diff --git a/can/driver.py b/can/driver.py index d9bf468..bb5b821 100644 --- a/can/driver.py +++ b/can/driver.py @@ -31,8 +31,42 @@ def RECEIVE_MESSAGE(can_bus): rx_msg = can_bus.Message print(rx_msg) + rx_data = rx_msg.data + if rx_msg.arbitration_id == global_vars.BMS_BOARD: - + bms_data.temperature[0]=rx_data[0] + bms_data.temperature[1]=rx_data[1] + bms_data.temperature[2]=rx_data[2] + bms_data.temperature[3]=rx_data[3] + bms_data.temperature[4]=rx_data[4] + bms_data.temperature[5]=rx_data[5] + bms_data.error_code = rx_data[6] + + elif rx_msg.arbitration_id == global_vars.SENSOR_BOARD: + sensors_board_data.temperature[0] = rx_data[0] + sensors_board_data.temperature[1] = rx_data[1] + sensors_board_data.imu_data = rx_data[2] + sensors_board_data.pressure_sensor_data = rx_data[3] + sensors_board_data.error_code = rx_data[4] + + elif rx_msg.arbitration_id == global_vars.MOTOR_CONTROLLER: #CHECK this might be wrong + motor_controller_data.battery_voltage = rx_data[0] + motor_controller_data.battery_current = rx_data[1] + motor_controller_data.motor_speed = rx_data[2] + motor_controller_data.motor_controller_temp = rx_data[3] + motor_controller_data.driving_direction = rx_data[4] + motor_controller_data.error_code = rx_data[5] + + elif rx_msg.arbitration_id == global_vars.MOTOR_CONTROLLER_1: + kelly_data_frame1.driving_direction_kelly = rx_data[0] + kelly_data_frame1.motor_speed_kelly = rx_data[1] + kelly_data_frame1.motor_error_code_kelly = rx_data[2] + + elif rx_msg.arbitration_id == global_vars.MOTOR_CONTROLLER_2: + kelly_data_frame2.battery_voltage_kelly = rx_data[0] + kelly_data_frame2.battery_current_kelly = rx_data[1] + kelly_data_frame2.motor_temp_kelly = rx_data[2] + kelly_data_frame2.motor_controller_temp_kelly = rx_data[3] """ FUNCTION: CREATE_SEND_DATA From 88b32c5edab7b64e36b570a41fb7bf98b4ba4baa Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Sat, 27 Apr 2024 14:55:54 -0400 Subject: [PATCH 12/50] inshallah --- can/config.py | 2 +- can/main.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/can/config.py b/can/config.py index ce805a0..dad9ace 100644 --- a/can/config.py +++ b/can/config.py @@ -14,7 +14,7 @@ class SENSORS_BOARD_DATA: pressure_sensor_data = c_uint8(0) error_code = c_uint8(0) -#this is going to be a problem. The 'data' part of a CAN message is a bytearray between 0 and 8 bytes. + class MOTOR_CONTROLLER_DATA: can_id = 0 battery_voltage = c_uint8(0) diff --git a/can/main.py b/can/main.py index d65fd11..9a50a48 100644 --- a/can/main.py +++ b/can/main.py @@ -22,7 +22,10 @@ def main(): CAN1_notifier = can.Notifier(CAN1, [CAN1_listener]) #assign listener to notifier #send and receive messages - msg_data = + # 1. send + msg_data = CREATE_SEND_DATA(0) + msg = can.Message(arbitration_id = 0x57, data = msg_data) + CAN1.send(msg) if __name__ == "__main__": main() \ No newline at end of file From 370d1c4679f2d405fe653b4658bf9656ff9a2803 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Sat, 27 Apr 2024 15:12:04 -0400 Subject: [PATCH 13/50] req.txt --- requirements.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..42ba688 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +can==0.0.0 +msgpack==1.0.8 +packaging==24.0 +python-can==4.3.1 +typing_extensions==4.11.0 +wrapt==1.16.0 From 3d0872bb978d1f7ff9c1af44b68aa03fbbe888f4 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 17:24:56 -0400 Subject: [PATCH 14/50] checkpoint --- can/config.py | 115 ++++++++++++++++++++++++++------------------------ can/driver.py | 2 +- 2 files changed, 61 insertions(+), 56 deletions(-) diff --git a/can/config.py b/can/config.py index dad9ace..de52d3a 100644 --- a/can/config.py +++ b/can/config.py @@ -7,35 +7,29 @@ class BMS_DATA: temperature = [c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0), c_uint8(0)] error_code = c_uint8(0) -class SENSORS_BOARD_DATA: +class SENSORS_1: #CONSISTS OF PRESSURE, LIM1, AND LIM2 can_id = 0 - temperature = [c_uint8(0), c_uint8(0)] - imu_data = c_uint8(0) - pressure_sensor_data = c_uint8(0) + pressure_sensor_data = c_uint16(0) + lim_temperature = [c_uint16(0), c_uint16(0)] error_code = c_uint8(0) +class SENSORS_2: #CONSISTS OF IMU + can_id = 0 + x_acceleration = c_uint16(0) + y_acceleration = c_uint16(0) + x_gyro = c_uint8(0) + y_gyro = c_uint8(0) + z_gyro = c_uint8(0) + error_code = c_uint8(0) class MOTOR_CONTROLLER_DATA: can_id = 0 - battery_voltage = c_uint8(0) - battery_current = c_uint8(0) - motor_speed = c_uint8(0) + battery_voltage = c_uint16(0) + battery_current = c_uint16(0) + motor_speed = c_uint16(0) motor_controller_temp = c_uint8(0) driving_direction = c_uint8(0) - error_code = c_uint8(0) - -class KELLY_DATA_FRAME1: - can_id = 0 - driving_direction_kelly = c_uint8(0) - motor_speed_kelly = c_uint8(0) - motor_error_code_kelly = c_uint8(0) - -class KELLY_DATA_FRAME2: - can_id = 0 - battery_voltage_kelly = c_uint8(0) - battery_current_kelly = c_uint8(0) - motor_temp_kelly = c_uint8(0) - motor_controller_temp_kelly = c_uint8(0) + error_code = c_uint8(0) #Note: the error code and driving direction are obtained from the same byte in the config.h datasegment. class GLOBAL: def __init__(self): @@ -45,8 +39,6 @@ def __init__(self): WARN_OFFSET = 0xFF # MOTOR CONTROLLER - MOTOR_CONTROLLER_1 = 0x10F8109A #make this either MOTOR_CONTROLLER_CAN_ID or KELLY_DATA_FRAME1_CAN_ID ?? - MOTOR_CONTROLLER_2 = 0x10F8108D MOTOR_CONTROLLER = 0xFF MOTOR_CONTROLLER_WARN = MOTOR_CONTROLLER - WARN_OFFSET @@ -55,9 +47,13 @@ def __init__(self): BMS_TEMP = 0 BMS_BOARD_WARN = BMS_TEMP - WARN_OFFSET - # SENSORS - SENSOR_BOARD = 0 - SENSOR_BOARD_WARN = SENSOR_BOARD - WARN_OFFSET + # SENSOR BOARD 1 + SENSOR_BOARD_1 = 0 + SENSOR_BOARD_1_WARN = SENSOR_BOARD_1 - WARN_OFFSET + + # SENSOR BOARD 2 + SENSOR_BOARD_2 = 0 + SENSOR_BOARD_2_WARN = SENSOR_BOARD_2 - WARN_OFFSET # THIS IS CONFIG.H FOR CROSS REFERENCE @@ -70,52 +66,61 @@ def __init__(self): # #define WARN_OFFSET 0xFF # // MOTOR CONTROLLER -# #define MOTOR_CONTROLLER_1 0x10F8109A -# #define MOTOR_CONTROLLER_2 0x10F8108D +# #define MOTOR_CONTROLLER_K1 0x10F8109A +# #define MOTOR_CONTROLLER_K2 0x10F8108D # #define MOTOR_CONTROLLER 0xFF # #define MOTOR_CONTROLLER_WARN MOTOR_CONTROLLER - WARN_OFFSET # // BMS # #define BMS_BOARD 0xFF # #define BMS_BOARD_WARN BMS_TEMP - WARN_OFFSET # // SENSORS -# #define SENSOR_BOARD 0xFF -# #define SENSOR_BOARD_WARN SENSOR_BOARD - WARN_OFFSET +# #define SENSOR_BOARD_1 0xFF +# #define SENSOR_BOARD_1_WARN SENSOR_BOARD_1 - WARN_OFFSET +# #define SENSOR_BOARD_2 0xFF +# #define SENSOR_BOARD_2_WARN SENSOR_BOARD_2 - WARN_OFFSET # // BEGIN KELLY DEFS # // FRAME 1 -# const DataSegment DRIVING_DIRECTION_K = {MOTOR_CONTROLLER_1, 1, 1}; -# const DataSegment MOTOR_SPEED_K = {MOTOR_CONTROLLER_1, 2, 3}; -# const DataSegment MOTOR_ERROR_CODE_K = {MOTOR_CONTROLLER_1, 4, 4}; +# const Data_Segment_t DRIVING_DIRECTION_K = {MOTOR_CONTROLLER_K1, 1, 1}; +# const Data_Segment_t MOTOR_SPEED_K = {MOTOR_CONTROLLER_K1, 2, 3}; +# const Data_Segment_t MOTOR_ERROR_CODE_K = {MOTOR_CONTROLLER_K1, 4, 4}; # // FRAME 2 -# const DataSegment BATTERY_VOLTAGE_K = {MOTOR_CONTROLLER_2, 1, 2}; -# const DataSegment BATTERY_CURRENT_K = {MOTOR_CONTROLLER_2, 3, 4}; -# const DataSegment MOTOR_TEMP_K = {MOTOR_CONTROLLER_2, 5, 6}; -# const DataSegment MOTOR_CONTROLLER_TEMP_K = {MOTOR_CONTROLLER_2, 7, 8}; +# const Data_Segment_t BATTERY_VOLTAGE_K = {MOTOR_CONTROLLER_K2, 1, 2}; +# const Data_Segment_t BATTERY_CURRENT_K = {MOTOR_CONTROLLER_K2, 3, 4}; +# const Data_Segment_t MOTOR_TEMP_K = {MOTOR_CONTROLLER_K2, 5, 6}; +# const Data_Segment_t MOTOR_CONTROLLER_TEMP_K = {MOTOR_CONTROLLER_K2, 7, 8}; # // END KELLY DEFS # // BEGIN MOTOR CONTROLLER DEFS -# const DataSegment BATTERY_VOLTAGE = {MOTOR_CONTROLLER, 1, 2}; -# const DataSegment BATTERY_CURRENT = {MOTOR_CONTROLLER, 3, 4}; -# const DataSegment MOTOR_SPEED = {MOTOR_CONTROLLER, 5, 6}; -# const DataSegment MOTOR_CONTROLLER_TEMP = {MOTOR_CONTROLLER, 7, 7}; -# const DataSegment DRIVING_DIRECTION = {MOTOR_CONTROLLER, 8, 8}; -# const DataSegment MOTOR_ERROR_CODE = {MOTOR_CONTROLLER, 8, 8}; +# const Data_Segment_t BATTERY_VOLTAGE = {MOTOR_CONTROLLER, 1, 2}; +# const Data_Segment_t BATTERY_CURRENT = {MOTOR_CONTROLLER, 3, 4}; +# const Data_Segment_t MOTOR_SPEED = {MOTOR_CONTROLLER, 5, 6}; +# const Data_Segment_t MOTOR_CONTROLLER_TEMP = {MOTOR_CONTROLLER, 7, 7}; +# const Data_Segment_t DRIVING_DIRECTION = {MOTOR_CONTROLLER, 8, 8}; +# const Data_Segment_t MOTOR_ERROR_CODE = {MOTOR_CONTROLLER, 8, 8}; # // END MOTOR CONTROLLER DEFS # // BEGIN BMS DEFS -# const DataSegment MUX1_TEMP = {BMS_BOARD, 1, 1}; -# const DataSegment MUX2_TEMP = {BMS_BOARD, 2, 2}; -# const DataSegment MUX3_TEMP = {BMS_BOARD, 3, 3}; -# const DataSegment MUX4_TEMP = {BMS_BOARD, 4, 4}; -# const DataSegment MUX5_TEMP = {BMS_BOARD, 5, 5}; -# const DataSegment MUX6_TEMP = {BMS_BOARD, 6, 6}; -# const DataSegment BMS_ERROR_CODE = {BMS_BOARD, 7, 7}; +# const Data_Segment_t MUX1_TEMP = {BMS_BOARD, 1, 1}; +# const Data_Segment_t MUX2_TEMP = {BMS_BOARD, 2, 2}; +# const Data_Segment_t MUX3_TEMP = {BMS_BOARD, 3, 3}; +# const Data_Segment_t MUX4_TEMP = {BMS_BOARD, 4, 4}; +# const Data_Segment_t MUX5_TEMP = {BMS_BOARD, 5, 5}; +# const Data_Segment_t MUX6_TEMP = {BMS_BOARD, 6, 6}; +# const Data_Segment_t BMS_ERROR_CODE = {BMS_BOARD, 8, 8}; # // END BMS DEFS # // BEGIN SENSORS BOARD DEFS -# const DataSegment PRESSURE_SENSOR_DATA = {SENSOR_BOARD, 1, 1}; -# const DataSegment IMU_DATA = {SENSOR_BOARD, 2, 3}; -# const DataSegment LIM_ONE_TEMP = {SENSOR_BOARD, 4, 5}; -# const DataSegment LIM_TWO_TEMP = {SENSOR_BOARD, 6, 7}; -# const DataSegment SENSORS_ERROR_CODE = {SENSOR_BOARD, 8, 8}; +# //FIRST FRAME +# const Data_Segment_t PRESSURE_SENSOR_DATA = {SENSOR_BOARD_1, 1, 2}; +# const Data_Segment_t LIM_ONE_TEMP = {SENSOR_BOARD_1, 3, 4}; +# const Data_Segment_t LIM_TWO_TEMP = {SENSOR_BOARD_1, 5, 6}; +# const Data_Segment_t SENSORS_ERROR_CODE_1 = {SENSOR_BOARD_1, 8, 8}; +# //SECOND (IMU) FRAME +# const Data_Segment_t X_ACCEL = {SENSOR_BOARD_2, 1, 2}; +# const Data_Segment_t Y_ACCEL = {SENSOR_BOARD_2, 3, 4}; +# const Data_Segment_t X_GYRO = {SENSOR_BOARD_2, 5, 5}; +# const Data_Segment_t Y_GYRO = {SENSOR_BOARD_2, 6, 6}; +# const Data_Segment_t Z_GYRO = {SENSOR_BOARD_2, 7, 7}; +# const Data_Segment_t SENSORS_ERROR_CODE_2 = {SENSOR_BOARD_2, 8, 8}; # // END SENSORS BOARD DEFS \ No newline at end of file diff --git a/can/driver.py b/can/driver.py index bb5b821..5e046d7 100644 --- a/can/driver.py +++ b/can/driver.py @@ -33,7 +33,7 @@ def RECEIVE_MESSAGE(can_bus): rx_data = rx_msg.data - if rx_msg.arbitration_id == global_vars.BMS_BOARD: + if rx_msg.arbitration_id == global_vars.BMS_BOARD : bms_data.temperature[0]=rx_data[0] bms_data.temperature[1]=rx_data[1] bms_data.temperature[2]=rx_data[2] From d2d207659861b404fabd6753a6ad0a785c4d769b Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 17:35:45 -0400 Subject: [PATCH 15/50] cleanup --- can/config.py | 26 ++++++++++++++------------ can/driver.py | 12 +++++------- can/main.py | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/can/config.py b/can/config.py index de52d3a..802935f 100644 --- a/can/config.py +++ b/can/config.py @@ -34,26 +34,28 @@ class MOTOR_CONTROLLER_DATA: class GLOBAL: def __init__(self): # GENERAL DEFINES - MAX_CAN_PAYLOAD_BYTES = 8 - BUFF_SIZE = 32 - WARN_OFFSET = 0xFF + self.MAX_CAN_PAYLOAD_BYTES = 8 + self.BUFF_SIZE = 32 + self.WARN_OFFSET = 0xFF + + #CAN ID DEFINES # MOTOR CONTROLLER - MOTOR_CONTROLLER = 0xFF - MOTOR_CONTROLLER_WARN = MOTOR_CONTROLLER - WARN_OFFSET + self.MOTOR_CONTROLLER = 0xFF + self.MOTOR_CONTROLLER_WARN = self.MOTOR_CONTROLLER - self.WARN_OFFSET # BMS - BMS_BOARD = 0 - BMS_TEMP = 0 - BMS_BOARD_WARN = BMS_TEMP - WARN_OFFSET + self.BMS_BOARD = 0 + self.BMS_BOARD_WARN = self.BMS_TEMP - self.WARN_OFFSET # SENSOR BOARD 1 - SENSOR_BOARD_1 = 0 - SENSOR_BOARD_1_WARN = SENSOR_BOARD_1 - WARN_OFFSET + self.SENSOR_BOARD_1 = 0 + self.SENSOR_BOARD_1_WARN = self.SENSOR_BOARD_1 - self.WARN_OFFSET # SENSOR BOARD 2 - SENSOR_BOARD_2 = 0 - SENSOR_BOARD_2_WARN = SENSOR_BOARD_2 - WARN_OFFSET + self.SENSOR_BOARD_2 = 0 + self.SENSOR_BOARD_2_WARN = self.SENSOR_BOARD_2 - self.WARN_OFFSET + # THIS IS CONFIG.H FOR CROSS REFERENCE diff --git a/can/driver.py b/can/driver.py index 5e046d7..a303b25 100644 --- a/can/driver.py +++ b/can/driver.py @@ -7,17 +7,15 @@ #instantiate objects of all classes global_vars = GLOBAL() bms_data = BMS_DATA() -sensors_board_data = SENSORS_BOARD_DATA() +sensors_1 = SENSORS_1() +sensors_2 = SENSORS_2() motor_controller_data = MOTOR_CONTROLLER_DATA() -kelly_data_frame1 = KELLY_DATA_FRAME1() -kelly_data_frame2 = KELLY_DATA_FRAME2() #assign CAN_IDs to all instantiated objects bms_data.can_id = global_vars.BMS_BOARD -sensors_board_data.can_id = global_vars.SENSOR_BOARD -motor_controller_data.can_id = global_vars.MOTOR_CONTROLLER: #CHECK this might be wrong -kelly_data_frame1.can_id = global_vars.MOTOR_CONTROLLER_1 -kelly_data_frame2.can_id = global_vars.MOTOR_CONTROLLER_2 +sensors_1.can_id = global_vars.SENSOR_BOARD_1 +sensors_2.can_id = global_vars.SENSOR_BOARD_2 +motor_controller_data.can_id = global_vars.MOTOR_CONTROLLER #define send and receive functions """ diff --git a/can/main.py b/can/main.py index 9a50a48..dd2fe65 100644 --- a/can/main.py +++ b/can/main.py @@ -10,7 +10,7 @@ def main(): os.system("sudo /sbin/ip link set can0 up type can bitrate 500000") #bring up can0 interface at 500kbps time.sleep(0.05) try: - CAN1 = can.interface.Bus(channel='can0', bustype='socketcan') #instance CAN object + CAN1 = can.interface.Bus(channel='can0', bustype='socketcan') #instantiate CAN object except OSError: print('Cannot find PiCAN board.') exit() From 9556e3522f273b905607c9a3f78e0f6ca3120ac3 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 17:59:03 -0400 Subject: [PATCH 16/50] cleanup --- can/driver.py | 71 ++++++++++++++++++--------------------------------- 1 file changed, 25 insertions(+), 46 deletions(-) diff --git a/can/driver.py b/can/driver.py index a303b25..5bace8c 100644 --- a/can/driver.py +++ b/can/driver.py @@ -31,7 +31,7 @@ def RECEIVE_MESSAGE(can_bus): rx_data = rx_msg.data - if rx_msg.arbitration_id == global_vars.BMS_BOARD : + if (rx_msg.arbitration_id == global_vars.BMS_BOARD) or (rx_msg.arbitration_id == global_vars.BMS_BOARD_WARN): bms_data.temperature[0]=rx_data[0] bms_data.temperature[1]=rx_data[1] bms_data.temperature[2]=rx_data[2] @@ -40,35 +40,31 @@ def RECEIVE_MESSAGE(can_bus): bms_data.temperature[5]=rx_data[5] bms_data.error_code = rx_data[6] - elif rx_msg.arbitration_id == global_vars.SENSOR_BOARD: + elif (rx_msg.arbitration_id == global_vars.SENSOR_BOARD_1) or (rx_msg.arbitration_id == global_vars.SENSOR_BOARD_1_WARN): + sensors_board_data.temperature[0] = rx_data[0] + sensors_board_data.temperature[1] = rx_data[1] + sensors_board_data.imu_data = rx_data[2] + sensors_board_data.pressure_sensor_data = rx_data[3] + sensors_board_data.error_code = rx_data[4] + + elif (rx_msg.arbitration_id == global_vars.SENSOR_BOARD_2) or (rx_msg.arbitration_id == global_vars.SENSOR_BOARD_2_WARN): sensors_board_data.temperature[0] = rx_data[0] sensors_board_data.temperature[1] = rx_data[1] sensors_board_data.imu_data = rx_data[2] sensors_board_data.pressure_sensor_data = rx_data[3] sensors_board_data.error_code = rx_data[4] - elif rx_msg.arbitration_id == global_vars.MOTOR_CONTROLLER: #CHECK this might be wrong + elif rx_msg.arbitration_id == global_vars.MOTOR_CONTROLLER: motor_controller_data.battery_voltage = rx_data[0] motor_controller_data.battery_current = rx_data[1] motor_controller_data.motor_speed = rx_data[2] motor_controller_data.motor_controller_temp = rx_data[3] motor_controller_data.driving_direction = rx_data[4] motor_controller_data.error_code = rx_data[5] - - elif rx_msg.arbitration_id == global_vars.MOTOR_CONTROLLER_1: - kelly_data_frame1.driving_direction_kelly = rx_data[0] - kelly_data_frame1.motor_speed_kelly = rx_data[1] - kelly_data_frame1.motor_error_code_kelly = rx_data[2] - - elif rx_msg.arbitration_id == global_vars.MOTOR_CONTROLLER_2: - kelly_data_frame2.battery_voltage_kelly = rx_data[0] - kelly_data_frame2.battery_current_kelly = rx_data[1] - kelly_data_frame2.motor_temp_kelly = rx_data[2] - kelly_data_frame2.motor_controller_temp_kelly = rx_data[3] - + """ FUNCTION: CREATE_SEND_DATA -@ARG can_bus: +@ARG arbitration_id RETURN: data packet. Bytearray. WHAT IT DO? Creates 'data' based on the arbitrationID of the frame we wish to send. Reveals the current state of @@ -77,7 +73,7 @@ def RECEIVE_MESSAGE(can_bus): def CREATE_SEND_DATA(arbitrationID): # define data object data = [] - if arbitrationID == global_vars.BMS_BOARD: + if (arbitrationID == global_vars.BMS_BOARD) or (arbitrationID == global_vars.BMS_BOARD_WARN): data = [bms_data.temperature[0], bms_data.temperature[1], bms_data.temperature[2], @@ -87,17 +83,19 @@ def CREATE_SEND_DATA(arbitrationID): bms_data.error_code, 0] - elif arbitrationID == global_vars.SENSOR_BOARD: - data = [sensors_board_data.temperature[0], - sensors_board_data.temperature[1], - sensors_board_data.imu_data, - sensors_board_data.pressure_sensor_data, - sensors_board_data.error_code, - 0, - 0, + elif (arbitrationID == global_vars.SENSOR_BOARD_1) or (arbitrationID == global_vars.SENSOR_BOARD_1_WARN): + data = [sensors_1.pressure_sensor_data & (0b11111111 << 8), + sensors_1.pressure_sensor_data & 0b11111111, + sensors_1.lim_temperature[0] & (0b11111111 << 8), + sensors_1.lim_temperature[0] & (0b11111111), + sensors_1.lim_temperature[1] & (0b11111111 << 8), + sensors_1.lim_temperature[1] & (0b11111111), + sensors_1.error_code, 0] - - elif arbitrationID == global_vars.MOTOR_CONTROLLER: #CHECK this might be wrong + elif (arbitrationID == global_vars.SENSOR_BOARD_2) or (arbitrationID == global_vars.SENSOR_BOARD_2_WARN): + data = [] + + elif (arbitrationID == global_vars.MOTOR_CONTROLLER) or (arbitrationID == global_vars.MOTOR_CONTROLLER_WARN): data = [motor_controller_data.battery_voltage, motor_controller_data.battery_current, motor_controller_data.motor_speed, @@ -107,25 +105,6 @@ def CREATE_SEND_DATA(arbitrationID): 0, 0] - elif arbitrationID == global_vars.MOTOR_CONTROLLER_1: - data = [kelly_data_frame1.driving_direction_kelly, - kelly_data_frame1.motor_speed_kelly, - kelly_data_frame1.motor_error_code_kelly, - 0, - 0, - 0, - 0] - - elif arbitrationID == global_vars.MOTOR_CONTROLLER_2: - data = [kelly_data_frame2.battery_voltage_kelly, - kelly_data_frame2.battery_current_kelly, - kelly_data_frame2.motor_temp_kelly, - kelly_data_frame2.motor_controller_temp_kelly, - 0, - 0, - 0, - 0] - else: data = [0, 0, 0, 0, 0, 0, 0, 0] From 2a6ce5c6cc83188e47b195ae16dcc8b38cdd283c Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 18:15:19 -0400 Subject: [PATCH 17/50] cleanup --- can/driver.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/can/driver.py b/can/driver.py index 5bace8c..41a9687 100644 --- a/can/driver.py +++ b/can/driver.py @@ -84,14 +84,23 @@ def CREATE_SEND_DATA(arbitrationID): 0] elif (arbitrationID == global_vars.SENSOR_BOARD_1) or (arbitrationID == global_vars.SENSOR_BOARD_1_WARN): - data = [sensors_1.pressure_sensor_data & (0b11111111 << 8), - sensors_1.pressure_sensor_data & 0b11111111, - sensors_1.lim_temperature[0] & (0b11111111 << 8), - sensors_1.lim_temperature[0] & (0b11111111), - sensors_1.lim_temperature[1] & (0b11111111 << 8), - sensors_1.lim_temperature[1] & (0b11111111), + + msb_pressure = bytes(sensors_1.pressure_sensor_data & (0b11111111 << 8)) + lsb_pressure = bytes(sensors_1.pressure_sensor_data & 0b11111111) + msb_lim_temp_0 = bytes(sensors_1.lim_temperature[0] & (0b11111111 << 8)) + lsb_lim_temp_0 = bytes(sensors_1.lim_temperature[0] & (0b11111111)) + msb_lim_temp_1 = bytes(sensors_1.lim_temperature[1] & (0b11111111 << 8)) + lsb_lim_temp_1 = bytes(sensors_1.lim_temperature[1] & (0b11111111)) + + data = [msb_pressure, + lsb_pressure, + msb_lim_temp_0, + lsb_lim_temp_0, + msb_lim_temp_1, + lsb_lim_temp_1, sensors_1.error_code, 0] + elif (arbitrationID == global_vars.SENSOR_BOARD_2) or (arbitrationID == global_vars.SENSOR_BOARD_2_WARN): data = [] From 17a633be40f0c10be07a8114559b8d37f662ae7c Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 18:23:58 -0400 Subject: [PATCH 18/50] cleanup --- can/driver.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/can/driver.py b/can/driver.py index 41a9687..9fdf29f 100644 --- a/can/driver.py +++ b/can/driver.py @@ -84,7 +84,7 @@ def CREATE_SEND_DATA(arbitrationID): 0] elif (arbitrationID == global_vars.SENSOR_BOARD_1) or (arbitrationID == global_vars.SENSOR_BOARD_1_WARN): - + msb_pressure = bytes(sensors_1.pressure_sensor_data & (0b11111111 << 8)) lsb_pressure = bytes(sensors_1.pressure_sensor_data & 0b11111111) msb_lim_temp_0 = bytes(sensors_1.lim_temperature[0] & (0b11111111 << 8)) @@ -102,9 +102,23 @@ def CREATE_SEND_DATA(arbitrationID): 0] elif (arbitrationID == global_vars.SENSOR_BOARD_2) or (arbitrationID == global_vars.SENSOR_BOARD_2_WARN): - data = [] + + msb_x_accel = bytes(sensors_2.x_acceleration & (0b11111111 << 8)) + lsb_x_accel = bytes(sensors_2.x_acceleration & (0b11111111)) + msb_y_accel = bytes(sensors_2.y_acceleration & (0b11111111 << 8)) + lsb_y_accel = bytes(sensors_2.y_acceleration & (0b11111111)) + + data = [msb_x_accel, + lsb_x_accel, + msb_y_accel, + lsb_y_accel, + sensors_2.x_gyro, + sensors_2.y_gyro, + sensors_2.z_gyro, + sensors_2.error_code] elif (arbitrationID == global_vars.MOTOR_CONTROLLER) or (arbitrationID == global_vars.MOTOR_CONTROLLER_WARN): + data = [motor_controller_data.battery_voltage, motor_controller_data.battery_current, motor_controller_data.motor_speed, From 46a1270420ad0b4a30c9e36ce1345c911e11b088 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 18:31:53 -0400 Subject: [PATCH 19/50] cleanup --- can/driver.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/can/driver.py b/can/driver.py index 9fdf29f..4d1e9c9 100644 --- a/can/driver.py +++ b/can/driver.py @@ -118,15 +118,23 @@ def CREATE_SEND_DATA(arbitrationID): sensors_2.error_code] elif (arbitrationID == global_vars.MOTOR_CONTROLLER) or (arbitrationID == global_vars.MOTOR_CONTROLLER_WARN): - - data = [motor_controller_data.battery_voltage, - motor_controller_data.battery_current, - motor_controller_data.motor_speed, + + msb_voltage = bytes(motor_controller_data.battery_voltage & (0b11111111 << 8)) + lsb_voltage = bytes(motor_controller_data.battery_voltage& (0b11111111)) + msb_current = bytes(motor_controller_data.battery_current & (0b11111111 << 8)) + lsb_current = bytes(motor_controller_data.battery_current & (0b11111111)) + msb_motor_speed = bytes(motor_controller_data.motor_speed & (0b11111111 << 8)) + lsb_motor_speed = bytes(motor_controller_data.motor_speed & (0b11111111)) + + data = [msb_voltage, + lsb_voltage, + msb_current, + lsb_current, + msb_motor_speed, + lsb_motor_speed, motor_controller_data.motor_controller_temp, - motor_controller_data.driving_direction, - motor_controller_data.error_code, - 0, - 0] + motor_controller_data.driving_direction + ] else: data = [0, 0, 0, 0, 0, 0, 0, 0] From 00b0479efc5e8dcc3eab15a69a7003f1f3cbf068 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 18:35:58 -0400 Subject: [PATCH 20/50] cleanup --- can/driver.py | 63 +++++++++++++++++++++++++-------------------------- can/main.py | 2 +- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/can/driver.py b/can/driver.py index 4d1e9c9..135d1c4 100644 --- a/can/driver.py +++ b/can/driver.py @@ -29,38 +29,38 @@ def RECEIVE_MESSAGE(can_bus): rx_msg = can_bus.Message print(rx_msg) - rx_data = rx_msg.data - - if (rx_msg.arbitration_id == global_vars.BMS_BOARD) or (rx_msg.arbitration_id == global_vars.BMS_BOARD_WARN): - bms_data.temperature[0]=rx_data[0] - bms_data.temperature[1]=rx_data[1] - bms_data.temperature[2]=rx_data[2] - bms_data.temperature[3]=rx_data[3] - bms_data.temperature[4]=rx_data[4] - bms_data.temperature[5]=rx_data[5] - bms_data.error_code = rx_data[6] + # rx_data = rx_msg.data + + # if (rx_msg.arbitration_id == global_vars.BMS_BOARD) or (rx_msg.arbitration_id == global_vars.BMS_BOARD_WARN): + # bms_data.temperature[0]=rx_data[0] + # bms_data.temperature[1]=rx_data[1] + # bms_data.temperature[2]=rx_data[2] + # bms_data.temperature[3]=rx_data[3] + # bms_data.temperature[4]=rx_data[4] + # bms_data.temperature[5]=rx_data[5] + # bms_data.error_code = rx_data[6] - elif (rx_msg.arbitration_id == global_vars.SENSOR_BOARD_1) or (rx_msg.arbitration_id == global_vars.SENSOR_BOARD_1_WARN): - sensors_board_data.temperature[0] = rx_data[0] - sensors_board_data.temperature[1] = rx_data[1] - sensors_board_data.imu_data = rx_data[2] - sensors_board_data.pressure_sensor_data = rx_data[3] - sensors_board_data.error_code = rx_data[4] + # elif (rx_msg.arbitration_id == global_vars.SENSOR_BOARD_1) or (rx_msg.arbitration_id == global_vars.SENSOR_BOARD_1_WARN): + # sensors_board_data.temperature[0] = rx_data[0] + # sensors_board_data.temperature[1] = rx_data[1] + # sensors_board_data.imu_data = rx_data[2] + # sensors_board_data.pressure_sensor_data = rx_data[3] + # sensors_board_data.error_code = rx_data[4] - elif (rx_msg.arbitration_id == global_vars.SENSOR_BOARD_2) or (rx_msg.arbitration_id == global_vars.SENSOR_BOARD_2_WARN): - sensors_board_data.temperature[0] = rx_data[0] - sensors_board_data.temperature[1] = rx_data[1] - sensors_board_data.imu_data = rx_data[2] - sensors_board_data.pressure_sensor_data = rx_data[3] - sensors_board_data.error_code = rx_data[4] - - elif rx_msg.arbitration_id == global_vars.MOTOR_CONTROLLER: - motor_controller_data.battery_voltage = rx_data[0] - motor_controller_data.battery_current = rx_data[1] - motor_controller_data.motor_speed = rx_data[2] - motor_controller_data.motor_controller_temp = rx_data[3] - motor_controller_data.driving_direction = rx_data[4] - motor_controller_data.error_code = rx_data[5] + # elif (rx_msg.arbitration_id == global_vars.SENSOR_BOARD_2) or (rx_msg.arbitration_id == global_vars.SENSOR_BOARD_2_WARN): + # sensors_board_data.temperature[0] = rx_data[0] + # sensors_board_data.temperature[1] = rx_data[1] + # sensors_board_data.imu_data = rx_data[2] + # sensors_board_data.pressure_sensor_data = rx_data[3] + # sensors_board_data.error_code = rx_data[4] + + # elif rx_msg.arbitration_id == global_vars.MOTOR_CONTROLLER: + # motor_controller_data.battery_voltage = rx_data[0] + # motor_controller_data.battery_current = rx_data[1] + # motor_controller_data.motor_speed = rx_data[2] + # motor_controller_data.motor_controller_temp = rx_data[3] + # motor_controller_data.driving_direction = rx_data[4] + # motor_controller_data.error_code = rx_data[5] """ FUNCTION: CREATE_SEND_DATA @@ -133,8 +133,7 @@ def CREATE_SEND_DATA(arbitrationID): msb_motor_speed, lsb_motor_speed, motor_controller_data.motor_controller_temp, - motor_controller_data.driving_direction - ] + motor_controller_data.driving_direction] else: data = [0, 0, 0, 0, 0, 0, 0, 0] diff --git a/can/main.py b/can/main.py index dd2fe65..cf8cb88 100644 --- a/can/main.py +++ b/can/main.py @@ -23,7 +23,7 @@ def main(): #send and receive messages # 1. send - msg_data = CREATE_SEND_DATA(0) + msg_data = [0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0] msg = can.Message(arbitration_id = 0x57, data = msg_data) CAN1.send(msg) From d9a26d2a0b693e26e6c8844b83392b1dab9d36bb Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 18:40:33 -0400 Subject: [PATCH 21/50] cleanup --- can/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/can/config.py b/can/config.py index 802935f..db1b4a4 100644 --- a/can/config.py +++ b/can/config.py @@ -46,7 +46,7 @@ def __init__(self): # BMS self.BMS_BOARD = 0 - self.BMS_BOARD_WARN = self.BMS_TEMP - self.WARN_OFFSET + self.BMS_BOARD_WARN = self.BMS_BOARD - self.WARN_OFFSET # SENSOR BOARD 1 self.SENSOR_BOARD_1 = 0 @@ -55,7 +55,7 @@ def __init__(self): # SENSOR BOARD 2 self.SENSOR_BOARD_2 = 0 self.SENSOR_BOARD_2_WARN = self.SENSOR_BOARD_2 - self.WARN_OFFSET - + # THIS IS CONFIG.H FOR CROSS REFERENCE From 9a7418bec27adc4a48ea0ecaeb52cb20f663df73 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 18:43:59 -0400 Subject: [PATCH 22/50] cleanup --- can/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/main.py b/can/main.py index cf8cb88..21ed68f 100644 --- a/can/main.py +++ b/can/main.py @@ -2,7 +2,7 @@ import time import os from config import * -from driver import * +from driver import RECEIVE_MESSAGE, CREATE_SEND_DATA def main(): From 11e6a82251052517e4c7bd09d00aa6aac7f71073 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 18:45:28 -0400 Subject: [PATCH 23/50] cleanup --- can/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/main.py b/can/main.py index 21ed68f..1c9833a 100644 --- a/can/main.py +++ b/can/main.py @@ -26,6 +26,6 @@ def main(): msg_data = [0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0] msg = can.Message(arbitration_id = 0x57, data = msg_data) CAN1.send(msg) - + os.system("sudo ip link set can0 down") if __name__ == "__main__": main() \ No newline at end of file From 0b8b6f0a1ee0f27fc5e2c5f047c75b1ef790daea Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 18:49:26 -0400 Subject: [PATCH 24/50] cleanup --- can/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/can/main.py b/can/main.py index 1c9833a..368c452 100644 --- a/can/main.py +++ b/can/main.py @@ -18,8 +18,8 @@ def main(): #create listener and notifier #(TODO: configure CAN connection (masks, etc)) - CAN1_listener = RECEIVE_MESSAGE - CAN1_notifier = can.Notifier(CAN1, [CAN1_listener]) #assign listener to notifier + CAN1_listener = RECEIVE_MESSAGE + CAN1_notifier = can.Notifier(CAN1, [CAN1_listener, CAN1]) #assign listener to notifier #send and receive messages # 1. send From 984f31ecb4047fb50aa946d8f7120b795c7945dc Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 18:57:15 -0400 Subject: [PATCH 25/50] cleanup --- can/driver.py | 6 +++-- can/main.py | 63 +++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/can/driver.py b/can/driver.py index 135d1c4..176087e 100644 --- a/can/driver.py +++ b/can/driver.py @@ -26,8 +26,10 @@ instantiated object based on the message's arbitration ID """ def RECEIVE_MESSAGE(can_bus): - rx_msg = can_bus.Message - print(rx_msg) + rx_msg = can_bus.recv() + print (rx_msg) + # rx_msg = can_bus.Message + # print(rx_msg) # rx_data = rx_msg.data diff --git a/can/main.py b/can/main.py index 368c452..f83a296 100644 --- a/can/main.py +++ b/can/main.py @@ -1,31 +1,66 @@ +# import can +# import time +# import os +# from config import * +# from driver import RECEIVE_MESSAGE, CREATE_SEND_DATA + +# def main(): + +# #CANBUS init +# os.system("sudo /sbin/ip link set can0 up type can bitrate 500000") #bring up can0 interface at 500kbps +# time.sleep(0.05) +# try: +# CAN1 = can.interface.Bus(channel='can0', bustype='socketcan') #instantiate CAN object +# except OSError: +# print('Cannot find PiCAN board.') +# exit() +# print('Ready') + +# #create listener and notifier +# #(TODO: configure CAN connection (masks, etc)) +# CAN1_listener = RECEIVE_MESSAGE +# CAN1_notifier = can.Notifier(CAN1, [CAN1_listener]) #assign listener to notifier + +# #send and receive messages +# # 1. send +# msg_data = [0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0] +# msg = can.Message(arbitration_id = 0x57, data = msg_data) +# CAN1.send(msg) +# os.system("sudo ip link set can0 down") + +# if __name__ == "__main__": +# main() + + import can import time import os from config import * -from driver import RECEIVE_MESSAGE, CREATE_SEND_DATA +class MessageListener(can.Listener): + def on_message_received(self, msg): + print(f'Received message: {msg}') def main(): - - #CANBUS init - os.system("sudo /sbin/ip link set can0 up type can bitrate 500000") #bring up can0 interface at 500kbps + os.system("sudo /sbin/ip link set can0 up type can bitrate 500000") # Bring up can0 interface at 500kbps time.sleep(0.05) try: - CAN1 = can.interface.Bus(channel='can0', bustype='socketcan') #instantiate CAN object + CAN1 = can.interface.Bus(channel='can0', bustype='socketcan') # Instantiate CAN object except OSError: - print('Cannot find PiCAN board.') - exit() - print('Ready') + print('Cannot find PiCAN board.') + exit() + print('Ready') - #create listener and notifier - #(TODO: configure CAN connection (masks, etc)) - CAN1_listener = RECEIVE_MESSAGE - CAN1_notifier = can.Notifier(CAN1, [CAN1_listener, CAN1]) #assign listener to notifier + CAN1_listener = MessageListener() + CAN1_notifier = can.Notifier(CAN1, [CAN1_listener]) # Assign listener to notifier - #send and receive messages - # 1. send msg_data = [0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0] msg = can.Message(arbitration_id = 0x57, data = msg_data) + CAN1.send(msg) + time.sleep(1) # Allow some time for message handling + CAN1_notifier.stop() + os.system("sudo ip link set can0 down") + if __name__ == "__main__": main() \ No newline at end of file From 744d8d66ec7c39d8ed5985f0dab2cf4695ba3d5b Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 18:58:34 -0400 Subject: [PATCH 26/50] cleanup --- can/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/can/main.py b/can/main.py index f83a296..50c6425 100644 --- a/can/main.py +++ b/can/main.py @@ -57,10 +57,10 @@ def main(): msg = can.Message(arbitration_id = 0x57, data = msg_data) CAN1.send(msg) - time.sleep(1) # Allow some time for message handling + time.sleep(0.001) # Allow some time for message handling CAN1_notifier.stop() os.system("sudo ip link set can0 down") - + if __name__ == "__main__": main() \ No newline at end of file From f9910f9978a3d9e5c50607026bab70e5e428bc21 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:00:16 -0400 Subject: [PATCH 27/50] cleanup --- can/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/main.py b/can/main.py index 50c6425..91e800d 100644 --- a/can/main.py +++ b/can/main.py @@ -53,7 +53,7 @@ def main(): CAN1_listener = MessageListener() CAN1_notifier = can.Notifier(CAN1, [CAN1_listener]) # Assign listener to notifier - msg_data = [0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0] + msg_data = [0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0] msg = can.Message(arbitration_id = 0x57, data = msg_data) CAN1.send(msg) From a7659f1d4775be515e56c4e8d92dcf08e20902f1 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:01:16 -0400 Subject: [PATCH 28/50] cleanup --- can/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/main.py b/can/main.py index 91e800d..229a905 100644 --- a/can/main.py +++ b/can/main.py @@ -53,7 +53,7 @@ def main(): CAN1_listener = MessageListener() CAN1_notifier = can.Notifier(CAN1, [CAN1_listener]) # Assign listener to notifier - msg_data = [0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0] + msg_data = [byte(0xF0), byte(0xF0), byte(0xF0), byte(0xF0)] msg = can.Message(arbitration_id = 0x57, data = msg_data) CAN1.send(msg) From 61cdaf126eabfbbac9808ed32ed840e562bdf4c2 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:01:48 -0400 Subject: [PATCH 29/50] cleanup --- can/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/main.py b/can/main.py index 229a905..0bb4575 100644 --- a/can/main.py +++ b/can/main.py @@ -53,7 +53,7 @@ def main(): CAN1_listener = MessageListener() CAN1_notifier = can.Notifier(CAN1, [CAN1_listener]) # Assign listener to notifier - msg_data = [byte(0xF0), byte(0xF0), byte(0xF0), byte(0xF0)] + msg_data = [bytes(0xF0), bytes(0xF0), bytes(0xF0), bytes(0xF0)] msg = can.Message(arbitration_id = 0x57, data = msg_data) CAN1.send(msg) From 398d8677b1942a547ece2191a45531d711db4eab Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:02:34 -0400 Subject: [PATCH 30/50] cleanup --- can/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/main.py b/can/main.py index 0bb4575..210e0ba 100644 --- a/can/main.py +++ b/can/main.py @@ -53,7 +53,7 @@ def main(): CAN1_listener = MessageListener() CAN1_notifier = can.Notifier(CAN1, [CAN1_listener]) # Assign listener to notifier - msg_data = [bytes(0xF0), bytes(0xF0), bytes(0xF0), bytes(0xF0)] + msg_data = [(0xF0), (0xF0), (0xF0), (0xF0)] msg = can.Message(arbitration_id = 0x57, data = msg_data) CAN1.send(msg) From 1439e1f5ea946d294820101f5b3302fc8b042c90 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:03:32 -0400 Subject: [PATCH 31/50] cleanup --- can/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/main.py b/can/main.py index 210e0ba..aa62364 100644 --- a/can/main.py +++ b/can/main.py @@ -54,7 +54,7 @@ def main(): CAN1_notifier = can.Notifier(CAN1, [CAN1_listener]) # Assign listener to notifier msg_data = [(0xF0), (0xF0), (0xF0), (0xF0)] - msg = can.Message(arbitration_id = 0x57, data = msg_data) + msg = can.Message(arbitration_id = 0x57, data = msg_data, is_extended_id = False) CAN1.send(msg) time.sleep(0.001) # Allow some time for message handling From 5c1037cace706f45bbe45ffd19b2ef3231f367d5 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:07:40 -0400 Subject: [PATCH 32/50] cleanup --- can/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/can/main.py b/can/main.py index aa62364..9e7187e 100644 --- a/can/main.py +++ b/can/main.py @@ -58,7 +58,9 @@ def main(): CAN1.send(msg) time.sleep(0.001) # Allow some time for message handling + CAN1_notifier.stop() + CAN1.shutdown() os.system("sudo ip link set can0 down") From cc69f2ad337dd605f1328b3ae13dae2fc3a382b4 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:08:51 -0400 Subject: [PATCH 33/50] cleanup --- can/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/can/main.py b/can/main.py index 9e7187e..8270059 100644 --- a/can/main.py +++ b/can/main.py @@ -42,6 +42,7 @@ def on_message_received(self, msg): def main(): os.system("sudo /sbin/ip link set can0 up type can bitrate 500000") # Bring up can0 interface at 500kbps + os.system("sudo /sbin/ip link set can1 up type can bitrate 500000") time.sleep(0.05) try: CAN1 = can.interface.Bus(channel='can0', bustype='socketcan') # Instantiate CAN object From e6254e5b4a2479bc0a1ac9234b126e8e935066d3 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:09:22 -0400 Subject: [PATCH 34/50] cleanup --- can/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/main.py b/can/main.py index 8270059..95e77f5 100644 --- a/can/main.py +++ b/can/main.py @@ -43,7 +43,7 @@ def on_message_received(self, msg): def main(): os.system("sudo /sbin/ip link set can0 up type can bitrate 500000") # Bring up can0 interface at 500kbps os.system("sudo /sbin/ip link set can1 up type can bitrate 500000") - time.sleep(0.05) + time.sleep(1) try: CAN1 = can.interface.Bus(channel='can0', bustype='socketcan') # Instantiate CAN object except OSError: From f52754fc1cebbac101629bb78d40e0ebc0878b57 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:11:11 -0400 Subject: [PATCH 35/50] cleanup --- can/main.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/can/main.py b/can/main.py index 95e77f5..0f935ee 100644 --- a/can/main.py +++ b/can/main.py @@ -10,7 +10,7 @@ # os.system("sudo /sbin/ip link set can0 up type can bitrate 500000") #bring up can0 interface at 500kbps # time.sleep(0.05) # try: -# CAN1 = can.interface.Bus(channel='can0', bustype='socketcan') #instantiate CAN object +# CAN0 = can.interface.Bus(channel='can0', bustype='socketcan') #instantiate CAN object # except OSError: # print('Cannot find PiCAN board.') # exit() @@ -18,14 +18,14 @@ # #create listener and notifier # #(TODO: configure CAN connection (masks, etc)) -# CAN1_listener = RECEIVE_MESSAGE -# CAN1_notifier = can.Notifier(CAN1, [CAN1_listener]) #assign listener to notifier +# CAN0_listener = RECEIVE_MESSAGE +# CAN0_notifier = can.Notifier(CAN0, [CAN0_listener]) #assign listener to notifier # #send and receive messages # # 1. send # msg_data = [0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0] # msg = can.Message(arbitration_id = 0x57, data = msg_data) -# CAN1.send(msg) +# CAN0.send(msg) # os.system("sudo ip link set can0 down") # if __name__ == "__main__": @@ -41,27 +41,27 @@ def on_message_received(self, msg): print(f'Received message: {msg}') def main(): - os.system("sudo /sbin/ip link set can0 up type can bitrate 500000") # Bring up can0 interface at 500kbps - os.system("sudo /sbin/ip link set can1 up type can bitrate 500000") + os.system("sudo ip link set can0 up type can bitrate 500000") # Bring up can0 interface at 500kbps + os.system("sudo ip link set can1 up type can bitrate 500000") time.sleep(1) try: - CAN1 = can.interface.Bus(channel='can0', bustype='socketcan') # Instantiate CAN object + CAN0 = can.interface.Bus(channel='can0', bustype='socketcan') # Instantiate CAN object except OSError: print('Cannot find PiCAN board.') exit() print('Ready') - CAN1_listener = MessageListener() - CAN1_notifier = can.Notifier(CAN1, [CAN1_listener]) # Assign listener to notifier + CAN0_listener = MessageListener() + CAN0_notifier = can.Notifier(CAN0, [CAN0_listener]) # Assign listener to notifier msg_data = [(0xF0), (0xF0), (0xF0), (0xF0)] msg = can.Message(arbitration_id = 0x57, data = msg_data, is_extended_id = False) - CAN1.send(msg) + CAN0.send(msg) time.sleep(0.001) # Allow some time for message handling - CAN1_notifier.stop() - CAN1.shutdown() + CAN0_notifier.stop() + CAN0.shutdown() os.system("sudo ip link set can0 down") From 95d7241f22f8bfadac86dcf79c476cb83bafc086 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:11:47 -0400 Subject: [PATCH 36/50] cleanup --- can/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/can/main.py b/can/main.py index 0f935ee..eb1f36e 100644 --- a/can/main.py +++ b/can/main.py @@ -42,8 +42,8 @@ def on_message_received(self, msg): def main(): os.system("sudo ip link set can0 up type can bitrate 500000") # Bring up can0 interface at 500kbps - os.system("sudo ip link set can1 up type can bitrate 500000") - time.sleep(1) + # os.system("sudo ip link set can1 up type can bitrate 500000") + time.sleep(0.05) try: CAN0 = can.interface.Bus(channel='can0', bustype='socketcan') # Instantiate CAN object except OSError: From 2e46391b1b8e21e5748e8554b27dfdaf0e322a53 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:14:12 -0400 Subject: [PATCH 37/50] cleanup --- can/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/can/main.py b/can/main.py index eb1f36e..6160f66 100644 --- a/can/main.py +++ b/can/main.py @@ -42,7 +42,7 @@ def on_message_received(self, msg): def main(): os.system("sudo ip link set can0 up type can bitrate 500000") # Bring up can0 interface at 500kbps - # os.system("sudo ip link set can1 up type can bitrate 500000") + os.system("sudo ip link set can1 up type can bitrate 500000") time.sleep(0.05) try: CAN0 = can.interface.Bus(channel='can0', bustype='socketcan') # Instantiate CAN object @@ -58,12 +58,13 @@ def main(): msg = can.Message(arbitration_id = 0x57, data = msg_data, is_extended_id = False) CAN0.send(msg) - time.sleep(0.001) # Allow some time for message handling + time.sleep(0.01) # Allow some time for message handling CAN0_notifier.stop() CAN0.shutdown() os.system("sudo ip link set can0 down") + os.system("sudo ip link set can1 down") if __name__ == "__main__": main() \ No newline at end of file From 8bd03a9636775195929cffce1b5b9eb52476db7f Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:16:03 -0400 Subject: [PATCH 38/50] cleanup --- can/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/main.py b/can/main.py index 6160f66..7a8370c 100644 --- a/can/main.py +++ b/can/main.py @@ -42,7 +42,7 @@ def on_message_received(self, msg): def main(): os.system("sudo ip link set can0 up type can bitrate 500000") # Bring up can0 interface at 500kbps - os.system("sudo ip link set can1 up type can bitrate 500000") + #os.system("sudo ip link set can1 up type can bitrate 500000") time.sleep(0.05) try: CAN0 = can.interface.Bus(channel='can0', bustype='socketcan') # Instantiate CAN object From d75fb345a0432709dfbad82686c0202cb6dc9adf Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:17:15 -0400 Subject: [PATCH 39/50] cleanup --- can/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/main.py b/can/main.py index 7a8370c..da0c364 100644 --- a/can/main.py +++ b/can/main.py @@ -58,7 +58,7 @@ def main(): msg = can.Message(arbitration_id = 0x57, data = msg_data, is_extended_id = False) CAN0.send(msg) - time.sleep(0.01) # Allow some time for message handling + time.sleep(0.001) # Allow some time for message handling CAN0_notifier.stop() CAN0.shutdown() From 0e95865fe703cfde39927c1cb6fcc253dc4c3d68 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:18:21 -0400 Subject: [PATCH 40/50] cleanup --- can/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/main.py b/can/main.py index da0c364..6dd93ff 100644 --- a/can/main.py +++ b/can/main.py @@ -56,7 +56,7 @@ def main(): msg_data = [(0xF0), (0xF0), (0xF0), (0xF0)] msg = can.Message(arbitration_id = 0x57, data = msg_data, is_extended_id = False) - + print(f"MESSAGE: {msg}") CAN0.send(msg) time.sleep(0.001) # Allow some time for message handling From ccc641a229ec55c588dba08bb294a6872fb51601 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:18:59 -0400 Subject: [PATCH 41/50] cleanup --- can/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/main.py b/can/main.py index 6dd93ff..c580a0d 100644 --- a/can/main.py +++ b/can/main.py @@ -56,7 +56,7 @@ def main(): msg_data = [(0xF0), (0xF0), (0xF0), (0xF0)] msg = can.Message(arbitration_id = 0x57, data = msg_data, is_extended_id = False) - print(f"MESSAGE: {msg}") + print(f"MESSAGE: {msg} \n") CAN0.send(msg) time.sleep(0.001) # Allow some time for message handling From 19f936d2ecb214675e180179ee604dbbc3c987f1 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:24:18 -0400 Subject: [PATCH 42/50] cleanup --- can/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/main.py b/can/main.py index c580a0d..f514b35 100644 --- a/can/main.py +++ b/can/main.py @@ -43,7 +43,7 @@ def on_message_received(self, msg): def main(): os.system("sudo ip link set can0 up type can bitrate 500000") # Bring up can0 interface at 500kbps #os.system("sudo ip link set can1 up type can bitrate 500000") - time.sleep(0.05) + time.sleep(10) try: CAN0 = can.interface.Bus(channel='can0', bustype='socketcan') # Instantiate CAN object except OSError: From 345327ee33c55a74c790c44b494303c9f980dd83 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:25:08 -0400 Subject: [PATCH 43/50] cleanup --- can/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/main.py b/can/main.py index f514b35..93a0f2d 100644 --- a/can/main.py +++ b/can/main.py @@ -58,7 +58,7 @@ def main(): msg = can.Message(arbitration_id = 0x57, data = msg_data, is_extended_id = False) print(f"MESSAGE: {msg} \n") CAN0.send(msg) - time.sleep(0.001) # Allow some time for message handling + time.sleep(0.5) # Allow some time for message handling CAN0_notifier.stop() CAN0.shutdown() From a836b233f9336450bf31faa241a3b4e1b4a4430e Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:38:41 -0400 Subject: [PATCH 44/50] cleanup --- can/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/main.py b/can/main.py index 93a0f2d..4441240 100644 --- a/can/main.py +++ b/can/main.py @@ -45,7 +45,7 @@ def main(): #os.system("sudo ip link set can1 up type can bitrate 500000") time.sleep(10) try: - CAN0 = can.interface.Bus(channel='can0', bustype='socketcan') # Instantiate CAN object + CAN0 = can.interface.Bus(channel='can0', bustype='socketcan', loopback = True) # Instantiate CAN object except OSError: print('Cannot find PiCAN board.') exit() From 43bda2e43073af48d10cceca3b39cfb4c7723169 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:39:37 -0400 Subject: [PATCH 45/50] cleanup --- can/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/can/main.py b/can/main.py index 4441240..9c4ee23 100644 --- a/can/main.py +++ b/can/main.py @@ -43,7 +43,7 @@ def on_message_received(self, msg): def main(): os.system("sudo ip link set can0 up type can bitrate 500000") # Bring up can0 interface at 500kbps #os.system("sudo ip link set can1 up type can bitrate 500000") - time.sleep(10) + time.sleep(0.05) try: CAN0 = can.interface.Bus(channel='can0', bustype='socketcan', loopback = True) # Instantiate CAN object except OSError: @@ -58,7 +58,7 @@ def main(): msg = can.Message(arbitration_id = 0x57, data = msg_data, is_extended_id = False) print(f"MESSAGE: {msg} \n") CAN0.send(msg) - time.sleep(0.5) # Allow some time for message handling + time.sleep(0.001) # Allow some time for message handling CAN0_notifier.stop() CAN0.shutdown() From 1f08e46fec7cf52e44185bd13886bbea35eecbd2 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:40:54 -0400 Subject: [PATCH 46/50] cleanup --- can/main.py | 116 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 49 deletions(-) diff --git a/can/main.py b/can/main.py index 9c4ee23..31a3ce8 100644 --- a/can/main.py +++ b/can/main.py @@ -1,70 +1,88 @@ +# # import can +# # import time +# # import os +# # from config import * +# # from driver import RECEIVE_MESSAGE, CREATE_SEND_DATA + +# # def main(): + +# # #CANBUS init +# # os.system("sudo /sbin/ip link set can0 up type can bitrate 500000") #bring up can0 interface at 500kbps +# # time.sleep(0.05) +# # try: +# # CAN0 = can.interface.Bus(channel='can0', bustype='socketcan') #instantiate CAN object +# # except OSError: +# # print('Cannot find PiCAN board.') +# # exit() +# # print('Ready') + +# # #create listener and notifier +# # #(TODO: configure CAN connection (masks, etc)) +# # CAN0_listener = RECEIVE_MESSAGE +# # CAN0_notifier = can.Notifier(CAN0, [CAN0_listener]) #assign listener to notifier + +# # #send and receive messages +# # # 1. send +# # msg_data = [0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0] +# # msg = can.Message(arbitration_id = 0x57, data = msg_data) +# # CAN0.send(msg) +# # os.system("sudo ip link set can0 down") + +# # if __name__ == "__main__": +# # main() + + # import can # import time # import os # from config import * -# from driver import RECEIVE_MESSAGE, CREATE_SEND_DATA +# class MessageListener(can.Listener): +# def on_message_received(self, msg): +# print(f'Received message: {msg}') # def main(): - -# #CANBUS init -# os.system("sudo /sbin/ip link set can0 up type can bitrate 500000") #bring up can0 interface at 500kbps +# os.system("sudo ip link set can0 up type can bitrate 500000") # Bring up can0 interface at 500kbps +# #os.system("sudo ip link set can1 up type can bitrate 500000") # time.sleep(0.05) # try: -# CAN0 = can.interface.Bus(channel='can0', bustype='socketcan') #instantiate CAN object +# CAN0 = can.interface.Bus(channel='can0', bustype='socketcan', loopback = True) # Instantiate CAN object # except OSError: -# print('Cannot find PiCAN board.') -# exit() -# print('Ready') +# print('Cannot find PiCAN board.') +# exit() +# print('Ready') -# #create listener and notifier -# #(TODO: configure CAN connection (masks, etc)) -# CAN0_listener = RECEIVE_MESSAGE -# CAN0_notifier = can.Notifier(CAN0, [CAN0_listener]) #assign listener to notifier +# CAN0_listener = MessageListener() +# CAN0_notifier = can.Notifier(CAN0, [CAN0_listener]) # Assign listener to notifier -# #send and receive messages -# # 1. send -# msg_data = [0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0] -# msg = can.Message(arbitration_id = 0x57, data = msg_data) +# msg_data = [(0xF0), (0xF0), (0xF0), (0xF0)] +# msg = can.Message(arbitration_id = 0x57, data = msg_data, is_extended_id = False) +# print(f"MESSAGE: {msg} \n") # CAN0.send(msg) +# time.sleep(0.001) # Allow some time for message handling + +# CAN0_notifier.stop() +# CAN0.shutdown() + # os.system("sudo ip link set can0 down") +# os.system("sudo ip link set can1 down") # if __name__ == "__main__": # main() - import can -import time -import os -from config import * -class MessageListener(can.Listener): - def on_message_received(self, msg): - print(f'Received message: {msg}') - def main(): - os.system("sudo ip link set can0 up type can bitrate 500000") # Bring up can0 interface at 500kbps - #os.system("sudo ip link set can1 up type can bitrate 500000") - time.sleep(0.05) - try: - CAN0 = can.interface.Bus(channel='can0', bustype='socketcan', loopback = True) # Instantiate CAN object - except OSError: - print('Cannot find PiCAN board.') - exit() - print('Ready') - - CAN0_listener = MessageListener() - CAN0_notifier = can.Notifier(CAN0, [CAN0_listener]) # Assign listener to notifier - - msg_data = [(0xF0), (0xF0), (0xF0), (0xF0)] - msg = can.Message(arbitration_id = 0x57, data = msg_data, is_extended_id = False) - print(f"MESSAGE: {msg} \n") - CAN0.send(msg) - time.sleep(0.001) # Allow some time for message handling - - CAN0_notifier.stop() - CAN0.shutdown() - - os.system("sudo ip link set can0 down") - os.system("sudo ip link set can1 down") - + # Setup the CAN bus in loopback mode + can_interface = 'can0' + bus = can.interface.Bus(channel=can_interface, bustype='socketcan', loopback=True) + # Send a message + message = can.Message(arbitration_id=0x123, data=[0x11, 0x22, 0x33], is_extended_id=False) + bus.send(message) + # Receive the message + received_message = bus.recv(10) # Timeout in seconds + if received_message: + print(f"Received message: {received_message}") + else: + print("No message received.") + bus.shutdown() if __name__ == "__main__": main() \ No newline at end of file From a83ef6318b68af99c206d8a9a278a3cdb752f097 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:48:58 -0400 Subject: [PATCH 47/50] cleanup --- can/main.py | 94 ++++++++++++++++++++++++++--------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/can/main.py b/can/main.py index 31a3ce8..13be5d3 100644 --- a/can/main.py +++ b/can/main.py @@ -32,57 +32,57 @@ # # main() -# import can -# import time -# import os -# from config import * -# class MessageListener(can.Listener): -# def on_message_received(self, msg): -# print(f'Received message: {msg}') - -# def main(): -# os.system("sudo ip link set can0 up type can bitrate 500000") # Bring up can0 interface at 500kbps -# #os.system("sudo ip link set can1 up type can bitrate 500000") -# time.sleep(0.05) -# try: -# CAN0 = can.interface.Bus(channel='can0', bustype='socketcan', loopback = True) # Instantiate CAN object -# except OSError: -# print('Cannot find PiCAN board.') -# exit() -# print('Ready') +import can +import time +import os +from config import * +class MessageListener(can.Listener): + def on_message_received(self, msg): + print(f'Received message: {msg}') -# CAN0_listener = MessageListener() -# CAN0_notifier = can.Notifier(CAN0, [CAN0_listener]) # Assign listener to notifier +def main(): + os.system("sudo ip link set can0 up type can bitrate 500000") # Bring up can0 interface at 500kbps + #os.system("sudo ip link set can1 up type can bitrate 500000") + time.sleep(0.05) + try: + CAN0 = can.interface.Bus(channel='can0', bustype='socketcan', loopback = True) # Instantiate CAN object + except OSError: + print('Cannot find PiCAN board.') + exit() + print('Ready') -# msg_data = [(0xF0), (0xF0), (0xF0), (0xF0)] -# msg = can.Message(arbitration_id = 0x57, data = msg_data, is_extended_id = False) -# print(f"MESSAGE: {msg} \n") -# CAN0.send(msg) -# time.sleep(0.001) # Allow some time for message handling + CAN0_listener = MessageListener() + CAN0_notifier = can.Notifier(CAN0, [CAN0_listener]) # Assign listener to notifier -# CAN0_notifier.stop() -# CAN0.shutdown() + msg_data = [(0xF0), (0xF0), (0xF0), (0xF0)] + msg = can.Message(arbitration_id = 0x57, data = msg_data, is_extended_id = False) + print(f"MESSAGE: {msg} \n") + CAN0.send(msg) + time.sleep(0.001) # Allow some time for message handling -# os.system("sudo ip link set can0 down") -# os.system("sudo ip link set can1 down") + CAN0_notifier.stop() + CAN0.shutdown() -# if __name__ == "__main__": -# main() + os.system("sudo ip link set can0 down") + os.system("sudo ip link set can1 down") -import can -def main(): - # Setup the CAN bus in loopback mode - can_interface = 'can0' - bus = can.interface.Bus(channel=can_interface, bustype='socketcan', loopback=True) - # Send a message - message = can.Message(arbitration_id=0x123, data=[0x11, 0x22, 0x33], is_extended_id=False) - bus.send(message) - # Receive the message - received_message = bus.recv(10) # Timeout in seconds - if received_message: - print(f"Received message: {received_message}") - else: - print("No message received.") - bus.shutdown() if __name__ == "__main__": - main() \ No newline at end of file + main() + +# import can +# def main(): +# # Setup the CAN bus in loopback mode +# can_interface = 'can0' +# bus = can.interface.Bus(channel=can_interface, bustype='socketcan', loopback=True) +# # Send a message +# message = can.Message(arbitration_id=0x123, data=[0x11, 0x22, 0x33], is_extended_id=False) +# bus.send(message) +# # Receive the message +# received_message = bus.recv(10) # Timeout in seconds +# if received_message: +# print(f"Received message: {received_message}") +# else: +# print("No message received.") +# bus.shutdown() +# if __name__ == "__main__": +# main() \ No newline at end of file From 0f3a2bc946ac3a76d635eefe9132b04f747698a9 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 19:54:33 -0400 Subject: [PATCH 48/50] cleanup --- can/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/main.py b/can/main.py index 13be5d3..33137ac 100644 --- a/can/main.py +++ b/can/main.py @@ -45,7 +45,7 @@ def main(): #os.system("sudo ip link set can1 up type can bitrate 500000") time.sleep(0.05) try: - CAN0 = can.interface.Bus(channel='can0', bustype='socketcan', loopback = True) # Instantiate CAN object + CAN0 = can.interface.Bus(channel='can0', bustype='socketcan', loopback = True, receive_own_messages=True ) # Instantiate CAN object except OSError: print('Cannot find PiCAN board.') exit() From eb98baa7ca29ad86b1689df27e783b5fd7a6b920 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 22:09:48 -0400 Subject: [PATCH 49/50] cleanup --- can/driver.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/can/driver.py b/can/driver.py index 176087e..1526af8 100644 --- a/can/driver.py +++ b/can/driver.py @@ -87,12 +87,12 @@ def CREATE_SEND_DATA(arbitrationID): elif (arbitrationID == global_vars.SENSOR_BOARD_1) or (arbitrationID == global_vars.SENSOR_BOARD_1_WARN): - msb_pressure = bytes(sensors_1.pressure_sensor_data & (0b11111111 << 8)) - lsb_pressure = bytes(sensors_1.pressure_sensor_data & 0b11111111) - msb_lim_temp_0 = bytes(sensors_1.lim_temperature[0] & (0b11111111 << 8)) - lsb_lim_temp_0 = bytes(sensors_1.lim_temperature[0] & (0b11111111)) - msb_lim_temp_1 = bytes(sensors_1.lim_temperature[1] & (0b11111111 << 8)) - lsb_lim_temp_1 = bytes(sensors_1.lim_temperature[1] & (0b11111111)) + msb_pressure = (sensors_1.pressure_sensor_data & (0b11111111 << 8)) + lsb_pressure = (sensors_1.pressure_sensor_data & 0b11111111) + msb_lim_temp_0 = (sensors_1.lim_temperature[0] & (0b11111111 << 8)) + lsb_lim_temp_0 = (sensors_1.lim_temperature[0] & (0b11111111)) + msb_lim_temp_1 = (sensors_1.lim_temperature[1] & (0b11111111 << 8)) + lsb_lim_temp_1 = (sensors_1.lim_temperature[1] & (0b11111111)) data = [msb_pressure, lsb_pressure, @@ -105,10 +105,10 @@ def CREATE_SEND_DATA(arbitrationID): elif (arbitrationID == global_vars.SENSOR_BOARD_2) or (arbitrationID == global_vars.SENSOR_BOARD_2_WARN): - msb_x_accel = bytes(sensors_2.x_acceleration & (0b11111111 << 8)) - lsb_x_accel = bytes(sensors_2.x_acceleration & (0b11111111)) - msb_y_accel = bytes(sensors_2.y_acceleration & (0b11111111 << 8)) - lsb_y_accel = bytes(sensors_2.y_acceleration & (0b11111111)) + msb_x_accel = (sensors_2.x_acceleration & (0b11111111 << 8)) + lsb_x_accel = (sensors_2.x_acceleration & (0b11111111)) + msb_y_accel = (sensors_2.y_acceleration & (0b11111111 << 8)) + lsb_y_accel = (sensors_2.y_acceleration & (0b11111111)) data = [msb_x_accel, lsb_x_accel, @@ -121,12 +121,12 @@ def CREATE_SEND_DATA(arbitrationID): elif (arbitrationID == global_vars.MOTOR_CONTROLLER) or (arbitrationID == global_vars.MOTOR_CONTROLLER_WARN): - msb_voltage = bytes(motor_controller_data.battery_voltage & (0b11111111 << 8)) - lsb_voltage = bytes(motor_controller_data.battery_voltage& (0b11111111)) - msb_current = bytes(motor_controller_data.battery_current & (0b11111111 << 8)) - lsb_current = bytes(motor_controller_data.battery_current & (0b11111111)) - msb_motor_speed = bytes(motor_controller_data.motor_speed & (0b11111111 << 8)) - lsb_motor_speed = bytes(motor_controller_data.motor_speed & (0b11111111)) + msb_voltage = (motor_controller_data.battery_voltage & (0b11111111 << 8)) + lsb_voltage = (motor_controller_data.battery_voltage& (0b11111111)) + msb_current = (motor_controller_data.battery_current & (0b11111111 << 8)) + lsb_current = (motor_controller_data.battery_current & (0b11111111)) + msb_motor_speed = (motor_controller_data.motor_speed & (0b11111111 << 8)) + lsb_motor_speed = (motor_controller_data.motor_speed & (0b11111111)) data = [msb_voltage, lsb_voltage, From d9b73f65566695bf41c614c10d01c536057a15b5 Mon Sep 17 00:00:00 2001 From: Mahesh Pranav Chandrasekhar Date: Fri, 3 May 2024 22:13:04 -0400 Subject: [PATCH 50/50] cleanup --- can/driver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/driver.py b/can/driver.py index 1526af8..5214621 100644 --- a/can/driver.py +++ b/can/driver.py @@ -56,7 +56,7 @@ def RECEIVE_MESSAGE(can_bus): # sensors_board_data.pressure_sensor_data = rx_data[3] # sensors_board_data.error_code = rx_data[4] - # elif rx_msg.arbitration_id == global_vars.MOTOR_CONTROLLER: + # elif (rx_msg.arbitration_id == global_vars.MOTOR_CONTROLLER) or (rx_msg.arbitration_id == global_vars.MOTOR_CONTROLLER_WARN): # motor_controller_data.battery_voltage = rx_data[0] # motor_controller_data.battery_current = rx_data[1] # motor_controller_data.motor_speed = rx_data[2]