-
Notifications
You must be signed in to change notification settings - Fork 3
src: intro_project: add sensor, lcd and bms functions #2
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
base: main
Are you sure you want to change the base?
Conversation
2e8be18 to
eaf6c1c
Compare
IbrahimFadel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great :) The only real thing is you never command torque, but I realize now i never specified that in the instructions lol
| steering_angle_mutex = xSemaphoreCreateMutex(); | ||
| can_mutex = xSemaphoreCreateMutex(); | ||
|
|
||
| can_init(CAN_RX_PIN, CAN_TX_PIN, 250000); // 250000 ?? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i didnt specify a baudrate so np
src/intro_project.cpp
Outdated
| xSemaphoreGive(can_mutex); | ||
| } | ||
|
|
||
| if (xSemaphoreTake(steering_angle_mutex, pdMS_TO_TICKS(1)) == pdTRUE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not too important but you only need to take this mutex and update the value if the previous if statement was successful
src/intro_project.cpp
Outdated
|
|
||
| while (1) { | ||
| if (xSemaphoreTake(spi_mutex, pdMS_TO_TICKS(100)) == pdTRUE) { | ||
| for (int i = 0; i < 20; i++) { // 20 ?? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a 138s1p battery, so if bms_get_voltage(i) gets the ith cell's voltage, this for loop should go to 138, but this is completely fine i didnt specify.
src/intro_project.cpp
Outdated
| float new_current = sensor_current_read(); | ||
|
|
||
| if (xSemaphoreTake(current_mutex, pdMS_TO_TICKS(1)) == pdTRUE) { | ||
| current = new_current; | ||
| xSemaphoreGive(current_mutex); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably use a queue for this because the size of the data (float) is small (one word) and it follows a producer consumer model
src/intro_project.cpp
Outdated
| if (xSemaphoreTake(steering_angle_mutex, pdMS_TO_TICKS(1)) == pdTRUE) { | ||
| steering_angle = (float)steering_angle_raw; | ||
| xSemaphoreGive(steering_angle_mutex); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same note here, i would probably use a queue for steering angle
src/intro_project.cpp
Outdated
| float steering_angle_ = sensor_steering_angle_get(); | ||
|
|
||
| float torques[4]; | ||
| calculate_torque_cmd(torques, current_, &wheel_speed_, steering_angle_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is correct, but you never actually commanded torque - you only calculated and printed it. I would add another motor control task that just receives current, wheelspeed and steering angle data, calculates torque and sends it on CAN. It could also then send those torque values to this task via a queue to be printed
Add sensor, LCD and BMS functions to update and display sensor values to LCD, and de-energize relays when voltage or temperature goes out of bounds.
eaf6c1c to
685f8ef
Compare
Add sensor, LCD and BMS functions to update and display sensor values to LCD, and de-energize relays when voltage or temperature goes out of bounds.