Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
91e76a7
init
XanderHayhoe Feb 16, 2024
97c0250
fix typo
XanderHayhoe Feb 16, 2024
3b9dec2
edits need to review
ishanimunasinghe Feb 19, 2024
ccab068
minor fixes
XanderHayhoe Apr 12, 2024
c409f09
Completed config.py
Apr 13, 2024
669e748
added identifiers for kelly frames
Apr 13, 2024
76fc004
okay Xander
Apr 13, 2024
e55c429
Preliminary CAN driver
Apr 22, 2024
a874e5e
Preliminary commit
Apr 27, 2024
43002d9
second commit
Apr 27, 2024
816b1b2
95% done
Apr 27, 2024
88b32c5
inshallah
Apr 27, 2024
370d1c4
req.txt
Apr 27, 2024
3d0872b
checkpoint
May 3, 2024
d2d2076
cleanup
May 3, 2024
9556e35
cleanup
May 3, 2024
2a6ce5c
cleanup
May 3, 2024
17a633b
cleanup
May 3, 2024
46a1270
cleanup
May 3, 2024
00b0479
cleanup
May 3, 2024
d9a26d2
cleanup
May 3, 2024
9a7418b
cleanup
May 3, 2024
11e6a82
cleanup
May 3, 2024
0b8b6f0
cleanup
May 3, 2024
984f31e
cleanup
May 3, 2024
744d8d6
cleanup
May 3, 2024
f9910f9
cleanup
May 3, 2024
a7659f1
cleanup
May 3, 2024
61cdaf1
cleanup
May 3, 2024
398d867
cleanup
May 3, 2024
1439e1f
cleanup
May 3, 2024
5c1037c
cleanup
May 3, 2024
cc69f2a
cleanup
May 3, 2024
e6254e5
cleanup
May 3, 2024
f52754f
cleanup
May 3, 2024
95d7241
cleanup
May 3, 2024
2e46391
cleanup
May 3, 2024
8bd03a9
cleanup
May 3, 2024
d75fb34
cleanup
May 3, 2024
0e95865
cleanup
May 3, 2024
ccc641a
cleanup
May 3, 2024
19f936d
cleanup
May 3, 2024
345327e
cleanup
May 3, 2024
a836b23
cleanup
May 3, 2024
43bda2e
cleanup
May 3, 2024
1f08e46
cleanup
May 3, 2024
a83ef63
cleanup
May 3, 2024
0f3a2bc
cleanup
May 3, 2024
eb98baa
cleanup
May 4, 2024
d9b73f6
cleanup
May 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions can/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import time
import can
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)
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:
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)
motor_controller_temp_kelly = c_uint16(0)

class GLOBAL:
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
29 changes: 29 additions & 0 deletions can/driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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
# 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):
# 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 chain
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