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 + Internal speed controller #31

Open
wants to merge 33 commits into
base: launch-control
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5b01836
Main pieces of PID loop, still not compiled
sebLopezCot Oct 11, 2018
9eec3fb
removing unneeded code
sebLopezCot Oct 11, 2018
b3966b2
Precision updates should be correct now
sebLopezCot Oct 13, 2018
006034d
Adding can messages for speed controller
sebLopezCot Oct 13, 2018
03e951e
Sending proper can messages from speed_controller
sebLopezCot Oct 13, 2018
c10deee
Now sending speed controller command messages from speed controller
sebLopezCot Oct 13, 2018
db4525c
Bringing speed controller into launch control for testing on the jacks
sebLopezCot Oct 13, 2018
2d7e90d
Adding in the driver toque command limiting
sebLopezCot Oct 14, 2018
8da3f67
ZERO GAINS TESTED, DOES NOTHING! pass
sebLopezCot Oct 14, 2018
b4d0d6b
Added new display page to dash for PID
SreyaV Oct 14, 2018
2622873
SPEED CONTROLS PROPERLY PROPORTIONAL 10 NM, 1500 RPM
sebLopezCot Oct 14, 2018
4a10cb6
TEST WORKS PROP GAIN AT MAX_TORQUE: 50 Nm
sebLopezCot Oct 14, 2018
f4f3404
PROP CONTROL 240 Nm good:
sebLopezCot Oct 14, 2018
eca848d
Bringing setpoint down again for safety
sebLopezCot Oct 14, 2018
890393f
Merge branch 'launch-control-internal-speed-controller' of https://gi…
SreyaV Oct 14, 2018
27aa862
INTEGRATOR TERM TESTED ON JACKS
sebLopezCot Oct 14, 2018
4c1a06f
Merge branch 'launch-control-internal-speed-controller' of github.com…
sebLopezCot Oct 14, 2018
cfc25f6
Derivative term tested on jacks
sebLopezCot Oct 14, 2018
82cea62
Setpoint to 0 for safety
sebLopezCot Oct 14, 2018
a57023e
Revert "Constant speed, no backwards check"
sebLopezCot Oct 14, 2018
0f9ef25
Adding in one more disable for safety
sebLopezCot Oct 14, 2018
edf9a9f
Change max speed -> 500 and no backwards check
sebLopezCot Oct 14, 2018
cf4b8db
Shuddering P
daniwhite Oct 14, 2018
608e157
No speeding up state, shuddering gains
daniwhite Oct 14, 2018
0ac25e8
Configure PID constants from the dash
daniwhite Oct 19, 2018
595b8ff
Fix wrong names and defaults
daniwhite Oct 19, 2018
bf496d3
Change max input speed
daniwhite Oct 20, 2018
236b71a
Setting max input speed higher for testing
sebLopezCot Oct 20, 2018
5290511
FIRST PALMER RUN: PID TESTING AT HIGHER SPEEDS
sebLopezCot Oct 21, 2018
5d62ad6
end of pid tuning
sebLopezCot Oct 21, 2018
4f1f29b
Fix junk files
nistath Oct 23, 2018
8a2ae6a
Fix 255 bug
nistath Oct 23, 2018
f293b5c
Fixing state machine bug
sebLopezCot Mar 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
220 changes: 220 additions & 0 deletions can_spec_my18.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ boards:
- MCCommand
- VCUControlsParams
- VCUControlsMonitoring
- VCUSpeedCntrlKpTimes1000
- VCUSpeedCntrlKiTimes1000
- VCUSpeedCntrlKdTimes1000
- VCUSpeedCntrlIWindupMax
- VCUSpeedCntrlIWindupMin
- VCUSpeedCntrlMinOutputValue
- VCUSpeedCntrlMaxOutputValue
- VCUSpeedCntrlMinInputValue
- VCUSpeedCntrlMaxInputValue
- VCUSpeedCntrlErrorUpdateTimeout
- VCUSpeedCntrlDt
- VCUSpeedCntrlEnabled
- VCUSpeedCntrlOutOfInputRangeThrottled
- VCUSpeedCntrlOutOfOutputRangeThrottled
- VCUSpeedCntrlErrorUpdateTimedOut
- VCUSpeedCntrlRPMSetpoint
- VCUSpeedCntrlCommandedTorque
- VCUSpeedCntrlRPMError
- VCUSpeedCntrlLastRPMError
- VCUSpeedCntrlDerivRPMError
- VCUSpeedCntrlRPMErrorAccumulated
- VCUSpeedCntrlLastErrorUpdateTimestamp
subscribe:
can0:
- FrontCanNodeBrakeThrottle
Expand Down Expand Up @@ -869,6 +891,204 @@ buses:
position: 48
length: 16
c_type: uint16_t
VCUSpeedCntrlKpTimes1000:
can_id: 0x223
period: 200ms
is_big_endian: true
segments:
kp_times_1000:
position: 0
length: 32
c_type: int32_t
VCUSpeedCntrlKiTimes1000:
can_id: 0x225
period: 200ms
is_big_endian: true
segments:
ki_times_1000:
position: 0
length: 32
c_type: int32_t
VCUSpeedCntrlKdTimes1000:
can_id: 0x227
period: 200ms
is_big_endian: true
segments:
kd_times_1000:
position: 0
length: 32
c_type: int32_t
VCUSpeedCntrlIWindupMax:
can_id: 0x229
period: 200ms
is_big_endian: true
segments:
i_windup_max:
position: 0
length: 32
c_type: int32_t
VCUSpeedCntrlIWindupMin:
can_id: 0x22B
period: 200ms
is_big_endian: true
segments:
i_windup_min:
position: 0
length: 32
c_type: int32_t
VCUSpeedCntrlMinOutputValue:
can_id: 0x22D
period: 200ms
is_big_endian: true
segments:
min_output_value:
position: 0
length: 32
c_type: int32_t
VCUSpeedCntrlMaxOutputValue:
can_id: 0x22F
period: 200ms
is_big_endian: true
segments:
max_output_value:
position: 0
length: 32
c_type: int32_t
VCUSpeedCntrlMinInputValue:
can_id: 0x231
Copy link
Member

