src: intro_project: add sensor, lcd and bms functions#2
src: intro_project: add sensor, lcd and bms functions#2alexapostolu wants to merge 1 commit intoUTFR:mainfrom
Conversation
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.
2e8be18 to
eaf6c1c
Compare
IbrahimFadel
left a comment
There was a problem hiding this comment.
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.
i didnt specify a baudrate so np
| xSemaphoreGive(can_mutex); | ||
| } | ||
|
|
||
| if (xSemaphoreTake(steering_angle_mutex, pdMS_TO_TICKS(1)) == pdTRUE) { |
There was a problem hiding this comment.
Not too important but you only need to take this mutex and update the value if the previous if statement was successful
|
|
||
| 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.
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.
| 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.
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
| 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.
Same note here, i would probably use a queue for steering angle
| 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.
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.