Skip to content

Commit

Permalink
got joystick to work
Browse files Browse the repository at this point in the history
  • Loading branch information
ss0g committed Jan 15, 2022
1 parent 9958e57 commit 01f1c2d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 65 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/spartronics4915/frc/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.spartronics4915.frc.Constants;
import com.spartronics4915.frc.commands.ExampleCommand;
import com.spartronics4915.frc.commands.JoystickMotorCommands;
import com.spartronics4915.frc.commands.JoystickMotorCommand;
import com.spartronics4915.frc.subsystems.ExampleSubsystem;
import com.spartronics4915.frc.subsystems.JoystickMotor;
import com.spartronics4915.lib.subsystems.SpartronicsSubsystem;
Expand Down Expand Up @@ -34,7 +34,7 @@ public class RobotContainer
public final JoystickMotor mJoystickMotor;

// public final ExampleCommand mAutoCommand;
public final JoystickMotorCommands mJoystickMotorCommands;
public final JoystickMotorCommand mJoystickMotorCommands;

// private final int kJoystickPort = Constants.OI.kJoystickId;
public static final Joystick mDriverController = new Joystick(Constants.OI.kJoystickId);
Expand All @@ -49,12 +49,12 @@ public RobotContainer()
// mAutoCommand = new ExampleCommand(mExampleSubsystem);

mJoystickMotor = JoystickMotor.getInstance();
mJoystickMotorCommands = new JoystickMotorCommands(mJoystickMotor);
mJoystickMotorCommands = new JoystickMotorCommand(mJoystickMotor);

configureButtonBindings();
SmartDashboard.putString("Container","Completed");

mJoystickMotor.setDefaultCommand(new JoystickMotorCommands(mJoystickMotor));
mJoystickMotor.setDefaultCommand(new JoystickMotorCommand(mJoystickMotor));
}

/** Use this method to define your button ==> command mappings. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.spartronics4915.frc.commands;

import edu.wpi.first.wpilibj2.command.CommandBase;
import edu.wpi.first.wpilibj.Joystick;

import com.spartronics4915.frc.Constants;
import com.spartronics4915.frc.subsystems.JoystickMotor;

public class JoystickMotorCommand extends CommandBase
{
private final JoystickMotor mJoystickMotor;
private final Joystick mJoystick;
private boolean mInverted;
private boolean mSlow;

public JoystickMotorCommand(JoystickMotor motor)
{
mJoystickMotor = motor;
mJoystick = motor.getJoystick();
mInverted = false;
mSlow = false;
addRequirements(mJoystickMotor);
}

@Override
public void execute()
{
double y = -1 * mJoystick.getY();

if (mSlow)
{
y *= Constants.JoystickMotorConstants.kMotorSlowSpeed;
}

if (mInverted)
{
y *= -1;
}

// copied from 2020-InfiniteRecharge, no idea how it works (magic)
y = Math.copySign(Math.pow(Math.abs(y), 5.0/3.0), y); // apply response curve
mJoystickMotor.set(applyDeadzone(y, Constants.JoystickMotorConstants.kJoystickDeadzone));
}

// also copied from ir2020
private double applyDeadzone(double val, double deadzone)
{
if (Math.abs(val) < deadzone)
{
return 0.0;
}
return val;
}
}

This file was deleted.

0 comments on commit 01f1c2d

Please sign in to comment.