Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ bun.lock
# macOS-specific files
.DS_Store

.vscode
.vscode

# IntelliJ
.idea/
Binary file added public/misc/loop_block.png

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This block diagram feels misleading due to the lack of plant in here. Take a look at this figure from the controls engineering in frc book (note that the figure numbering is a bit different than in the wpilib docs).

Image

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 106 additions & 0 deletions src/content/docs/misc/motor_control.mdx

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When will this page be placed in the sequence? What will students already have learned? I think we need to consider how this will integrate into the learning sequence. I'm imagining this will be stage 2 (which is when FF is first introduced and when we first actually control a motor rather than just a full drivetrain), but I'm struggling to see how this would integrate into a course well. The content here is good, but I'm just not sure on integrating it into the course and making it compelling for the student.

Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Controlling mechanisms with motors

With the introduction of the brushless era of motors in FRC, motors have become the dominant choicewhen it comes to controlling robot degrees of freedom, compared to servos or pneumatics.
Brushless motors have incredible size to performance ratios, and the smart motor controllers that accompany them make it easy to control a variety of mechanisms.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this intro section necessary? I'm not sure it's necessary to refer to pre-covid pneumatics usage. The discussion of performance also isn't really relevant, as it's basically just the standard at this point.

This section will cover the most common types of software controllers for motors in FRC.

## Motor Controllers
Not to be confused with hardware motor controllers like the REV Spark Max or CTRE TalonFX, a software motor controller is a function that converts a setpoint input to a motor output.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think this is really a standard term. At least, not something I've heard referred to like this before. This just feels very confusing to introduce a duplicate term that really only is used here

In the simplest case, the input _is_ the output, such as when using voltage or throttle (duty-cycle) control.

A more complex example would multiply the setpoint, say a flywwhel rpm, by some constant to convert to volts for the motor.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I feel like this is putting the cart before the horse. Using the example of FF before any of that is introduced doesn't make much sense.


Understanding and mastering these controllers will help your robots to be fast and accurate, and help you to be succesful in FRC.

## Open- and Closed-loop Controllers
The types of controllers that you can create can be split into two categories: open-loop, and closed-loop.
Open-loop refers to a mechanism that have only a single input, the setpoint.
Open-loop controllers will often, but not always, utilize a mathematical model of the motor and mechanism to make an educated estimate of how the motor should act in order to reach the setpoint.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Especially RE the comment about the open-loop section being titled better below, this line adds confusion.

However, they have no way of knowing if the motor is behaving according to the model, so open-loop control is inadequate for most FRC mechanisms.

Closed-loop mechanisms have an additional input: a measurement of the current state of the mechanism.
A closed-loop controller will combine this measurement and setpoint to determine the output.
Using a measurement from the mechanism is beneficial because it gives your controller insight into how the mechanism is actually behaving.
This _feedback_ from the mechanism can help account for the modle being inaccurate, or disturbances which have caused the mechanism to not act exactly according to the model.

Closed-loop control is fundamental to creating fast and accurate mechansims, but requires more effort to get working properly.
Open-loop control is simpler, but may lack the precision that closed-loop offers.

