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

Launch control refactor (up to date with competition VCU code) #22

Closed
wants to merge 14 commits into from
Closed
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ src/**/bin
# Annoying ropeproject
**/.ropeproject

test/**/*.png

# vim
*.swp

Expand Down
36 changes: 26 additions & 10 deletions can_spec_my18.yml
Original file line number Diff line number Diff line change
Expand Up @@ -393,16 +393,6 @@ buses:
position: 6
length: 1
c_type: bool
lc_state:
position: 7
length: 3
c_type: enum
enum:
BEFORE: 0
SPEEDING_UP: 1
SPEED_CONTROLLER: 2
ZERO_TORQUE: 3
DONE: 4
VCUErrors:
can_id: 0x0F4
period: 111ms
Expand Down Expand Up @@ -681,6 +671,19 @@ buses:
position: 60
length: 1
c_type: bool
DashRequestLC:
can_id: 0x0D5
is_big_endian: true
period: 69ms
nistath marked this conversation as resolved.
Show resolved Hide resolved
segments:
using_launch_ctrl:
position: 0
length: 1
c_type: bool
launch_ctrl_slip_ratio: # Ranges from 105 to 115
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why does it range from 105 to 115?

position: 16
length: 16
c_type: uint16_t
nistath marked this conversation as resolved.
Show resolved Hide resolved
VCUControlsParams:
can_id: 0x0D4
is_big_endian: true
Expand Down Expand Up @@ -736,6 +739,19 @@ buses:
position: 60
length: 1
c_type: bool
VCUParamsLC:
can_id: 0x0D6
is_big_endian: true
period: 200ms
segments:
using_launch_ctrl:
position: 0
length: 1
c_type: bool
slip_ratio: # Ranges from 105 to 115
position: 16
length: 16
c_type: uint16_t
nistath marked this conversation as resolved.
Show resolved Hide resolved
ButtonRequest:
can_id: 0x0D8
period: 73ms
Expand Down
36 changes: 34 additions & 2 deletions src/dashboard/src/page_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void draw_nav_line(page_manager_t *pm, NHD_US2066_OLED *oled) {

void draw_critical_page(page_manager_t *pm, NHD_US2066_OLED *oled);
void draw_regen_page(page_manager_t *pm, NHD_US2066_OLED *oled);
void draw_launch_control_page(page_manager_t *pm, NHD_US2066_OLED *oled);
void draw_traction_page(page_manager_t *pm, NHD_US2066_OLED *oled);
void draw_fault_page(page_manager_t *pm, NHD_US2066_OLED *oled);

Expand All @@ -60,8 +61,11 @@ void page_manager_update(page_manager_t *pm, NHD_US2066_OLED *oled) {
draw_critical_page(pm, oled);
break;
case DASH_PAGE_REGEN:
draw_regen_page(pm, oled);
break;
draw_regen_page(pm, oled);
break;
case DASH_PAGE_LAUNCH_CONTROL:
draw_launch_control_page(pm, oled);
break;
case DASH_PAGE_TEMP_LIM:
draw_temp_lim_page(pm, oled);
break;
Expand Down Expand Up @@ -430,6 +434,34 @@ void draw_volt_lim_page(page_manager_t *pm, NHD_US2066_OLED *oled) {
oled_print(oled, ">");
}

void draw_launch_control_page(page_manager_t *pm, NHD_US2066_OLED *oled) {
carstats_t *stats = pm->stats;

oled_clearline(oled, 1);
oled_set_pos(oled, 1, 0);

if (stats->buttons.right.rising_edge) {
stats->controls.launch_ctrl_slip_ratio += 1;
}

stats->controls.launch_ctrl_slip_ratio = LOOPOVER(stats->controls.launch_ctrl_slip_ratio, 101, 120);
nistath marked this conversation as resolved.
Show resolved Hide resolved

if (stats->buttons.B.rising_edge) stats->controls.using_launch_ctrl ^= 1; // NOT

oled_print(oled, "LAUNCH CONTROL ");

oled_print(oled, (stats->controls.using_launch_ctrl) ? "ON" : "OFF");

oled_rprint_pad(oled, "SLIP RATIO ", 4);

if (stats->controls.launch_ctrl_slip_ratio != -1) {
oled_print_num(oled, stats->controls.launch_ctrl_slip_ratio);
}
else {
oled_print(oled, DATA_UNKNOWN);
}
}

void draw_fault_page(page_manager_t *pm, NHD_US2066_OLED *oled) {
carstats_t *stats = pm->stats;

Expand Down
20 changes: 20 additions & 0 deletions src/vcu/inc/controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
#define MAX_ACCEL_VAL 1000
#define MIN_ACCEL_VAL 0

// Launch control contants
Copy link
Contributor Author

Choose a reason for hiding this comment

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

spelling error

// After wheel speed crosses this threshold, start using slip controller
#define LC_WS_THRESH 45000
#define LC_cGR 347 // Gear ratio times 100
#define LC_ACCEL_BEGIN 950 // 95%
#define LC_ACCEL_RELEASE 50 // 5%
#define LC_BRAKE_BEGIN 100 // We want a lower threshold
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we still want this comment?

#define LC_BACKWARDS_CUTOFF 10

// RG = regen
#define RG_MOTOR_SPEED_THRESH 250 // RPM
#define RG_CAR_SPEED_THRESH 5 // kph
Expand All @@ -31,6 +40,14 @@
#define FRONT_BRAKE brake_1
#define REAR_BRAKE brake_2

typedef enum {
BEFORE,
SPEEDING_UP,
SPEED_CONTROLLER,
ZERO_TORQUE,
DONE,
} Launch_Control_State_T;

// TL = temp limiting
#define MAX_TEMP 5800 // centiCelsius

Expand All @@ -40,11 +57,14 @@
#define TEMP_LOG_LENGTH 200

extern can0_VCUControlsParams_T control_settings;
extern can0_VCUParamsLC_T lc_settings;

// INTERACTION FUNCTIONS
void enable_controls(void);
void disable_controls(void);
bool get_controls_enabled(void);
void execute_controls(void);
void set_lc_done(void);
void set_lc_state_before(void);

#endif // ifndef __TORQUE_CALC
11 changes: 11 additions & 0 deletions src/vcu/src/can_handles.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,17 @@ void handleDashRequest(Frame *msg) {
control_settings.active_aero_enabled = unpacked_msg.active_aero_enabled;
}

void handle_DashRequestLC(Frame *msg) {
can0_DashRequestLC_T unpacked_msg;

unpack_can0_DashRequestLC(msg, &unpacked_msg);

if (unpacked_msg.launch_ctrl_slip_ratio != 65535) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is 65535? Should this really go in the Dash Request handler?

Copy link
Member

Choose a reason for hiding this comment

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

-1 is the convention for "hey vcu use your default value". Should've been -1 cast to the correct type.

lc_settings.slip_ratio = unpacked_msg.launch_ctrl_slip_ratio;
lc_settings.using_launch_ctrl = unpacked_msg.using_launch_ctrl;
}
}

void send_VCUHeartbeat(void) {
LIMIT(can0_VCUHeartbeat);

Expand Down
Loading