Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double solenoids #4

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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
27 changes: 11 additions & 16 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package frc.robot;

import com.ctre.phoenix.motorcontrol.NeutralMode;

import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
Expand All @@ -10,31 +12,24 @@
public class Robot extends TimedRobot {
private Command m_autonomousCommand;
public static OI oi;
public static Motors motorOne;
public static Motors motorTwo;
public static Motors motorThree;
// exm:
public static Motors motorOneAndThree;



@Override
public void robotInit() {
Robot.motorOne = new Motors(RobotMap.VICTOR_SP_1);
Robot.motorTwo = new Motors(RobotMap.VICTOR_SP_2);
Robot.motorThree = new Motors(RobotMap.VICTOR_SP_3);
Robot.motorOneAndThree = new Motors(RobotMap.VICTOR_SP_1, RobotMap.VICTOR_SP_3);
Robot.oi = new OI();

SmartDashboard.putData("move motors", new MoveMotors(motorOne, oi.getXboxController()::getY, () -> false));
RobotComponents.tslonright.setNeutralMode(NeutralMode.Coast);
RobotComponents.talonleft.setNeutralMode(NeutralMode.Coast);
motorOneAndThree = new Motors(RobotComponents.talonleft, RobotComponents.tslonright);
oi = new OI();

SmartDashboard.putData("move motors", new MoveMotors(motorOneAndThree, () -> -0.6, () -> false));
SmartDashboard.putData("stop motors", new MoveMotors(motorOneAndThree, () -> 0.0, () -> false));
}

@Override
public void robotPeriodic() {
// Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled
// commands, running already-scheduled commands, removing finished or interrupted commands,
// and running subsystem periodic() methods. This must be called from the robot's periodic
// block in order for anything in the Command-based framework to work.
CommandScheduler.getInstance().run();
SmartDashboard.putNumber("voltage", RobotComponents.talonleft.getStatorCurrent());
}

@Override
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/frc/robot/RobotComponents.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package frc.robot;

import com.ctre.phoenix.motorcontrol.can.TalonSRX;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;

import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.VictorSP;

/**
* This class holds all the components of the robot.
*/
public class RobotComponents {

// public static final VictorSP VICTOR_SP_ONE = new VictorSP(RobotMap.VICTOR_SP_ONE);
// public static final VictorSP VICTOR_SP_TWO = new VictorSP(RobotMap.VICTOR_SP_TWO);
// public static final VictorSP VICTOR_SP_THREE = new VictorSP(RobotMap.VICTOR_SP_THREE);

public static final WPI_TalonSRX talonleft = new WPI_TalonSRX(RobotMap.LEFT_TALON_SHOOTER);
public static final WPI_TalonSRX tslonright = new WPI_TalonSRX(RobotMap.RIGHT_TALON_SHOOTER);

/*
public static final DoubleSolenoid DOUBLE_SOLENOID_ONE = new DoubleSolenoid(RobotMap.DOUBLE_SOLENOID_ONE_CHANNEL_A,
RobotMap.DOUBLE_SOLENOID_ONE_CHANNEL_B);
public static final DoubleSolenoid DOUBLE_SOLENOID_TWO = new DoubleSolenoid(RobotMap.DOUBLE_SOLENOID_TWO_CHANNEL_A,
RobotMap.DOUBLE_SOLENOID_TWO_CHANNEL_B);
public static final DoubleSolenoid DOUBLE_SOLENOID_THREE = new DoubleSolenoid(
RobotMap.DOUBLE_SOLENOID_THREE_CHANNEL_A, RobotMap.DOUBLE_SOLENOID_THREE_CHANNEL_B);
*/
}
22 changes: 15 additions & 7 deletions src/main/java/frc/robot/RobotMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@
*/
public class RobotMap {

public static final int VICTOR_SP_1 = 0;
public static final int VICTOR_SP_2 = 1;
public static final int VICTOR_SP_3 = 2;

public static final int DOUBLE_SOLENOID_1 = 3;
public static final int DOUBLE_SOLENOID_2 = 4;
public static final int DOUBLE_SOLENOID_3 = 5;
public static final int VICTOR_SP_ONE = 0;
public static final int VICTOR_SP_TWO = 1;
public static final int VICTOR_SP_THREE = 2;

public static final int LEFT_TALON_SHOOTER = 1;
public static final int RIGHT_TALON_SHOOTER = 2;

public static final int DOUBLE_SOLENOID_ONE_CHANNEL_A = 3;
public static final int DOUBLE_SOLENOID_ONE_CHANNEL_B = 4;

public static final int DOUBLE_SOLENOID_TWO_CHANNEL_A = 5;
public static final int DOUBLE_SOLENOID_TWO_CHANNEL_B = 6;

public static final int DOUBLE_SOLENOID_THREE_CHANNEL_A = 7;
public static final int DOUBLE_SOLENOID_THREE_CHANNEL_B = 2;
}
1 change: 0 additions & 1 deletion src/main/java/frc/robot/commands/MoveMotors.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class MoveMotors extends CommandBase {
Motors motors;

public MoveMotors(Motors motors, Supplier<Double> power, Supplier<Boolean> isFinished) {
addRequirements(motors);
this.power = power;
this.motors = motors;
this.isFinished = isFinished;
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/frc/robot/commands/SetSolenoids.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package frc.robot.commands;

import java.util.function.Supplier;

import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.subsystems.DoubleSolenoids;
import edu.wpi.first.wpilibj.DoubleSolenoid.Value;

/** Creates a new SetSolenoids. */
public class SetSolenoids extends CommandBase {
DoubleSolenoids doubleSolenoids;
Supplier<Value> value;
Supplier<Boolean> isFinished;

public SetSolenoids(DoubleSolenoids doubleSolenoids, Supplier<Value> value, Supplier<Boolean> isFinished) {
addRequirements(doubleSolenoids);
this.value = value;
this.doubleSolenoids = doubleSolenoids;
this.isFinished = isFinished;
}

@Override
public void initialize() {
}

@Override
public void execute() {
this.doubleSolenoids.setSolenoids(value.get());
}

@Override
public void end(boolean interrupted) {
}

@Override
public boolean isFinished() {
return this.isFinished.get();
}
}
18 changes: 11 additions & 7 deletions src/main/java/frc/robot/subsystems/DoubleSolenoids.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package frc.robot.subsystems;

import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.DoubleSolenoid.Value;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

/**
* Creates a new DoubleSolenoids.
*/
/** Creates a new DoubleSolenoids. */
public class DoubleSolenoids extends SubsystemBase {
private int doubleSolenoids[];
DoubleSolenoid doubleSolenoids[];

public DoubleSolenoids(int... doubleSolenoids) {
for(int i = 0; i < doubleSolenoids.length; i++){
this.doubleSolenoids[i] = new DoubleSolenoid
public DoubleSolenoids(DoubleSolenoid... doubleSolenoids) {
for (int i = 0; i < doubleSolenoids.length; i++) {
this.doubleSolenoids[i] = doubleSolenoids[i];
}
}

public void setSolenoids(Value value) {
for (DoubleSolenoid doubleSolenoid : this.doubleSolenoids) {
doubleSolenoid.set(value);
}
}

@Override
Expand Down
42 changes: 16 additions & 26 deletions src/main/java/frc/robot/subsystems/Motors.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,29 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

package frc.robot.subsystems;

import edu.wpi.first.wpilibj.VictorSP;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandBase;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

/**
* Creates a new Motor, and hold all the functions of said motor.
*/
/**
* Creates a new Motor, and hold all the functions of said motor.
*/
public class Motors extends SubsystemBase {
VictorSP motors[];
private SpeedController motors[];

public Motors(int... motors) {
for (int i = 0; i < this.motors.length; i++) {
this.motors[i] = new VictorSP(motors[i]);
}
public Motors(SpeedController... motors) {
this.motors = motors;
}

public Motors(){
public Motors(CommandBase command, SpeedController... motors) {
this(motors);
command.addRequirements(this);
setDefaultCommand(command);
}

public void moveMotors(double power){
for (VictorSP victor : this.motors){
victor.set(power);
public void moveMotors(double power) {
for (SpeedController speedController : this.motors) {
speedController.set(power);
}
}

@Override
public void periodic() {
// This method will be called once per scheduler run
}

}
Loading