APIs and Libraries
Libraries and APIs
A library is a collection of code someone else already wrote, that you can reuse instead of writing it yourself. WPILib — the library every FRC robot depends on — is exactly this: motor control, sensors, the whole command-based framework, all written once and reused by thousands of teams.
The API (Application Programming Interface) is the instructions for how to actually use a library: what classes it gives you, what each one can do, and what you need to pass in. You don't need to know how a library's code works internally — you just need its API.
Classes, Attributes, and Behaviors
A class is the building block a library gives you — it defines a new kind of value, the same way int or double do, except you (or a library author) define what it means. An object is one specific thing built from a class.
Every class bundles two things together:
- Attributes — the data it holds. Stored in variables.
- Behaviors — what it can do. Defined as methods.
TalonFX shooterMotor = new TalonFX(5); // shooterMotor is an object, built from the TalonFX class
shooterMotor.set(0.8); // a behavior — call a method with the dot operator
The . (dot operator) is how you reach an object's behaviors and attributes. shooterMotor.set(0.8) means: find the set method defined in the TalonFX class, and run it on this specific motor object.
Why This Matters
You don't need to know how TalonFX is implemented internally — motor controller firmware, CAN bus protocol, none of it — to use shooterMotor.set(0.8) correctly. That's the entire point of a library: someone else solved the hard problem once, documented how to use their solution, and you build on top of it instead of starting from scratch.
Common Pitfalls
- Confusing a class with an object.
TalonFXis the class (the blueprint);shooterMotoris one specific object built from it. A robot might have severalTalonFXobjects — one per motor. - Forgetting the dot operator.
shooterMotor set(0.8)isn't valid — the dot is what connects an object to its behavior.
Key Takeaways
- A library is reusable code written by someone else; its API documents how to use it.
- A class defines a new kind of value, bundling attributes (data) and behaviors (methods) together.
- An object is one specific instance built from a class.
- The dot operator (
.) accesses an object's attributes and behaviors.
Derived from csawesome-2026: unit-1-using-objects-and-methods/1.07-apis-and-libraries.md (CSA 1.7)