Skip to content

Commit

Permalink
Merge pull request #96 from flamingchickens1540/drive-framework
Browse files Browse the repository at this point in the history
Drive Framework (motion profiling edition)
  • Loading branch information
RobinsonZ authored Jan 8, 2019
2 parents 758f97e + 4ba83bc commit de9b0aa
Show file tree
Hide file tree
Showing 51 changed files with 3,108 additions and 145 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,8 @@ gradle-app.setting

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties

### ROOSTER-specific

# motion profiles
*.csv
6 changes: 3 additions & 3 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions .idea/runConfigurations/Deploy_HeadingPIDPipelineTestRobot.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions .idea/runConfigurations/Deploy_MotionProfilePipelineTestRobot.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions .idea/runConfigurations/Deploy_ProfileContainerTestingRobot.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions .idea/runConfigurations/Deploy_TurningRatePIDPipelineTestRobot.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions .idea/runConfigurations/Deploy_VelocityCharacterizationRobot.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions .idea/runConfigurations/Deploy_WheelbaseTestRobot.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ Advanced closed-loop drive code for a tank drive.

`org.team1540.rooster.drive.pipeline`

A flexible system for controlling a robot drive. More docs [here](docs/Drive%20Pipelines.md).

#### Motion Profiling

`org.team1540.rooster.motionprofiling`

A system for executing motion profiles on a tank drive.
A flexible system for controlling a robot drive. More docs [here](docs/Drive%20Pipelines.md), with a specific section on motion profiling [here](docs/Motion%20Profiling.md).

#### Power Management

Expand Down
32 changes: 7 additions & 25 deletions docs/Drive Pipelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Executable pipeline = new SimpleJoystickInput(new Joystick(0), 1, 5, false, fals
Breakdown:

- ` SimpleJoystickInput(new Joystick(0), 1, 5, false, false)`: Takes values from a joystick on port 0, with axis 1 as the left and axis 5 on the right, inverting neither
- `.then(new TalonSRXOutput(leftTalon, rightTalon))`: Sends the output of the previous `SimpleJoystickInput` to your `leftTalon` and `rightTalon`. Since the output of `SimpleJoystickInput` only sets the feed-forward (i.e. raw throttle) term, it'll automatically use `PercentOutput` output mode.
- `.then(new CTREOutput(leftTalon, rightTalon))`: Sends the output of the previous `SimpleJoystickInput` to your `leftTalon` and `rightTalon`. Since the output of `SimpleJoystickInput` only sets the feed-forward (i.e. raw throttle) term, it'll automatically use `PercentOutput` output mode.

### Execute a Motion Profile

Expand All @@ -44,7 +44,7 @@ Breakdown:

- `ProfileInput` takes values from two provided `MotionProfile` instances and returns the setpoint for the current time. The timer starts when the pipeline is first executed.
- `OpenLoopFeedForward` takes the velocity and acceleration setpoints from the `ProfileInput` and calculates a suitable feed-forward for them using coefficients you provide, Oblarg-style. It then passes those velocities down.
- `TalonSRXOutput`, since it's receiving position setpoints from the `ProfileInput`, tells the Talon closed-loop to PID to those setpoints while providing the feed-forward from the `OpenLoopFeedForward` as an additional bump term.
- `CTREOutput`, since it's receiving position setpoints from the `ProfileInput`, tells the Talon closed-loop to PID to those setpoints while providing the feed-forward from the `OpenLoopFeedForward` as an additional bump term.

### Use in a Command

Expand All @@ -64,14 +64,8 @@ Most "stock" pipeline elements pass around `TankDriveData` instances to encapsul
An input that returns the same `TankDriveData` every time:

```java
TankDriveData tankDriveData = new TankDriveData(
new DriveData(0),
new DriveData(0),
OptionalDouble.empty(),
OptionalDouble.empty());

Executable pipeline = ((Input) () -> tankDriveData)
.then(new CTREOutput(leftTalon, rightTalon))
Executable pipeline = ((Input) () -> new TankDriveData().withVelocities(0, 0))
.then(new CTREOutput(leftTalon, rightTalon))
```

#### Custom Processor
Expand All @@ -80,21 +74,9 @@ A processor that multiplies the received position by two:

```java
Executable pipeline = new SimpleJoystickInput(new Joystick(0), 1, 5, false, false)
.then(data -> return new TankDriveData(
new DriveData(
d.left.position.isPresent() ? OptionalDouble.of(d.left.position.getAsDouble() * 2) : d.left.position,
d.left.velocity,
d.left.acceleration,
d.left.additionalFeedForward
),
new DriveData(
d.right.position.isPresent() ? OptionalDouble.of(d.right.position.getAsDouble() * 2) : d.right.position,
d.right.velocity,
d.right.acceleration,
d.right.additionalFeedForward
),
d.heading, d.turningRate);
))
.then(data -> data.modifyPositions(
(left) -> left.isPresent() ? left.getAsDouble() * 2 : left,
(right) -> right.isPresent() ? right.getAsDouble() * 2 : right)
.then(new CTREOutput(leftTalon, rightTalon))
```

Expand Down
Loading

0 comments on commit de9b0aa

Please sign in to comment.