Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
18 views

Programming III - Commands and Basic Motor Control

Uploaded by

arjunalwe24
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Programming III - Commands and Basic Motor Control

Uploaded by

arjunalwe24
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

PROGRAMMING III

Commands and Basic Motor Control


RECALL
Two major types of motors: brushless and

brushed

Brushed: CIM, mini CIM

Brushless: Neo, Neo 550, Falcon 500, Kraken x60


RECALL
Motors require motor controllers to communicate with

the roboRIO. They are connected through the CAN Bus.

Brushed motors: VictorSPX, TalonSRX, SparkMAX

Neo, Neo 550: SparkMAX

Falcon 500, Kraken x60: TalonFX (built into motor)

TWO MAJOR LIBRARIES --> REV and CTRE


CONTROLLING MOTORS
1. Identify the motor and motor

2. Assign a CAN ID to the motor controller using REV

Hardware Client or Phoenix Tuner X

RECALL: Every device on the CAN Bus must have an ID to

identify it
CONTROLLING MOTORS
3. Instantiate the motor controller with the correct CAN

ID.

SparkMAXs require the additional parameter MotorType:

either MotorType.kBrushed or MotorType.kBrushless

4. Set additional properties for motors.


MOTOR PROPERTIES
Inverted: Switch direction of movement

Current Limit: Maximum current that can be drawn

Neutral/Idle Mode: Behaviour when not moving (hold or coast)

Brake Mode: Behaviour when stopping (hold or coast)

Follower: Follows the movement of another motor

Ramp Rate: Acceleration for power supplied to motor


CONTROLLING MOTORS (REV)

.set(speed) -> takes a double ranging from -1 to 1.

.setVoltage(volts) -> takes a double measuring ranging from

-maxVolts to maxVolts of battery

*.set() is a set it and forget it method, meaning the motor will

move at whatever speed was given until .set(0) is called.


CONTROLLING MOTORS (CTRE)
.set(ControlMode, value) -> ControlMode dictates how the

value affects movement

ControlModes: ControlMode.PercentOutput,

ControlMode.Velocity, ControlMode.Current,

ControlMode.Position.
COMMANDS
Two different ways to declare a Command: subclassing &

Command Factories

A subclassed command turns one Command into its own

separate file.

A Command factory is a method that returns a Command


COMMANDS
Two different ways to declare a Command: subclassing &

Command Factories

A subclassed command turns one Command into its own

separate file.

A Command factory is a method that returns a Command


SUBCLASSED
FACTORY
LIFECYCLE OF A COMMAND
COMMAND TYPES
runOnce/InstantCommand: initialize

run/RunCommand: execute

startEnd/StartEndCommand: initialize, end

runEnd: execute, end

FunctionalCommand: initialize, execute, isFinished, end


HOW TO RETURN A COMMAND
Some Command types (runOnce, run, startEnd, runEnd) can

be called as a property of a subsystem. They are inherited

from the subsystem superclass


HOW TO RETURN A COMMAND
Commands can be created by instantiating that command type

This is useful when the Command is created outside of a subsystem,

or when using FunctionalCommands. FunctionalCommands cannot

be called as children of subsystems.


LAMBDAS
Creates a function in one line. Helps us treat actions as data.

Why do Commands need lambdas?

new RunCommand(System.out.println(“Hello, World”)); is

incorrect because Java thinks you’re trying to run

System.out.println(“Hello, World”) in that line


LAMBDAS

new RunCommand(() -> System.out.println(“Hello, World”));

allows us to treat that print statement as data, storing it within

the Command.
DOUBLE COLON

A double colon acts like a map to the location of a method. It

references the method, allowing the Command to save it.

Method references only work with void methods with no

parameters.
BINDING COMMANDS
Create a controller (CommandXboxController or

CommandPS4Controller) in RobotContainer

In the configureBindings method, call controller.desiredButton(),

i.e x, y, rightTrigger, leftBumper, leftJoystick


BINDING COMMANDS
Call a conditional such as .onTrue, .onFalse, .whileTrue,

.whileFalse, .toggleOnTrue, .toggleOnFalse on the Trigger.

Put a Command inside the decorator, usually by calling a

subsystem’s command factory.


BINDING COMMANDS

Controller Trigger Condition Command Factory


COMMAND MODIFIERS
Command objects have a variety of useful modifiers

alongWith()

.andThen()

.withTimeout()

.until()

.unless()
COMMAND GROUPS
Parallel Group: Commands run simultaneously

Race Group: As soon as one Command finishes, all others are interrupted.

Deadline Group: As soon as a specific “deadline” Command finishes, all

others are interrupted.

Sequence: Commands executed one after another.

Repeating Sequence: Commands executed sequentially, over and over

agian.
COMMAND GROUPS
Command Groups can be called by adding a decorator to an existing

Command, or by using a static Command factory from the Commands

class:
TIPS
Use VSCode IntelliSense if you don’t know what you’re looking for
TIPS
Hover over errors to see what the issue is

Use Quick Fix to resolve simple errors


TIPS
Make sure Commands can end
TIPS
Find good documentation

WPILib Docs

REV, CTRE, and other manufacturer websites

Example Code

Chief Delphi

Other teams’ GitHub


TIPS
TIPS
FRC Unofficial Server

You might also like