Skip to content

Conversation

jasondaming
Copy link
Member

Summary

Significantly improves the motor controller code examples to address issue #1385 by fixing confusing variable names and adding context about where code should be placed in a robot program.

Changes

Fixed Confusing Variable Names

Before: Spark spark = new Spark(0); (the "Buffalo buffalo" problem)
After: Spark intakeMotor = new Spark(0); (clear, descriptive name)

  • Changed variable names to be mechanism-based (intakeMotor, shooterMotor)
  • Used different PWM ports (0 and 1) to reinforce that these are separate motors
  • Added clear, descriptive comments for each line

Added Context Sections

Basic Usage:

  • Reorganized existing examples under clear header
  • Added important note explaining set() range (-1.0 to 1.0 with meanings)
  • Improved inline comments

Where to Put This Code (NEW):

  • Command-Based programs: Full example showing motor controller as subsystem member variable with runIntake() and stopIntake() methods
  • Timed Robot programs: Full example showing motor controller in Robot class with robotInit() and teleopPeriodic() usage
  • Includes all three languages (Java, C++, Python) for both patterns

Common Use Cases (NEW):

  • Lists real mechanisms that use motor controllers:
    • Intakes (collect game pieces)
    • Shooters (launch game pieces)
    • Conveyors (move game pieces)
    • Arms/Elevators (raise/lower mechanisms)
    • Climbers (extend/retract)
  • Links to drivetrain classes and WPILib examples

Impact

This transformation makes the article significantly more useful for beginners by:

  1. Eliminating the confusing "class name = class name" pattern
  2. Showing where motor controller code actually belongs in a robot program
  3. Providing complete, copy-pasteable examples for both Command-Based and Timed Robot
  4. Explaining what motor controllers are commonly used for on real robots

Fixes #1385

- Changed confusing variable names (Spark spark -> intakeMotor)
- Used different PWM ports (0 and 1) to avoid confusion
- Added descriptive comments for each line
- Added 'Basic Usage' section header
- Added important note explaining set() range (-1.0 to 1.0)
- Added 'Where to Put This Code' section with examples for:
  - Command-Based programs (subsystem class)
  - Timed Robot programs (Robot class with robotInit/teleopPeriodic)
- Added 'Common Use Cases' section listing real mechanisms:
  - Intakes, shooters, conveyors, arms/elevators, climbers
- Links to drivetrain classes and WPILib examples

Fixes wpilibsuite#1385
}
private:
std::unique_ptr<frc::Spark> m_intakeMotor;
Copy link
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 how we want to declare in C++


## CAN Motor Controllers

A handful of CAN motor controllers are available through vendors such as CTR Electronics, REV Robotics, and Playing with Fusion. See :doc:`/docs/software/can-devices/third-party-devices`, :doc:`/docs/software/vscode-overview/3rd-party-libraries`, and :doc:`/docs/software/examples-tutorials/third-party-examples` for more information.
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's more vendors with CAN motors now, right?


## Using PWM Motor Controllers

PWM motor controllers can be controlled in the same way as a CAN motor controller. For a more detailed background on *how* they work, see :doc:`pwm-controllers`. To use a PWM motor controller, simply use the appropriate motor controller class provided by WPILib and supply it the port the motor controller(s) are plugged into on the roboRIO. All approved motor controllers have WPILib classes provided for them.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd delete the line about PWM motor controllers being controlled the same as CAN controllers. I think it's potentially confusing since there's a lot of differences, and as CAN controllers haven't been discussed, assuming that people know what that means doesn't seem like a good assumption.


.. note:: The ``Spark`` and ``VictorSP`` classes are used here as an example; other PWM motor controller classes have exactly the same API.

### Basic Usage
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like the Basic Usage section doesn't add value, compared to the command and timed sections below and is potentially confusing. I'd delete it. For example, it shows both declaration and usage, and only addresses where declaration goes, but the command and timed sections show both clearly. Really the only thing this adds is the ranges of the set method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Example code in "Using Motor Controllers with Code" needs improvement

3 participants