Difference between revisions of "MATLAB code"
Line 1: | Line 1: | ||
=Commonly Used Variables= | =Commonly Used Variables= | ||
− | *state: state is an vector with 8 state variables, in order they are, time step, X position, Y position, Lean Angle, Yaw Angle, Steer Angle, Lean Angle Rate, Velocity | + | *'''state''': state is an vector with 8 state variables, in order they are, time step, X position, Y position, Lean Angle, Yaw Angle, Steer Angle, Lean Angle Rate, Velocity |
− | *motCommands - this is the same as <math>\vec{u}</math> in the control equation, for forward moving balancing, it is steer angle rate <math>[\dot{\delta}]</math> | + | *'''motCommands''' - this is the same as <math>\vec{u}</math> in the control equation, for forward moving balancing, it is steer angle rate <math>[\dot{\delta}]</math> |
− | + | *'''K''' - this is the vector of the three gain values k1,k2,k3. They are used to find the value of <math>[\dot{\delta}]</math> | |
+ | = MATLAB files = | ||
+ | |||
+ | == runBicycleTest.m == | ||
+ | Inputs: | ||
+ | <div style="column-count:3;-moz-column-count:3;-webkit-column-count:3"> | ||
+ | * x0,y0 - initial location | ||
+ | * v0 - initial speed | ||
+ | * delta0 - initial steer angle | ||
+ | * phi0 - initial lean angle | ||
+ | * phi_dot0 - initial lean angle ratw | ||
+ | * psi0 - initial yaw angle (heading) | ||
+ | * K - vector of gains (k1, k2, k3) | ||
+ | * delta_offset - either a scalar (a constant offset), or a vector of offsets (the bike will attempt to hit delta_offset(n) at the nth timestep | ||
+ | * numTimeSteps - the number of time steps to run the simulation for | ||
+ | * graph - 1=draws graph, 0=does not | ||
+ | </div> | ||
+ | |||
+ | Outputs: | ||
+ | success - 1 if bike stayed up successfully throughout duration of the test, 0 if the bike falls down(lean angle becomes greater than pi/4 during the test) | ||
+ | allStates - matrix with size (number of time steps x 8). Each row of this matrix contains a state, it contains all the states for all the timesteps in the test. | ||
+ | |||
+ | This function uses state variables and gains and passes them to rhs, which produces the derivative of all the state variables(minus timestep) and the motor command then it uses that derivative and euler integrates to find the next state values. It repeats this process for all the time steps in the test. Each time step is 1/50 second apart. Finally it uses all the states and all the motor commands and calls animateBike, to produce an animation of the bike and create all the data graphs for analysis. | ||
+ | |||
=== animateBike.m === | === animateBike.m === | ||
Inputs: | Inputs: | ||
Line 10: | Line 33: | ||
* delta_offset | * delta_offset | ||
* phi_offset | * phi_offset | ||
+ | |||
=== balanceControlOptimizer.m === | === balanceControlOptimizer.m === | ||
+ | |||
=== BikeAndMotorConstants.m === | === BikeAndMotorConstants.m === | ||
+ | |||
=== CircleAboutZ.m === | === CircleAboutZ.m === | ||
Inputs: | Inputs: | ||
* r - radius of the circle | * r - radius of the circle | ||
+ | |||
=== drawBike.m === | === drawBike.m === | ||
Inputs: | Inputs: |
Revision as of 00:27, 16 May 2020
Contents
Commonly Used Variables
- state: state is an vector with 8 state variables, in order they are, time step, X position, Y position, Lean Angle, Yaw Angle, Steer Angle, Lean Angle Rate, Velocity
- motCommands - this is the same as in the control equation, for forward moving balancing, it is steer angle rate
- K - this is the vector of the three gain values k1,k2,k3. They are used to find the value of
MATLAB files
runBicycleTest.m
Inputs:
- x0,y0 - initial location
- v0 - initial speed
- delta0 - initial steer angle
- phi0 - initial lean angle
- phi_dot0 - initial lean angle ratw
- psi0 - initial yaw angle (heading)
- K - vector of gains (k1, k2, k3)
- delta_offset - either a scalar (a constant offset), or a vector of offsets (the bike will attempt to hit delta_offset(n) at the nth timestep
- numTimeSteps - the number of time steps to run the simulation for
- graph - 1=draws graph, 0=does not
Outputs: success - 1 if bike stayed up successfully throughout duration of the test, 0 if the bike falls down(lean angle becomes greater than pi/4 during the test) allStates - matrix with size (number of time steps x 8). Each row of this matrix contains a state, it contains all the states for all the timesteps in the test.
This function uses state variables and gains and passes them to rhs, which produces the derivative of all the state variables(minus timestep) and the motor command then it uses that derivative and euler integrates to find the next state values. It repeats this process for all the time steps in the test. Each time step is 1/50 second apart. Finally it uses all the states and all the motor commands and calls animateBike, to produce an animation of the bike and create all the data graphs for analysis.
animateBike.m
Inputs:
- state
- p
- motCommands
- delta_offset
- phi_offset
balanceControlOptimizer.m
BikeAndMotorConstants.m
CircleAboutZ.m
Inputs:
- r - radius of the circle
drawBike.m
Inputs:
- x
- y
- z
- yaw
- roll
- steer
- p
lqr_BC_optimizer.m
plotMultipleControllersTogether.m
rhs.m
- currentState
- p
- K
- delta_offset
- phi_offset
runBicycleTest.m
Inputs:
- x0,y0 - intial location
- v0 - initial speed
- delta0 - intial steer angle
- phi0 - intial lean angle
- phi_dot0 - intial derivative of lean angle
- psi0 - intial yaw angle (heading)
- K - vector of gains (k1, k2, k3)
- delta_offset - either a scalar (a constant offset), or a vector of offsets (the bike will attempt to hit delta_offset(n) at the nth timestep
- numTimeSteps - the number of time steps to run the simulation for
- graph - 1= draws graph, 0 =does not