Well I got code to compile and deploy but nothing functions

#1

Here is the code:

 /*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 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.Joystick;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.drive.MecanumDrive;
//import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType;
//import edu.wpi.first.wpilibj.hal.HAL;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.Spark;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.DigitalInput;




/**
 * This is a demo program showing how to use Mecanum control with the RobotDrive
 * class.
 */
public class Robot extends TimedRobot {
  private static final int kFrontLeftChannel = 2;
  private static final int kRearLeftChannel = 3;
  private static final int kFrontRightChannel = 1;
  private static final int kRearRightChannel = 0;

  private static final int kJoystickChannel = 0;

  private MecanumDrive m_robotDrive;
  private Joystick m_stick;

  @Override
  public void robotInit() {
    var m_frontLeft = new Spark(0);	
    var m_rearLeft = new Spark(1);
	  var m_frontRight = new Spark(14);	
	  var m_rearRight = new Spark(15);

    // Invert the left side motors.
    // You may need to change or remove this to match your robot.
    m_frontLeft.setInverted(true);
    m_rearLeft.setInverted(true);

    var m_robotDrive = new MecanumDrive(m_frontLeft, m_rearLeft, m_frontRight, m_rearRight);

    var m_stick = new Joystick(kJoystickChannel);

    
  JoystickButton button1 = new JoystickButton(m_stick, 1);

  
  
  

    
    


  }

  //Override
  public void teleopPeriodic() {
    // Use the joystick X axis for lateral movement, Y axis for forward
    // movement, and Z axis for rotation.
    m_robotDrive.driveCartesian(m_stick.getX(), m_stick.getY(),
        m_stick.getZ(), 0.0);

    DoubleSolenoid launchersolenoid = new DoubleSolenoid(1, 2);

			
            

    //launchersolenoid.set(DoubleSolenoid.Value.kOff);
    //launchersolenoid.set(DoubleSolenoid.Value.kForward);
    //launchersolenoid.set(DoubleSolenoid.Value.kReverse);

    if(m_stick.getRawButton(1))
{
    launchersolenoid.set(DoubleSolenoid.Value.kForward);
    
}
else
{
    launchersolenoid.set(DoubleSolenoid.Value.kReverse);
}
//Compressor On and Off Code

  DigitalInput getPressureSwitchValue = new DigitalInput(2);
  Relay CompressorSwitch = new Relay(1);

 

  //CompressorSwitch.set(Relay.Value.kOn);

  //CompressorSwitch.set(Relay.Value.kOff);

  if(getPressureSwitchValue.get() == true) {
    CompressorSwitch.set(Relay.Value.kOn);
  } else {
    CompressorSwitch.set(Relay.Value.kOff);
  }
  



  }


}

I can add a photo of the wiring too if it would help

0 Likes

#2

You need to move all of the “new” calls (e.g. new DigitalInput, new Relay, new DoubleSolenoid) into robotInit. Calling them from teleopPeriodic() will basically instantly raise an exception on enabling the robot because it will be seen as trying to double-allocate these resources the second time teleopPeriodic is called (it’s called periodically during teleop, hence the name).

In the future, it would be helpful to not only provide the code but be more specific than “nothing functions” when it comes to symptoms–what does the DS show? Is there any console/RioLog output, etc. In this case I would expect you to see “No Robot Code” for a brief bit after enabling the robot, and a stacktrace to appear in the log window.

0 Likes

#3

Ok did that now getting these errors:

C:\Users\Administrator\Desktop\t-SHIRT launcher\t-shirt_Launcher\t-shirtattempt\src\main\java\frc\robot\Robot.java:100: error: cannot find symbol
    launchersolenoid.set(DoubleSolenoid.Value.kForward);
    ^
  symbol:   variable launchersolenoid
  location: class Robot
C:\Users\Administrator\Desktop\t-SHIRT launcher\t-shirt_Launcher\t-shirtattempt\src\main\java\frc\robot\Robot.java:105: error: cannot find symbol
    launchersolenoid.set(DoubleSolenoid.Value.kReverse);
    ^
  symbol:   variable launchersolenoid
  location: class Robot
