Skip to content
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

Fwxv 250 update drive fsm #240

Merged
merged 9 commits into from
Dec 2, 2023
Merged

Fwxv 250 update drive fsm #240

merged 9 commits into from
Dec 2, 2023

Conversation

mitchellostler
Copy link
Collaborator

Refactor Drive FSM to finalize the main functionality it needs to have

@@ -2,6 +2,8 @@
#include "log.h"
#include "tasks.h"

DECLARE_TASK(master_task);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added so that we can reference "master_task" when sending notifications, etc

@@ -0,0 +1,191 @@
#pragma once
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial commit of exported enums. Some are from XV, the rest are leftovers from MSXIV. Expect this to change

#define BEGIN_PRECHARGE_SIGNAL 2
#define PRECHARGE_STATE_COMPLETE 2
#define NUMBER_OF_CYCLES_TO_WAIT 10
#define POWER_FSM_STATE_OFF 0 // will be changed later
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These need to go in exported enums


if (pca9555_reg_val == PCA9555_REG_DEFAULT) { // No button pressed
return STATUS_CODE_OK;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add this to the pca interface, might make a good new member ticket

@mitchellostler
Copy link
Collaborator Author

@JarvisWeng Main changes to this are moving all of the hardware interaction for Centre Console to one file, update_dashboard.c. Would be a good place to start your review. You can also look at other places where I've added comments. Ayo is working on validating these changes, but might be better to merge them in so we don't block others

#define CC_LED_PUSH_START \
{ .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT }
#define CC_LED_POWER \
{ .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_4 }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ayo going to change all these addresses right?


if (pca9555_reg_val == PCA9555_REG_DEFAULT) { // No button pressed
return STATUS_CODE_OK;
}
if ((~(pca9555_reg_val)&REGEN_BTN_MASK) != 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right before this if, maybe do pca9555_reg_val = ~pca9555_reg_val. That way you don't do it for every if. Or maybe the compiler optimizes this out anyway.

prv_speed_is_negative()) {
next_state = REVERSE;
fsm_transition(fsm, DRIVE);
break;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just do a return here?
You do this to only wait on STATUS_CODE_INCOMPLETE? So you only want the first notification?

// this is a fail case | going back to neutral
fsm_shared_mem_set_drive_error_code(STATUS_CODE_TIMEOUT);
next_state = NEUTRAL;
if (power_received_counter > 3) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a ticket to change this to watchdog when Adhiraj makes a change, we will fix this

power_received_counter++;
}

if (power_received_counter > 3) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number and duplicate logic. Maybe make into a prv function?

s_regen_braking = false;
pca9555_gpio_set_state(&s_output_leds[HAZARD_LED], PCA9555_GPIO_STATE_LOW);
} else {
s_regen_braking = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just move s_regen_braking out of if

if (get_power_info_power_state() != s_last_power_state) {
if (get_power_info_power_state() == EE_POWER_ON_STATE ||
get_power_info_power_state() == EE_POWER_DRIVE_STATE) {
pca9555_gpio_set_state(&s_output_leds[POWER_LED], PCA9555_GPIO_STATE_HIGH);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High regardless?

}

// Update left/right LED
if (get_steering_info_input_lights() != s_last_lights_state) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this is my bad, but I'm pretty sure you don't need the () when you use the getters. They should just be #defines. Though if you like it's fine, but I'm pretty sure it serves no purpose

if (get_drive_state() != DRIVE || get_pedal_output_brake_output()) {
new_cc_state = false;
} else {
if (cc_info & EE_STEERING_CC_TOGGLE_MASK) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Else if?

uint16_t batt_perc_val = get_battery_status_batt_perc();
seg_display_set_int(&cc_display, s_target_velocity);
if (speed_kph >= 100) {
seg_display_set_int(&speed_display, (int)speed_kph);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious if this can overflow into a negative speed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully we aren't doing > 255 km/h 😅, we might have bigger problems than speed overflow.

@Kyle02 Kyle02 force-pushed the FWXV_250_Update_Drive_FSM branch from 70880a1 to 9a7eef7 Compare December 2, 2023 20:11
Copy link
Collaborator

@Kyle02 Kyle02 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mitchellostler mitchellostler merged commit ee5863e into main Dec 2, 2023
1 check passed
@mitchellostler mitchellostler deleted the FWXV_250_Update_Drive_FSM branch December 2, 2023 21:41
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.

3 participants