-
Notifications
You must be signed in to change notification settings - Fork 6
Spark MAX & Spark FLEX
Click here for full SparkMAX/SparkFlex documentation.
This documentation is for motors created by REV Robotics, including, but not limited to:
- The NEO 550 Brushless Motor
- The Core Hex Motor
- The HD Hex Motor
The code below is used to configure the SparkMax/SparkFlex configurator objects, and it should be kept in mind that SparkMax and SparkFlex are the names of the motor controllers, not the motors themselves.
To initialize a SparkMax, put
private SparkMax exampleMotor;at the start of the function, which creates the motor object, then set it in the constructor using
exampleMotor = new SparkMax(Ports.EXAMPLE_MOTOR, MotorType.kBrushless);(replacing example motor with the motor you're using and setting motor type based on whether we're using brushless motors or not)
Now that you've set up the motor, you can configure it!
Initialized in the start of the function via
private SparkClosedLoopController exampleController; and then set in the constructor using the code:
exampleController = exampleMotor.getClosedLoopController();Uses:
- Setting the motor velocity like
this.desiredVelocity = velocity;
exampleController.setReference(value, SparkBase.ControlType.kControlType);The Control Types are as follows:
- kCurrent
- kDutyCycle
- kMAXMotionPositionControl
- kMAXMotionVelocityControl
- kPosition
- kVelocity
- kVoltage
The Two MAXMotion control types are for closed loop control, which is for when we feed data back into our program to adapt to situations, and the value parameter is a value that sets a reference the motor tries to go to based on control type. For basic duty cycle control this should be a value between -1 and 1. Otherwise:
- Voltage Control: Voltage (volts)
- Velocity Control: Velocity (RPM)
- Position Control: Position (Rotations)
- Current Control: Current (Amps)
- other uses and information about detailed here
Initialized in the constructor via
SparkMaxConfig exampleConfig = new SparkMaxConfig();Important:
If you are setting a follower for a motor, two separate configs are required, with the follower having the .follow command listed below
Uses:
- Setting a motor to follow another motor
exampleFollowerConfig.follow(exampleMotorLeader.getDeviceId());- Setting what the motor does when you stop providing input to the motor (either brakes or coasts on momentum)
exampleConfig.idleMode(IdleMode.kBrake); or exampleConfig.idleMode(IdleMode.kCoast);- Setting a smart current limit, which is how much, in amps, that can pass through the motor controller at a time.
exampleConfig.smartCurrentLimit(exampleConstants.EXAMPLE_CURRENT_LIMIT);- Setting the P, I, D, and FeedForward values for the motor (PID is detailed more here)
exampleConfig.closedLoop.pidf(exampleConstants.EXAMPLE_KP, exampleConstants.EXAMPLE_KI, exampleConstants.EXAMPLE_KD, exampleConstants.EXAMPLE_KFF);Once you've set the configs using your SparkMaxConfig object, you'll need to apply the configurations to your SparkMax motor object by using the code:
exampleMotor.configure(exampleConfig, SparkBase.ResetMode.kResetSafeParameters, SparkBase.PersistMode.kPersistParameters);Breakdown of above code:
- exampleConfig: the SparkMaxConfig object you configured
- SparkBase.ResetMode: Whether you reset the parameters on configure, following with .kResetSafeParameters as shown above will reset the parameters, while following with .kNoResetSafeParameters will not.
- SparkBase.PersistMode: whether you want your parameters to persist in the case of a power cycle, which is a reboot. Following the method with .kPersistParameters will save the parameters for the next power cycle, and .kNoPersistParameters makes the current configuration not persist through a power cycle and should only be used when setting a temporary config.
This is an officially licensed product of Team 4026. Decatur Robotics 2024 is not sponsored by any other Team, and is not responsible for any damages caused by using this product or trusting the programming team, which is by far the least most trustworthy team(Shadow owen money gang, we love coding the robot). By using this product, you are consenting to your information, and thus your identity to be stolen and first-born child taken.
- Editing Documentation & Markdown Syntax
- Code Team to-do List
- Code Standards
- Common Library Structure
- Interfaces
- General Setup
- Branching System
- How to Create Pull Requests
- How to Switch Branches
- Code Reviews
- Reverting Commits
- Singleton Pattern
- Software Installations
- Necessary IntelliJ Plugins
- Vendordeps
- Setting Up New Projects
- Autoformatter Set Up
- Showbot Requirements
- Autonomous
- Calling a Command Based on a Button Press
- CAN
- Clearing Sticky Faults
- Current Limits
- PID Config and Usage
- Robot.java, TeleopInit, DisabledInit
- RoboRio Ports
- SetDefaultCommand
- Wait for Time
- SlewRateLimiter
- LEDs
- InstantCommand
- PhotonVision
- Apriltags
- Camera Display on Shuffleboard
- Object Detection
- Raspberry Pi
- Network Tables
- List of Network Tables (2023)
Up to date as of SJ2, end of 2023 season