C:\Users\Administrator\Desktop\t-SHIRT launcher\t-shirt_Launcher\t-shirtattempt\src\main\java\frc\robot\Robot.java:117: error: cannot find symbol
  if(getPressureSwitchValue.get() == true) {
     ^
  symbol:   variable getPressureSwitchValue
  location: class Robot
C:\Users\Administrator\Desktop\t-SHIRT launcher\t-shirt_Launcher\t-shirtattempt\src\main\java\frc\robot\Robot.java:118: error: cannot find symbol
    CompressorSwitch.set(Relay.Value.kOn);
    ^
  symbol:   variable CompressorSwitch
  location: class Robot
C:\Users\Administrator\Desktop\t-SHIRT launcher\t-shirt_Launcher\t-shirtattempt\src\main\java\frc\robot\Robot.java:120: error: cannot find symbol
    CompressorSwitch.set(Relay.Value.kOff);
    ^
  symbol:   variable CompressorSwitch
  location: class Robot
5 errors

also tried using just the meccanum code and get this printout:

ERROR 1 MecanumDrive… Output not updated often enough. edu.wpi.first.wpilibj.MotorSafety.check(MotorSafety.java:101)

0 Likes

#4

In your code you see how the private MecanumDrive m_robotDrive; is at the top, and then you initialize it separately in robotInit() with var m_robotDrive = new MecanumDrive(m_frontLeft, m_rearLeft, m_frontRight, m_rearRight);

You need to do the same with all your other objects. By moving the entirty to robotInit(), the objects won’t exist for teleopPeriodic().

0 Likes

#5

can you give me an example for one of the ones I need to add still figuring the coding thing out since I’m using our FRC stuff from last year but only know vex from this year

0 Likes

#6

I’m at this point now:

     /*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 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.Joystick;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.drive.MecanumDrive;
//import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType;
//import edu.wpi.first.wpilibj.hal.HAL;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.Spark;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.DigitalInput;




/**
 * This is a demo program showing how to use Mecanum control with the RobotDrive
 * class.
 */
public class Robot extends TimedRobot {
  private static final int kFrontLeftChannel = 2;
  private static final int kRearLeftChannel = 3;
  private static final int kFrontRightChannel = 1;
  private static final int kRearRightChannel = 0;

  private static final int kJoystickChannel = 0;

  private MecanumDrive m_robotDrive;
  private Joystick m_stick;
  private DoubleSolenoid launchersolenoid;
  private DigitalInput getPressureSwitchValue;
  private Relay CompressorSwitch;
  private JoystickButton launchersolenoid;

  @Override
  public void robotInit() {
    var m_frontLeft = new Spark(0);	
    var m_rearLeft = new Spark(1);
	  var m_frontRight = new Spark(14);	
	  var m_rearRight = new Spark(15);

    // Invert the left side motors.
    // You may need to change or remove this to match your robot.
    m_frontLeft.setInverted(true);
    m_rearLeft.setInverted(true);

    var m_robotDrive = new MecanumDrive(m_frontLeft, m_rearLeft, m_frontRight, m_rearRight);

    var m_stick = new Joystick(kJoystickChannel);

    var launchersolenoid = new DoubleSolenoid(1,2);



    var getPressureSwitchValue = new DigitalInput(2);
    var CompressorSwitch = new Relay(1);


    var button1 = new JoystickButton(m_stick, 1);

  
  
  

    
    


  }

  //Override
  public void teleopPeriodic() {
    // Use the joystick X axis for lateral movement, Y axis for forward
    // movement, and Z axis for rotation.
    m_robotDrive.driveCartesian(m_stick.getX(), m_stick.getY(),
        m_stick.getZ(), 0.0);



			
            

    //launchersolenoid.set(DoubleSolenoid.Value.kOff);
    //launchersolenoid.set(DoubleSolenoid.Value.kForward);
    //launchersolenoid.set(DoubleSolenoid.Value.kReverse);

    if(m_stick.getRawButton(1))
{
    launchersolenoid.set(DoubleSolenoid.Value.kForward);
    
}
else
{
    launchersolenoid.set(DoubleSolenoid.Value.kReverse);
}
//Compressor On and Off Code



 

  //CompressorSwitch.set(Relay.Value.kOn);

  //CompressorSwitch.set(Relay.Value.kOff);

  if(getPressureSwitchValue.get() == true) {
    CompressorSwitch.set(Relay.Value.kOn);
  } else {
    CompressorSwitch.set(Relay.Value.kOff);
  }
  



  }


}
0 Likes

#7

Anywhere you are declaring the variable, AND using the new keyword inside the teleopPeriodic() method.

DoubleSolenoid launchersolenoid = new DoubleSolenoid(1, 2);
DigitalInput getPressureSwitchValue = new DigitalInput(2);
Relay CompressorSwitch = new Relay(1);

0 Likes

#8

I have those moved to innit have them declared with the private and got code to deploy are there any other specifics? I know it at least moved before so the drivebase shoudl still be working

 /*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 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.Joystick;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.drive.MecanumDrive;
//import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType;
//import edu.wpi.first.wpilibj.hal.HAL;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.Spark;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.DigitalInput;




/**
 * This is a demo program showing how to use Mecanum control with the RobotDrive
 * class.
 */
public class Robot extends TimedRobot {
  private static final int kFrontLeftChannel = 2;
  private static final int kRearLeftChannel = 3;
  private static final int kFrontRightChannel = 1;
  private static final int kRearRightChannel = 0;
  private static final int kJoystickChannel = 0;
  private MecanumDrive m_robotDrive;
  private Joystick m_stick;
  private DoubleSolenoid launchersolenoid;
  private DigitalInput getPressureSwitchValue;
  private Relay CompressorSwitch;

  @Override
  public void robotInit() {
    var m_frontLeft = new Spark(0);	
    var m_rearLeft = new Spark(1);
	  var m_frontRight = new Spark(14);	
	  var m_rearRight = new Spark(15);

    // Invert the left side motors.
    // You may need to change or remove this to match your robot.
    m_frontLeft.setInverted(true);
    m_rearLeft.setInverted(true);

    var m_robotDrive = new MecanumDrive(m_frontLeft, m_rearLeft, m_frontRight, m_rearRight);
    var m_stick = new Joystick(kJoystickChannel);
    var launchersolenoid = new DoubleSolenoid(1,2);
    var getPressureSwitchValue = new DigitalInput(2);
    var CompressorSwitch = new Relay(1);

  
  
  

    
    


  }

  //Override
  public void teleopPeriodic() {
    // Use the joystick X axis for lateral movement, Y axis for forward
    // movement, and Z axis for rotation.
    m_robotDrive.driveCartesian(m_stick.getX(), m_stick.getY(),
        m_stick.getZ(), 0.0);



			
            

    //launchersolenoid.set(DoubleSolenoid.Value.kOff);
    //launchersolenoid.set(DoubleSolenoid.Value.kForward);
    //launchersolenoid.set(DoubleSolenoid.Value.kReverse);

    if(m_stick.getRawButton(1))
{
    launchersolenoid.set(DoubleSolenoid.Value.kForward);
    
}
else
{
    launchersolenoid.set(DoubleSolenoid.Value.kReverse);
}
//Compressor On and Off Code



 

  //CompressorSwitch.set(Relay.Value.kOn);

  //CompressorSwitch.set(Relay.Value.kOff);

  if(getPressureSwitchValue.get() == true) {
    CompressorSwitch.set(Relay.Value.kOn);
  } else {
    CompressorSwitch.set(Relay.Value.kOff);
  }
  



  }


}
0 Likes

#9

I am also now getting the error saying this: ERROR 1 MecanumDrive… Output not updated often enough. edu.wpi.first.wpilibj.MotorSafety.check(MotorSafety.java:101)

0 Likes

#10

I barely know what the var keyword does (just looked it up a second ago), but you shouldn’t need it on these lines, and having it may do weird things:

var m_robotDrive = new MecanumDrive(m_frontLeft, m_rearLeft, m_frontRight, m_rearRight);
var m_stick = new Joystick(kJoystickChannel);
var launchersolenoid = new DoubleSolenoid(1,2);
var getPressureSwitchValue = new DigitalInput(2);
var CompressorSwitch = new Relay(1);

Apart from that, it looks good.

0 Likes

#11

ok I’ll remove that

0 Likes

#12

alright now different error with those removed what should be in front of those?

edit: nevermind have the proper things in front of those testing code again

0 Likes

#13

You shouldn’t need anything additional in front of those.
Now, the way you have it, you DO want var in front of these lines:

var m_frontLeft = new Spark(0);	
var m_rearLeft = new Spark(1);
var m_frontRight = new Spark(14);	
var m_rearRight = new Spark(15);

OR
you want to replace var with Spark.

0 Likes

#14

thanks got those parts fixed and code deployed but getting the safety error still in the drivestation print out

This error:

ERROR 1 MecanumDrive… Output not updated often enough. edu.wpi.first.wpilibj.MotorSafety.check(MotorSafety.java:101)

0 Likes

#15

One thing to check there is if you have the most up-to-date image on the RIO. I know there was an issue fixed involving the Drive MotorSafety WatchDogs earlier this season. I believe it should be v14, and i believe this can be checked on the diagnostics tab of the DriverStation.

Otherwise, I’m not sure why you are seeing that issue. Everything else looks good.

0 Likes

#16

checked and the rio is v14 I’m reupdating it again to be safe hopefully i can get this working today or monday since we need it by the 18th

if that doesn’t work is there a way to just disable that?

0 Likes

#17

also thanks for trying to help and dealing with me

0 Likes

#18

also getting this as output in the drivers station now:

ERROR 1 Unhandled exception: java.lang.NullPointerException frc.robot.Robot.teleopPeriodic(Robot.java:82)
Warning at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:274): Robots should not quit, but yours did!
ERROR 1 The startCompetition() method (or methods called by it) should have handled the exception above. edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:276)

