Skip to content

Conversation

@alexapostolu
Copy link
Member

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.

Copy link
Contributor

@IbrahimFadel IbrahimFadel left a 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 ??
Copy link
Contributor

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

xSemaphoreGive(can_mutex);
}

if (xSemaphoreTake(steering_angle_mutex, pdMS_TO_TICKS(1)) == pdTRUE) {
Copy link
Contributor

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


while (1) {
if (xSemaphoreTake(spi_mutex, pdMS_TO_TICKS(100)) == pdTRUE) {
for (int i = 0; i < 20; i++) { // 20 ??
Copy link
Contributor

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.

Comment on lines 219 to 224
float new_current = sensor_current_read();

if (xSemaphoreTake(current_mutex, pdMS_TO_TICKS(1)) == pdTRUE) {
current = new_current;
xSemaphoreGive(current_mutex);
}
Copy link
Contributor

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

Comment on lines 262 to 265
if (xSemaphoreTake(steering_angle_mutex, pdMS_TO_TICKS(1)) == pdTRUE) {
steering_angle = (float)steering_angle_raw;
xSemaphoreGive(steering_angle_mutex);
}
Copy link
Contributor

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

float steering_angle_ = sensor_steering_angle_get();

float torques[4];
calculate_torque_cmd(torques, current_, &wheel_speed_, steering_angle_);
Copy link
Contributor

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants