İ did the coding with no errors but it doesnt works

Hello i wrote the code it has no errors and it succesffully deployed to robot i looked at driver station
and everything looks ok but the robot doesnt moves can you pls help me ?

The code:
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot;
import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax;
import edu.wpi.first.wpilibj.motorcontrol.PWMMotorController;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj.motorcontrol.Spark;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.drive.MecanumDrive;

  • The VM is configured to automatically run this class, and to call the functions corresponding to

  • each mode, as described in the TimedRobot documentation. If you change the name of this class or

  • the package after creating this project, you must also update the build.gradle file in the

  • project.
    public class Robot extends TimedRobot {

    • This function is run when the robot is first started up and should be used for any
    • initialization code.

    private PWMSparkMax leftMotor1 = new PWMSparkMax(1);
    private PWMSparkMax leftMotor2 = new PWMSparkMax(2);
    private PWMSparkMax rightMotor1 = new PWMSparkMax(4);
    private PWMSparkMax rightMotor2 = new PWMSparkMax(3);

    private Joystick joy1 = new Joystick(0);

public void robotInit() {}

public void robotPeriodic() {}

public void autonomousInit() {}

public void autonomousPeriodic() {}

public void teleopInit() {}

public void teleopPeriodic() {
double speed = -joy1.getRawAxis(1) * 0.6;
double turn = joy1.getRawAxis(3) * 0.3;

double left = speed + turn;
double right = speed - turn;



public void disabledInit() {}

public void disabledPeriodic() {}

public void testInit() {}

public void testPeriodic() {}

public void simulationInit() {}

public void simulationPeriodic() {}

I can think of a few things that might be wrong with it just from what I can see now.

  1. Make sure your joystick is connected.
  2. Your motor IDs might be wrong.
  3. I’m not sure that’s the correct name for a sparkMax (I don’t know which sparkMax you’re using so I could be wrong about that)

Was this your first time deploying code and opening driver station on your laptop?

If yes, be sure to follow these steps to set up your team number in there and check your joystick’s are connected properly

Some of what you have in that code should really be in constants instead, but can you also just post your github repo so we can see your drive subsystem?

1 Like

Print the values of left and right to assure that you are telling the motors to operate.

Have you set the correct motor type - brushless/brushed?

Verify that your PWM wiring to the motor controllers is correct. (You haven’t confused CAN with PWM, have you? CAN has different wiring and different Java code.)

Post the complete rioLOG for the deploy through failure to perform correctly.

1 Like

Some good things to check so far but I would just like to add:

İ did the coding with no errors but it doesnt work

Welcome to the rest of your programming career!


The code looks perfectly fine and should work IF:

  1. Your joystick is connected and appears in the top-most slot on the USB tab of the driverstation application (show a screenshot if unsure)
  2. Your motors are each controlled by a REV SparkMax motor controller and connected to PWM ports 1-4 on the roborio.
  3. Your driver station application is using the latest version, configured with your team number, and enabled in teleop mode

Check each of these and tell us which doesn’t match. If they all do, please provide more information about what you’ve tried and how it isn’t working.

Also, please tell us what the lights on the top of each of the SparkMax’s is doing when you attempt to drive.

1 Like

When you successfully deploy does driver station say Disabled or or No Communication or No Robot Code?

i dont understood what have you meant by orinting motor values

no it says everything is perfect in driver station everything looks ok
but when we use the controller it doesnt moves

this one

Are you sure you’re using the right joystick axes? On an xbox controller you’d want to use 0 and 4 for your throttle and turn. To make sure, go to driverstation and click the USB icon on the left-hand side of the window. That will tell you if a) you are actually getting a joystick reading, and b) what port it’s running on. If you click on the joystick in the driverstation window, it’ll also give you a rundown of the buttons and axes on the controller

Other posts here helped make sure the joystick values are correctly used. Add a print statement to these statements to verify successfully accessing the joysticks.

double left = speed + turn;
double right = speed - turn;
System.out.println("left " + left + ", right " + right);
1 Like

Then your code should be correct if your using pwm, but if your using CAN then replace pwm with CAN.

Can you just post screenshots and your full code so we can help diagnose. Get a screenshot of each of the tabs on the left side of the driver station.

What motors are you using with the spark max? Are you using pwm or are you using CAN?

You’ve updated all your device firmware? Do your motors move if you try controlling them using Rev hardware client?

Did you check the steps I sent in my first post about entering your team number in driver station to match the team number you set up on the Roborio?

Is there a specific reason you are using PWMs instead of CAN for these Spark Max’s ?
Nobody here has asked so I figured I would. Do you know the difference or did you find some example code and follow that ? If your really using CAN did you set the IDs properly ?