You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code excerpt is only meant to show how feedforward works. This is not how we actually implement feedforward, but should give you a better idea of the inner workings of feedforward.
52
52
53
-
## System Idenfication
53
+
## Tuning and System Idenfication
54
+
Similar to PID, you can tune values by manually guessing and checking.
55
+
56
+
[Click here to try tuning a feedforward controller. SCROLL TO "PURE FEEDFORWARD CONTROL", SKIP EVERYTHING ELSE](https://docs.wpilib.org/en/stable/docs/software/advanced-controls/introduction/tuning-flywheel.html)
57
+
58
+
Follow the instructions and see if you can get the optimal tuning solution. The model simulates a flywheel shooter mechanism and halfway through the simulation it shoots a ball. **DO NOT SKIP THIS PRACTICE**
59
+
60
+
While manual tuning works, WPILIB provides a way to generate kS, kV, and kA, called System Identification, or SysID for short.
61
+
62
+
!!! warning
63
+
Do not move on if you don't know how [lambdas/consumers](https://docs.wpilib.org/en/stable/docs/software/basic-programming/functions-as-data.html) work and the [Java Unit library](https://docs.wpilib.org/en/stable/docs/software/basic-programming/java-units.html).
64
+
65
+
System Identification is the process of determining a mathematical model for the behavior of a system through statistical anaylsis of its inputs and outputs. SysID has a process to determine kS, kV, and kA for the motor, so you don't have to do any tuning! They also provide PID values, but treat them as a "starting point" for further tuning.
66
+
67
+
Read the following WPILIB articles:
68
+
69
+
-[Creating an Identification Routine](https://docs.wpilib.org/en/stable/docs/software/advanced-controls/system-identification/creating-routine.html)
70
+
-[Running the Identification Routine](https://docs.wpilib.org/en/stable/docs/software/advanced-controls/system-identification/running-routine.html)
71
+
72
+
<hr>
73
+
74
+
For those that want a quick summary:
75
+
76
+
The SysID tool runs two types of tests:
77
+
78
+
- Quasistatic: mechanism is gradually sped up (determines amount of voltage needed for velocity)
79
+
- Dynamic: mechanism is given a constant 'step voltage' (determines amount of voltage needed for acceleration)
80
+
81
+
These tests can be run backwards and forwards. To create the test, you have to write create a SysIdRoutine object:
The `SysIdRoutine.Config()` is where you specify custom parameters for the quasistatic and dynamic tests.
101
+
For example if you write:
102
+
```java
103
+
// ramp rate of 3 volts per second and step voltage of 8 volts
104
+
newSysIdRoutine.Config(3, 8);
105
+
```
106
+
By default the ramp rate is 1 volt per second and the step voltage is 7 volts. The reason why you may want to lower the ramp rate is so it doesn't run too fast and smash into the wall. Typically the default works fine.
107
+
The `Config` object also accepts a timeout and callback (function that is called when the test is over).
108
+
109
+
Now that you have set the parameters, you need to specify which motors receive voltage and how you will log the data for analysis. In this example we will be controlling a single motor. The `Mechanism` object accepts those two functions:
Here are the two functions that drive and log the motor voltage:
115
+
```java
116
+
// Mutable holder for unit-safe voltage values, persisted to avoid reallocation.
117
+
privatefinalMutableMeasure<Voltage> voltage = mutable(Volts.of(0));
118
+
119
+
publicvoid driveMotor(Measure<Voltage> volts) {
120
+
motor.setVoltage(volts.in(Volts));
121
+
}
122
+
123
+
publicvoid logMotor(SysIdRoutineLog log) {
124
+
log.motor("shooter-motor")
125
+
.voltage(voltage.mut_replace(
126
+
motor.get() *RobotController.getBatteryVoltage(),
127
+
Volts
128
+
));
129
+
}
130
+
```
131
+
Note that [SysIdRoutineLog](https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/sysid/SysIdRoutineLog.html) has a handy `motor` method which returns a `SysIdRoutineLog.MotorLog` object used to log voltage, linear position, velocity, and more. [Take a look at all the properties the object logs](https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/sysid/SysIdRoutineLog.MotorLog.html).
132
+
133
+
You may also notice that the only values that the logger logs are of instances that must be of `MutableMeasure<(insert measure)>`. This records the values along with its units. You can't just log a value.
134
+
135
+
After you set up the testing parameters and mechanism to test, the SysIdRoutine provides functions that return a command to run the test.
Typically it is recommended to bind these commands to controller buttons or an autonomous routine. If using a controller, it is recommended to bind them like this:
Now you are ready to enable and run the tests! Typically the longer you run them, the more data you get which will lead to more accurate calculations. However, keep in mind not to run too long for safety purposes. After all four tests have been run, use the [DataLogTool](https://docs.wpilib.org/en/stable/docs/software/telemetry/datalog-download.html) to get the files.
0 commit comments