PIMoveTo¶
Note
Looking for a detailed description? See PI Deep Dive.
-
void
PIMoveTo(char *fName, int size, bool preload)¶ Uses a PI controller to move the robot using a trajectory profile as the reference data. The passed in trajectory profile should have 6 columns. The first 3 are the total angular displacements(rad) of motors 1, 2, and 3 repsectively, with the last 3 being the respective angular velocities(rad/s). The delta time is 0.1 seconds. The loop each iteration will calculate difference in encoder counts to convert it into displacement in radians using countsToRadDisp. This will then be added to the total angular displacement for each motor, and these calculated values will be subracted with the reference angular displacements to get the error for each motor. These errors are then summed to the motors individual total error counter, and based on the error values and P & I constants, angular velocities(rad/s) to set the motors to is calculated. Then the funtion setRadSToPercent is called to convert the angular speeds to percent and limit them within operating range, and then set the motors to that percent.
- Parameters
fName: the file name of trajectory profile.size: the number of lines/commands in trajectory profile.preload: If true, the file will be preloaded and won’t start until the start light turns on.
Examples¶
1 | PIMoveTo("upRamp.txt", 31, false);
|
Note that while size may be any number equal to or larger to the number of lines, it is more effecient for memory
to keep size equal to the number of lines. Additionally, the given file name must match the format shown in
Trajectory profiles.
1 | PIMoveTo("start.txt", 21, true);
|
In this example, preload is true. Thus, it will read the file and populate the arrays, but will not start moving
until getCdsColor reports that light is detected.
Function Variables¶
Type |
Name |
Description |
|---|---|---|
|
|
The current iteration encoder counts for motor 1 |
|
|
The current iteration encoder counts for motor 2 |
|
|
The current iteration encoder counts for motor 3 |
|
|
The previous iteration encoder counts for motor 1 |
|
|
The previous iteration encoder counts for motor 2 |
|
|
The previous iteration encoder counts for motor 3 |
|
|
The total angular displacement for motor 1 in radians |
|
|
The total angular displacement for motor 2 in radians |
|
|
The total angular displacement for motor 3 in radians |
|
|
Temporary variable to read motor 1’s reference angular position from file |
|
|
Temporary variable to read motor 2’s reference angular position from file |
|
|
Temporary variable to read motor 3’s reference angular position from file |
|
|
Temporary variable to read motor 1’s reference angular velocity from file |
|
|
Temporary variable to read motor 2’s reference angular velocity from file |
|
|
Temporary variable to read motor 3’s reference angular velocity from file |
|
|
Reference angular positions - Columns are each motor, rows are each value |
|
|
Reference angular velocities - Columns are each motor, rows are each value |
|
|
Stores the actual current total displacement for motor 1 in radians |
|
|
Stores the actual current total displacement for motor 2 in radians |
|
|
Stores the actual current total displacement for motor 3 in radians |
|
|
Calculated motor 1’s speed in rad/s to correct for error from PI controller |
|
|
Calculated motor 2’s speed in rad/s to correct for error from PI controller |
|
|
Calculated motor 3’s speed in rad/s to correct for error from PI controller |
|
|
The total error error for motor 1 used by the integral term |
|
|
The total error error for motor 2 used by the integral term |
|
|
The total error error for motor 3 used by the integral term |
|
|
The proportional constant |
|
|
The integral constant |