Choose a reason for hiding this comment

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

2 space after : gore

period: 200ms
is_big_endian: true
segments:
min_input_value:
position: 0
length: 32
c_type: int32_t
VCUSpeedCntrlMaxInputValue:
can_id: 0x233
period: 200ms
is_big_endian: true
segments:
max_input_value:
position: 0
length: 32
c_type: int32_t
VCUSpeedCntrlErrorUpdateTimeout:
can_id: 0x235
period: 200ms
is_big_endian: true
segments:
error_update_timeout:
position: 0
length: 32
c_type: int32_t
VCUSpeedCntrlDt:
can_id: 0x237
period: 200ms
is_big_endian: true
segments:
dt:
position: 0
length: 32
c_type: int32_t
VCUSpeedCntrlEnabled:
can_id: 0x239
period: 200ms
is_big_endian: true
segments:
enabled:
position: 0
length: 1
c_type: bool
VCUSpeedCntrlOutOfInputRangeThrottled:
can_id: 0x23B
period: 200ms
is_big_endian: true
segments:
out_of_input_range_throttled:
position: 0
length: 1
c_type: bool
VCUSpeedCntrlOutOfOutputRangeThrottled:
can_id: 0x23D
period: 200ms
is_big_endian: true
segments:
out_of_output_range_throttled:
position: 0
length: 1
c_type: bool
VCUSpeedCntrlErrorUpdateTimedOut:
can_id: 0x23F
period: 200ms
is_big_endian: true
segments:
error_update_timed_out:
position: 0
length: 1
c_type: bool
VCUSpeedCntrlRPMSetpoint:
can_id: 0x241
period: 200ms
is_big_endian: true
segments:
rpm_setpoint:
position: 0
length: 32
c_type: int32_t
VCUSpeedCntrlCommandedTorque:
can_id: 0x243
period: 200ms
is_big_endian: true
segments:
commanded_torque:
position: 0
length: 32
c_type: int32_t
VCUSpeedCntrlRPMError:
can_id: 0x245
period: 200ms
is_big_endian: true
segments:
rpm_error:
position: 0
length: 32
c_type: int32_t
VCUSpeedCntrlLastRPMError:
can_id: 0x247
period: 200ms
is_big_endian: true
segments:
last_rpm_error:
position: 0
length: 32
c_type: int32_t
VCUSpeedCntrlDerivRPMError:
can_id: 0x249
period: 200ms
is_big_endian: true
segments:
deriv_rpm_error:
position: 0
length: 32
c_type: int32_t
VCUSpeedCntrlRPMErrorAccumulated:
can_id: 0x24B
period: 200ms
is_big_endian: true
segments:
rpm_error_accumulated:
position: 0
length: 32
c_type: int32_t
VCUSpeedCntrlLastErrorUpdateTimestamp:
can_id: 0x24D
period: 200ms
is_big_endian: true
segments:
last_error_update_timestamp:
position: 0
length: 32
c_type: uint32_t
MCCommand:
can_id: 0x0C0 # From manual
period: 9ms # MC needs a message at 2 Hz or higher
Expand Down
25 changes: 25 additions & 0 deletions src/vcu/inc/can_handles.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "stdio.h"
#include "stm32f2xx_hal.h"
#include "CANlib.h"
#include <stdbool.h>
#include <stdint.h>

