-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/86dregyk6/can driver #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
XanderHayhoe
wants to merge
50
commits into
master
Choose a base branch
from
feature/86dregyk6/can-driver
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
91e76a7
init
XanderHayhoe 97c0250
fix typo
XanderHayhoe 3b9dec2
edits need to review
ishanimunasinghe ccab068
minor fixes
XanderHayhoe c409f09
Completed config.py
669e748
added identifiers for kelly frames
76fc004
okay Xander
e55c429
Preliminary CAN driver
a874e5e
Preliminary commit
43002d9
second commit
816b1b2
95% done
88b32c5
inshallah
370d1c4
req.txt
3d0872b
checkpoint
d2d2076
cleanup
9556e35
cleanup
2a6ce5c
cleanup
17a633b
cleanup
46a1270
cleanup
00b0479
cleanup
d9a26d2
cleanup
9a7418b
cleanup
11e6a82
cleanup
0b8b6f0
cleanup
984f31e
cleanup
744d8d6
cleanup
f9910f9
cleanup
a7659f1
cleanup
61cdaf1
cleanup
398d867
cleanup
1439e1f
cleanup
5c1037c
cleanup
cc69f2a
cleanup
e6254e5
cleanup
f52754f
cleanup
95d7241
cleanup
2e46391
cleanup
8bd03a9
cleanup
d75fb34
cleanup
0e95865
cleanup
ccc641a
cleanup
19f936d
cleanup
345327e
cleanup
a836b23
cleanup
43bda2e
cleanup
1f08e46
cleanup
a83ef63
cleanup
0f3a2bc
cleanup
eb98baa
cleanup
d9b73f6
cleanup
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.