Skip to content

Commit

Permalink
Merge pull request #2 from UOA-FSAE/main
Browse files Browse the repository at this point in the history
merge latest main for definitions
  • Loading branch information
Zane-Larking authored Apr 25, 2024
2 parents e5e67f9 + 9d87f59 commit 5c24bde
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 103 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/validator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pyyaml
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run validator
run: |
python validator.py
13 changes: 13 additions & 0 deletions definitions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
can:
- name: "can1"
baudrate: 1000
- name: "can2"
baudrate: 1000
- name: "can3"
baudrate: 250

messages:
- ID: 0x103
can_line: "can3"
message: "AMSError"
110 changes: 7 additions & 103 deletions fs-common-protobuf/can.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,108 +2,12 @@ syntax = "proto3";

/* Current ID: 0x103 */
message AMSError {
bool IMD = 0;
bool valid_cell_count = 1; /* If the number of cells found by BMS is equal to expected number of cells */
bool is_bms_alive = 2; /* If the bms is reporting / alive */
bool is_over_temperature = 3; /* If the temperature of the cells is above the threshold */
bool is_warn_temperature = 4; /* If the temperature of the cells is over the warning the threshold */
bool is_over_voltage = 5; /* If the voltage of the cells is above the threshold */
bool is_under_voltage = 6; /* If the voltage of the cells is below the threshold */
bool IMD = 1; /* Imd fault */
bool valid_cell_count = 2; /* If the number of cells found by BMS is equal to expected number of cells */
bool is_bms_alive = 3; /* If the bms is reporting / alive */
bool is_over_temperature = 4; /* If the temperature of the cells is above the threshold */
bool is_warn_temperature = 5; /* If the temperature of the cells is over the warning the threshold */
bool is_over_voltage = 6; /* If the voltage of the cells is above the threshold */
bool is_under_voltage = 7; /* If the voltage of the cells is below the threshold */
}




// TODO below are the specific bit lengths needed on the CAN frame for each
// value. Either values need to be shift encoded into a single/two 32 bit ints
// or masking on values should be specified.

/* Go-Kart */
/* Motec -> Orin
/* Current ID: */
/* size 3 bytes */
message CANRAW {
int8 velocity = 1
int16 steering = 2
}


/* Orin -> Nano */
/* Current ID: 0x300 */
/* size 6 bytes */
message Ackermann {
int8 speed = 1; /* Desired speed of the car. Must be between 0 and 120 km/h. */
int8 acceleration = 2; /* Desired acceleration. Must be between 0 and 256 m/s^2. */
int8 jerk = 3; /* Desired jefk. Must be between 0 and 1 m/s^3. */
int16 steering_angle = 4; /* Desired steering_angle. Must be between -45 and 45 degrees. */
int8 steering_angle_velocity = 5; /* Desired_angle_velocity. Must be between 0 and 1 radians/s. */
}



//* Data Logging

/* Required ID: 0x500 */
/* size 8 bytes */
message DrivingDynamics1 {
uint8 speed_actual = 1; /* bit 0-7 */
uint8 speed_target = 2; /* bit 8-15 */
int8 steering_angle_actual = 3; /* bit 16-23 */
int8 steering_angle_target = 4; /* bit 24-31 */
uint8 brake_hydr_actual = 5; /* bit 32-39 */
uint8 brake_hydr_target = 6; /* bit 40-47 */
int8 motor_moment_actual = 7; /* bit 48-55 */
int8 motor_moment_target = 8; /* bit 56-63 */

}

/* Required ID: 0x501 */
/* size 6 bytes */
message DrivingDynamics2 {
int16 acceleration_longitudinal = 1; /* bit 0-15 1/512 scale */
int16 acceleration_lateral = 2; /* bit 16-31 1/512 scale */
int16 yaw_rate = 3; /* bit 32-47 1/128 scale*/
}

/* Required ID: 0x502 */
/* size 5 Bytes */
message SystemStatus {
AS_State as_state = 1; /* bit 0-2 */
EBS_State ebs_state = 2; /* bit 3-4 */
AMI_State ami_state = 3; /* bit 5-7 */
bool steering_state = 4; /* bit 8 */
Service_Brake_State service_brake_state = 5; /* bit 9-10*/
uint4 lap_counter = 6; /* bit 11-14 */
uint8 Cones_count_actual = 7; /* bit 15-22 */
uint17 Cones_count_all = 8; /* bit 23-39 (17 bits) */
}

enum AS_State {
AS_state_off = 0;
AS_state_ready = 1;
AS_state_driving = 2;
AS_state_emergency_brake = 3;
AS_state_finish = 4;
}

enum EBS_State {
EBS_state_unavailable = 0;
EBS_state_armed = 1;
EBS_state_activated = 2;
}

enum AMI_State {
AMI_state_acceleration = 0;
AMI_state_skidpad = 1;
AMI_state_trackdrive = 2;
AMI_state_braketest = 3;
AMI_state_inspection = 4;
AMI_state_autocross = 5;
}

enum Service_Brake_State {
Steering_state = 0;
Service_brake_state_disengaged = 1;
Service_brake_state_engaged = 2;
Service_brake_state_available = 3;
}
38 changes: 38 additions & 0 deletions validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
""" Validates definitions
Checks to see if the names of all the messages in definitions are the correct name.
"""
import yaml


def get_all_can_message_names() -> list:
with open("fs-common-protobuf/can.proto", "r") as file:
message_names = []

for line in file:
line_parts = line.split(" ")
if line_parts[0] == "message":
message_names.append(line_parts[1])

return message_names


def get_all_defined_messages() -> list:
with open("definitions.yml", "r") as file:
definitions = yaml.safe_load(file)
message_names = [message['message'] for message in definitions['messages']]

return message_names


if __name__ == "__main__":
can_message_names = get_all_can_message_names()
print(f"all protobuf can message names = {can_message_names}")

definition_message_names = get_all_defined_messages()
print(f"all definition message names requested = {definition_message_names}")

for definition_message_name in definition_message_names:
if definition_message_name not in can_message_names:
raise ValueError(f"{definition_message_name} not defined in can proto. \n"
f"list of available message names are {can_message_names}")

0 comments on commit 5c24bde

Please sign in to comment.