#include "state.h"
#include "fault.h"
Expand Down Expand Up @@ -41,4 +43,27 @@ void sendSpeedCmdMsg(int16_t speed, int16_t torque_limit);
void sendMotorOffCmdMsg(void);
void send_mc_fault_clear(void);

void sendVCUSpeedCntrlKpTimes1000Msg(void);
void sendVCUSpeedCntrlKiTimes1000Msg(void);
void sendVCUSpeedCntrlKdTimes1000Msg(void);
void sendVCUSpeedCntrlIWindupMaxMsg(void);
void sendVCUSpeedCntrlIWindupMinMsg(void);
void sendVCUSpeedCntrlMinOutputValueMsg(void);
void sendVCUSpeedCntrlMaxOutputValueMsg(void);
void sendVCUSpeedCntrlMinInputValueMsg(void);
void sendVCUSpeedCntrlMaxInputValueMsg(void);
void sendVCUSpeedCntrlErrorUpdateTimeoutMsg(void);
void sendVCUSpeedCntrlDtMsg(void);
void sendVCUSpeedCntrlEnabledMsg(void);
void sendVCUSpeedCntrlOutOfInputRangeThrottledMsg(void);
void sendVCUSpeedCntrlOutOfOutputRangeThrottledMsg(void);
void sendVCUSpeedCntrlErrorUpdateTimedOutMsg(void);
void sendVCUSpeedCntrlRPMSetpointMsg(void);
void sendVCUSpeedCntrlCommandedTorqueMsg(void);
void sendVCUSpeedCntrlRPMErrorMsg(void);
void sendVCUSpeedCntrlLastRPMErrorMsg(void);
void sendVCUSpeedCntrlDerivRPMErrorMsg(void);
void sendVCUSpeedCntrlRPMErrorAccumulatedMsg(void);
void sendVCUSpeedCntrlLastErrorUpdateTimestampMsg(void);

#endif // ifndef __CAN_HANDLES_H
4 changes: 4 additions & 0 deletions src/vcu/inc/controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include "fault_pedalbox.h"
#include "fault_brakes.h"

// Internal Speed Controller settings for launch control
#define MAX_INPUT_SPEED 3000
#define SPEED_CONTROLLER_UPDATE_PERIOD_MS 1

// TODO: Extract MAX_TORQUE from RMS EEPROM (over CAN?)
#define MAX_TORQUE 2400 // unit: dNm
#define MAX_ACCEL_VAL 1000
Expand Down
73 changes: 73 additions & 0 deletions src/vcu/inc/speed_controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#ifndef __SPEED_CONTROLLER
#define __SPEED_CONTROLLER

