One side of our robot is randomly moving when enabling TeleOperated

For some reason, only one side of the robot will randomly move for seemingly no reason. It will not fully move, but only have small movements.

Where to start?

Is this the drive train you’re talking about? If not, then what?
What motor controllers and motors are you using that are twitching?
Are they connected via CAN or PWM?
Would you post your code?
Is the movement only a single blip as teleop begins, or does it continue?

Check your teleOP init. Next thing you should check is if your joysticks are zero on your driver station and add a dead band if needed. If none of that fixes your solution post your code if possible please.

1 Like

Do you have a dead zone on your controller? If not that could be it

coding? what type of coding do you use and can you post the code here?

try swapping out your controller, probably a bad joystick

Yes, this is the drivetrain. We are using 4 victor SPX controllers and CIM motors I believe connected over PWM.
Teleop command

/*----------------------------------------------------------------------------*/
/* 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.commands;
import java.util.function.DoubleSupplier;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.subsystems.DriveSubsystem;

public class TeleOpDrive extends CommandBase {
  private final DriveSubsystem drive;
  private final DoubleSupplier xSpeed;
  private final DoubleSupplier zRotation;
  
  
  
  /**
   * Creates a new TeleOpDrive.
   */
  public TeleOpDrive(DriveSubsystem drive, DoubleSupplier xSpeed, DoubleSupplier zRotation) {
    // Use addRequirements() here to declare subsystem dependencies.
    this.drive = drive;
    this.xSpeed = xSpeed;
    this.zRotation = zRotation;
    addRequirements(drive);
  }

  // Called when the command is initially scheduled.
  @Override
  public void initialize() {
  }

  // Called every time the scheduler runs while the command is scheduled.
  @Override
  public void execute() {
    drive.drive(xSpeed.getAsDouble(), zRotation.getAsDouble());
  }

  // Called once the command ends or is interrupted.
  @Override
  public void end(boolean interrupted) {
    drive.drive(0, 0);
  }

  // Returns true when the command should end.
  @Override
  public boolean isFinished() {
    return false;
  }
}

Drive Subsystem

/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018-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.drive.DifferentialDrive;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants;

public class DriveSubsystem extends SubsystemBase {
  /**
   * Creates a new DriveSubsystem.
   */
  
  private final DifferentialDrive m_robotDrive;
  public DriveSubsystem() {
    m_robotDrive = new DifferentialDrive(Constants.m_left,Constants.m_right);
  }
  public void drive(double xSpeed, double zRotation){
    m_robotDrive.arcadeDrive(xSpeed,zRotation);
  }

  public void aim(double aim){
    Constants.m_aim.set(aim);
  }

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

Constants

/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018-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;

import edu.wpi.first.wpilibj.*;
import frc.robot.subsystems.DriveSubsystem;

/**
 * The Constants class provides a convenient place for teams to hold robot-wide
 * numerical or boolean constants. This class should not be used for any other
 * purpose. All constants should be declared globally (i.e. public static). Do
 * not put anything functional in this class.
 *
 * <p>
 * It is advised to statically import this class (or one of its inner classes)
 * wherever the constants are needed, to reduce verbosity.
 */
public final class Constants {
    public static final Joystick m_stick = new Joystick(0);
    public static final Joystick m_stick2 = new Joystick(1);
    public static final SpeedController m_frontLeft = new PWMVictorSPX(0);
    public static final SpeedController m_rearLeft = new PWMVictorSPX(1);
    public static final SpeedControllerGroup m_left = new SpeedControllerGroup(m_frontLeft, m_rearLeft);

    public static final SpeedController m_frontRight = new PWMVictorSPX(3);
    public static final SpeedController m_rearRight = new PWMVictorSPX(2);
    public static final SpeedControllerGroup m_right = new SpeedControllerGroup(m_frontRight, m_rearRight);
    public static final PWMVictorSPX m_shooter = new PWMVictorSPX(4);
    public static final SpeedController m_scooper = new PWMVictorSPX(5);

    public static final Servo m_aim = new Servo(6);
    public static final DriveSubsystem drive = new DriveSubsystem();
    public static final DoubleSolenoid m_solenoid = new DoubleSolenoid(0, 1);
    public static final Compressor m_compressor = new Compressor(); //fix can ids when go school
}

It’ll twitch for a few seconds, stop, then twitch again, then stop continously.

Could you put all your code in Github and post a link? Also, exactly when does this happen? For example, enabling directly in to teleop, enabling auto, or after transition from auto to teleop?

It does sound like you need a deadband, don’t accept values any values between .03 and -.03 or something like that for the speed and rotation.

Github

Your Constants class scares me. You should not be creating motor controllers, solenoids and the like in Constants. Each of those should be moved to the subsystem that owns them and made private. What should be in Constants is the definition of the constant port values for the motor controllers and solenoids.

With all those things public in Constants it is difficult to know what code might causing the behavior you are seeing.

Also, I notice you are using the z-axis for rotation control. Depending on the joystick controller you are using, that could be a problem. For example, on some controllers, the z-axis is the throttle below the main stick and some of those are hard to get into a true 0 position.

2 Likes