0 Likes

#19

I HIGHLY recommend AGAINST disabling the MotorSafety watchdogs. They are there to stop the motors in the event the robot locks up or otherwise stops taking in user input.

For the new error, what is Robot.java line 82? Go ahead and post your updated code if you need help there. Also, it may be a good idea to do the same thing with your Spark objects as you did with everything else. (Move Spark m_<direction><side>; to the top area, and then just have m_<direction><side> = new Spark(<port>); in the robotInit() )

0 Likes

#20

Heres what I’m at now sadly club is wrapping up so I have to wait till monday to finish work the other great thing is now one of the sparks was tripping a breaker

/----------------------------------------------------------------------------/
/* Copyright © 2017-2018 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.Joystick;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.drive.MecanumDrive;
//import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType;
//import edu.wpi.first.wpilibj.hal.HAL;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.Spark;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.DigitalInput;




/**
 * This is a demo program showing how to use Mecanum control with the RobotDrive
 * class.
 */
public class Robot extends TimedRobot {
  private static final int kFrontLeftChannel = 2;
  private static final int kRearLeftChannel = 3;
  private static final int kFrontRightChannel = 1;
  private static final int kRearRightChannel = 0;
  private static final int kJoystickChannel = 0;
  private MecanumDrive m_robotDrive;
  private Joystick m_stick;
  private DoubleSolenoid launchersolenoid;
  private DigitalInput getPressureSwitchValue;
  private Relay CompressorSwitch;