#include "stm32f2xx_hal.h"
#include <stdbool.h>
#include <stdint.h>

#include "can_handles.h"

extern can0_VCUSpeedCntrlKpTimes1000_T kp_times_1000_frame;
extern can0_VCUSpeedCntrlKiTimes1000_T ki_times_1000_frame;
extern can0_VCUSpeedCntrlKdTimes1000_T kd_times_1000_frame;
extern can0_VCUSpeedCntrlIWindupMax_T i_windup_max_frame;
extern can0_VCUSpeedCntrlIWindupMin_T i_windup_min_frame;
extern can0_VCUSpeedCntrlMinOutputValue_T min_output_value_frame;
extern can0_VCUSpeedCntrlMaxOutputValue_T max_output_value_frame;
extern can0_VCUSpeedCntrlMinInputValue_T min_input_value_frame;
extern can0_VCUSpeedCntrlMaxInputValue_T max_input_value_frame;
extern can0_VCUSpeedCntrlErrorUpdateTimeout_T error_update_timeout_frame;
extern can0_VCUSpeedCntrlDt_T dt_frame;
extern can0_VCUSpeedCntrlEnabled_T enabled_frame;
extern can0_VCUSpeedCntrlOutOfInputRangeThrottled_T out_of_input_range_throttled_frame;
extern can0_VCUSpeedCntrlOutOfOutputRangeThrottled_T out_of_output_range_throttled_frame;
extern can0_VCUSpeedCntrlErrorUpdateTimedOut_T error_update_timed_out_frame;
extern can0_VCUSpeedCntrlRPMSetpoint_T rpm_setpoint_frame;
extern can0_VCUSpeedCntrlCommandedTorque_T commanded_torque_frame;
extern can0_VCUSpeedCntrlRPMError_T rpm_error_frame;
extern can0_VCUSpeedCntrlLastRPMError_T last_rpm_error_frame;
extern can0_VCUSpeedCntrlDerivRPMError_T deriv_rpm_error_frame;
extern can0_VCUSpeedCntrlRPMErrorAccumulated_T rpm_error_accumulated_frame;
extern can0_VCUSpeedCntrlLastErrorUpdateTimestamp_T last_error_update_timestamp_frame;

// PUBLIC STRUCTS
typedef struct {
int32_t kp_times_1000;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Small thing but this indentation is annoying

int32_t ki_times_1000;
int32_t kd_times_1000;
int32_t i_windup_max;
int32_t i_windup_min;
int32_t min_output_value;
int32_t max_output_value;
int32_t min_input_value;
int32_t max_input_value;
int32_t dt;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe should be unsigned

uint32_t error_update_timeout;
} SpeedControllerParams;

typedef struct {
bool enabled;
bool out_of_input_range_throttled;
bool out_of_output_range_throttled;
bool error_update_timed_out;
int32_t rpm_setpoint;
int32_t commanded_torque;
int32_t rpm_error;
int32_t last_rpm_error;
int32_t deriv_rpm_error;
int32_t rpm_error_accumulated;
uint32_t last_error_update_timestamp;
} SpeedControllerInternalVars;

// PUBLIC FUNCTIONS
void init_speed_controller_defaults(int32_t max_input_speed,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Another annoying indentation inconsistency

int32_t max_output_torque, uint32_t update_period_millis);
void enable_speed_controller(void);
void disable_speed_controller(void);
void set_speed_controller_setpoint(int32_t rpm);
void update_speed_controller_error(int32_t actual_rpm,
uint32_t actual_rpm_msg_timestamp);
int32_t get_speed_controller_torque_command(void);
bool get_speed_controller_enabled(void);

#endif // ifndef __SPEED_CONTROLLER
1 change: 1 addition & 0 deletions src/vcu/inc/state_vcu_driving.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "state_vcu.h"
#include "can_handles.h"
#include "controls.h"
#include "speed_controller.h"

#define AA_SETUP 10
#define AA_HOLD 10
Expand Down
Loading