Ther terms open- and closed-loop refers to the shape of the controller when diagrammed out.
See this image from the [WPILib Docs](https://docs.wpilib.org/en/stable/docs/software/advanced-controls/introduction/control-system-basics.html#block-diagrams):
![Closed Loop Block Diagram](/misc/loop_block.png).

When there is no feedback, the diagram forms a straight line from input to output.
In the closed-loop case, the input -> output -> feedback forms a loop.

## Open Loop Control

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this section could be titled better. I don't think calling this open loop control is great. Even though it is open loop control, it feels confusing when you start talking about open loop velocity. It doesn't really make sense to have open loop velocity be within this section, but not have closed loop be within this section, since the discussion of duty cycle and voltage applies to closed loop as well.


Some mechanisms, like intake rollers, can provide successful performance even without incorporating feedback from the mechanism.
Intake rollers are commonly controlled simply by running the motor at a throttle level, which represents a percentage of the battery voltage.
A 50% throttle, set with `motor.setThrottle(0.5)` will output 50% of the battery voltage to the motor.
Even if the battery voltage is a little higher or lower from one point in time to the next, the effect on intake performance is likely to be negligible, so there is no need to account for it in your controller.

The simplest open-loop mechanisms require almost no configuration in code, since you don't need to configure gear ratios or feedback gains.

The two most common open-loop setpoint types are duty-cycle and voltage.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This discussion of duty cycle vs position really needs to be the first thing discussed on this page because how you actually make the motor spin and the concepts behind that is the root of everything else on this page.


Duty-cycle is a percentage of input voltage coming from the robot's battery to the motor controller.
WPILib refers to this percentage as throttle.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Duplicate explanation of throttle from above

If the battery voltage is 11.8 volts, and you request a 50% duty-cycle, or 50% throttle, the motor controller will output 5.9 volts to the motor.

Voltage control allows you to directly control the output going to the motor.
If the battery voltage is 12.2 volts, and you request a voltage of 6 volts, the motor controller will output 6 volts.
Likewise, if the battery voltage dips to 11.8 volts, the motor controller will still output 6 volts

Voltage control is recommended over duty-cycle for open loop control because of its repeatability.
The voltage going to the motor does not fluctuate with changes in battery voltage.
When using voltage control, it is recommended to not exceed a setpoint of 10 volts to account for voltage sag as your battery is used up throughout the match.
Voltage control can accomodate voltages _higher_ than the setpoint by reducing the duty cycle, but if the input voltage is below the setpoint, the motor controller cannot overcome the deficit.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should be an Aside I feel like


### Open Loop Velocity

While open-loop position control does not work well in FRC, open-loop velocity control is very practical due to the nature of motors.
Many teams will choose to run flywheels for shooters using open-loop control, since there is a direct relationship between motor voltage and motor speed, referred to as the velocity constant _kV_.
This relationship can be found theoretically using key characteristics of the motor, or empirically by taking velocity measurements at different voltages to calculate _kV_.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The lack of mention of kS here feels very odd to me.

See the [WPILib Docs](https://docs.wpilib.org/en/stable/docs/software/advanced-controls/introduction/introduction-to-feedforward.html#introduction-to-dc-motor-feedforward) page on DC Motor Feedforward for more info about kV.

If you don't want to calculate kV, you can use voltage directly as your setpoint.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I feel like this section should make it more clear that you're using velocity units with kV (include output = kS + kV * setpoint here too, I think), but with this specific line, you are abandoning velocity units


It is common practice to use open-loop velocity control on swere drivetrains too, where precise velocity is not as important.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't totally like this paragraph because it really only applies to teleop driving (and even then, not all teams do it). It feels odd to say this, but then know that if autoalign is discussed, it'll go against this, etc. Especially as swerve will have its own section of the site, this feels like a note best left off of this page

The human driver acts like a closed-loop controller, using measurements taken of robot position and speed in order to adjust its movement.

## Closed-Loop Control

### Closed-Loop Position Control

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The lack of position FF discussion feels odd


Position control is the most common closed-loop control scheme in FRC.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I feel like this sentence is unnecessary. It really only makes sense if you go "I want closed loop control", then as "hmm what should I do, position or velocity?" and then decide position. Making the sentence go the other direction "If you need to control the position of a mechanism, closed-loop control is how you do that" (word it better of course), the sentence makes more sense in context.

Mechanisms that use position control include elevators, pivoting arm, slap-down intakes, climbers, and every swerve drivetrain contains four position-controlled modules.

#### Measuring your mechanism

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I feel like this belongs on a separate page, likely beyond stage 2 where homing techniques (beyond just starting in a known position) can be discussed in more detail. Possibly in general a discussion on sensing.


The most common feedback sensor in position-controlled mechanism is an encoder, a small electronic device that can measure rotation.
Brushless motors all contain internal encoders, so these are a popular choice for teams.
They require no extra work to incorporate into a mechanisms design, and are guaranteed to be functioning as long as the motor is.
The downside of these internal encoders is they reset to a position of _0_ when the motor turns on, regardless of the mechansims physical location.
To counteract this, you either need to perform a homing sequence that moves your mechanism in a controlled manner to a fixed location, then reset the encoder reading to match, or to always power on the robot with the mechanisms in a known spot, such as a physical hardstop.
Using a hardstop location at power-on is recommended for its simplicity, and because you always power the robot on when it is on the field at competition, you will be able to position the mechanisms correctly before doing so.

An alternative to a motors internal encoder is an external encoder.
External encoders can be mounted to an axle that rotates as the mechanism moves.
By attaching the encoder to the final shaft of a rotating mechanism, such as an arm, you can treat the encoder reading as _absolute_, requiring no homing sequence or specific power-on location.


### Closed-Loop Velocity Control

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This section should probably be above closed-loop position so that it's physically closer to closed-loop velocity


Closed-loop velocity control relies heavily on the open-loop control discussed above, but with similar incorporation of feedback gains to account for disturbances.
An example of disturbance that you may need to account for is a game piece slowing down your shooter's flywheel.
In years when you have to shoot multiple game pieces one after another, like in 2026 Rebuilt, closed-loop control can help your flywheel recover between shots in a way that open-loop alone cannot.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Rebuilt should be all caps



## Choosing a control scheme

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Capitalize header


Choosing a control scheme for a mechanism should feel straightforward.
If you need a mechanism to move to a precise position and stay there, closed-loop position is the only option.
If you need a mechanism to move at a specific speed, start with open-loop velocity control.
If you find that the mechanism still doesn't perform as well as you'd like, consider if adding feedback would improve performance.
Instead, if you only need a mechanism to move at rough speeds, open loop control is a simple way to achieve motion.