  @Override
  public void robotInit() {


  Spark  m_frontLeft = new Spark(0);	
  Spark  m_rearLeft = new Spark(1);
	Spark  m_frontRight = new Spark(2);	
  Spark  m_rearRight = new Spark(3);
  MecanumDrive  m_robotDrive = new MecanumDrive(m_frontLeft, m_rearLeft, m_frontRight, m_rearRight);
  Joystick  m_stick = new Joystick(kJoystickChannel);
  DoubleSolenoid launchersolenoid = new DoubleSolenoid(1,2);
  DigitalInput  getPressureSwitchValue = new DigitalInput(2);
  Relay CompressorSwitch = new Relay(1);

    // Invert the left side motors.
    // You may need to change or remove this to match your robot.
    m_frontLeft.setInverted(true);
    m_rearLeft.setInverted(true);

  
  
  

    
    


  }

  //Override
  public void teleopPeriodic() {
    // Use the joystick X axis for lateral movement, Y axis for forward
    // movement, and Z axis for rotation.
    m_robotDrive.driveCartesian(m_stick.getX(), m_stick.getY(),
        m_stick.getZ(), 0.0);



			
            

    //launchersolenoid.set(DoubleSolenoid.Value.kOff);
    //launchersolenoid.set(DoubleSolenoid.Value.kForward);
    //launchersolenoid.set(DoubleSolenoid.Value.kReverse);

    if(m_stick.getRawButton(1))
{
    launchersolenoid.set(DoubleSolenoid.Value.kForward);
    
}
else
{
    launchersolenoid.set(DoubleSolenoid.Value.kReverse);
}
//Compressor On and Off Code



 

  //CompressorSwitch.set(Relay.Value.kOn);

  //CompressorSwitch.set(Relay.Value.kOff);

  if(getPressureSwitchValue.get() == true) {
    CompressorSwitch.set(Relay.Value.kOn);
  } else {
    CompressorSwitch.set(Relay.Value.kOff);
  }
  



  }


}
0 Likes