Cant strafe on a swerve, programming or electrical issue?

Context: Our team has finally received our Swerve X modules, we hooked up 2 NEO’s w/ SparkMax, using CANCoders. We don’t have an actual chassis, so we propped up the modules on wood I copied and modified some code from FRC 0 to Autonomous (source code for that video)

Our CANCoders are connected to our turning motors’ SparkMax, so that we didn’t have to connect them into our DIO ports on the RIO (We’re reserving them for other things like limit switches).

Our Swerve code lives in this repo, more specifically, the code is divided into SwerveModule, SwerveDrive, and finally a ControlSwerve command that drives it.

In RobotContainer, we’ve created an instance of our swerve drive and then set the ControlSwerve as the default command:

private final SwerveDrive swerveDrive = new SwerveDrive();
  

  /** The container for the robot. Contains subsystems, OI devices, and commands. */
  public RobotContainer() {
    // Configure the trigger bindings
    configureBindings();
    
    swerveDrive.setDefaultCommand(new ControlSwerve(swerveDrive,
     () -> controller.getRawAxis(1)*-1,
      () -> controller.getRawAxis(2),
       () -> controller.getRawAxis(4),
        () -> true));


  }

... rest of the code ...

Now, the problem is that when I run this code, I can drive forward and back on the left axis, and rotate using the right axis. But I can’t strafe at all.

At first I thought this was a code error, but I could not identify any problems. So, I asked the electrical group of my team to see if anything was wrong, however they hadn’t noticed anything.

I was 80% sure that my code was correct, so I decided to try and run the turning motor automatically in code. Here is what I did:

At the top of my Robot class: I declared a CANSparkMax and set the id to one of the turning motors

CANSparkMax testingMotor = new CANSParkMax(2, MotorType.kBrushless);

then in teleopPeriodic() i just run the motor at .5 speed forever:

@Override
  public void teleopPeriodic() {
       testingmotor.set(.5);
}

However, when I run this motor does not move, however our SparkMax does get the signal because it “blinks”, so then I tried changing the id in the constructor to 1 (drive motor), and then our drive motor moves perfectly.

So why does the turning motor not move? Even if the SparkMax connected to it can clearly get the signal? I even checked REV Hardware client, yet I don’t see any issues there either.

So now I’m certain that this is a problem with electrical, but we are unsure as to what is causing this.

here is what our swerve electrical board looks like [Imgur album]

I got these photos before I left our robotics lab today, if anyone needs better pictures, I will update this tommorow

Are you sure you are using CANcoders? You could be using MagEncoders or CanAndCoders (Helium).

Can you move the motor using percentage control in the Rev Hardware Client?

I just double checked, and I realized that we are using SRX Mag Encoders, NOT CANCoders… I will have to change that in the code.

To answer your second question: no, we can’t move the motor using percentage control in the REV Hardware client, the only ones we’re able to move is the drive motors

For debugging purposes try unplugging the can bus when you run the motor. But does the Hardware Client have any errors or anything? Can you crank start the motor spinning?

Unfortunately you are going to have one heck of a time using MagEncoders with Sparkmaxes.

Here’s a resource on how to wire them: Using the VEX SRX Mag Encoders with Spark Max from the pictures I’m guessing you aren’t wiring it properly

Its always an electrical problem

If the code crashes, its because the rio pcb is flawed

On a more serious note, (building off above answers) I would recommend wiring your encoders to the roborio and running the control loop using the builtin motor encoder

Thanks for the swift reply, however I still have a few questions:

  1. We are using CTRE’s SRX Mag Encoders, do we have to follow a different process to get it up and running?

  2. Do I have to make major modifications in my codebase to reflect these changes? If so, would it be easier to connect the encoders into the RoboRIO instead?

Thanks, but how do I “get” the absolute encode thats plugged into the rio, like an object similar to how RelativeEncoder works in REVLib

turningMotor = new CANSparkMax(turningMotorId, MotorType.kBrushless);
RelativeEncoder encoder = turningMotor.getEncoder();

But I see no way to do this in Pheonix 6

EDIT: In other words, how do I program an SRX Mag Encoder, I only see examples from Pheonix 5 (we are using v6) and those examples only let you use the encoder if its connected to a TalonFX or something.

If you are to connect the encoders to the roborio directly, you will need one of the WPIlib encoder classes

You should use either the quaderature encoder or the duty cycle/pwm encoder, depending on your wiring

from the SRX mag encoder product page:

The device provides both a Quadrature interface that may be used for relative position measurement and a Pulse Width Modulated output for absolute position measurement

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.