Lost our last programmer

Welp, it’s nearing that time of year yet again and sadly, we have lost our Java programmer. We have yet to get any response out of our robot outside of the hello world program. Would someone verify if the following code (pulled from the generic tutorial) should work?


package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;

public class GroundZeroTemplate extends SimpleRobot {
    
    RobotDrive drive = new RobotDrive(1,3,2,4);
    Joystick leftStick = new Joystick(1);
    Joystick rightStick = new Joystick(2);
            
    /**
     * This function is called once each time the robot enters autonomous mode.
     */
    public void autonomous() {
        /*getWatchdog().setEnabled(true);
        getWatchdog().setExpiration(0.5);
        drive.drive(1,0);
        Timer.delay(2);
        drive.drive(0,0);*/
        for (int i = 0; i < 4; i++) {
            drive.drive(0.5, 0.0); // drive 50% fwd 0% turn
            Timer.delay(2.0); // wait 2 seconds
            drive.drive(0.0, 0.75); // drive 0% fwd 0% turn
        }
    }

    /**
     * This function is called once each time the robot enters operator control.
     */
    public void operatorControl() {
        while (true && isOperatorControl() && isEnabled()) // loop until change
        {
            drive.tankDrive(leftStick, rightStick); // drive w/ joysticks
            Timer.delay(0.005);
        }
    }
}

The only unique aspect of our setup is that we are using 4 motors connected to 4 jaguars in our setup instead of the default 2.

When we activate this code in both autonomous as well as user-driven modes, we get no visual response from the jaguars whatsoever nor any movement. Should I look at something in this code or do I need to start looking at electrical problems?

Thank you!

Make sure to remove this part:

/*getWatchdog().setEnabled(true);

/* starts a comment. // is appropriate there.

The above post notes that all your actions in autonomous are commented out.

I would try outputting the joystick values in the teleop code (try System.out.println() to print to Netbeans’ console) to make sure you are getting input from the joysticks. If the jaguar lights still stay solid yellow when you know joystick values are going through, I’d check the signal wiring.

Yeah, that block is commented out by design. The commented section is what was originally there, which I removed. Is watchdog required for the robot to operate? I know it’s required to be legal in play.

Let me try outputting my joysticks this afternoon and I’ll get back to you. That would be a major start.

Cool. I threw this in and am testing it now:

    public void operatorControl() {
        while (true && isOperatorControl() && isEnabled()) // loop until change
        {
            drive.tankDrive(leftStick, rightStick); // drive w/ joysticks
            Timer.delay(0.005);
            System.out.print("Left:");
            System.out.println(leftStick);
            System.out.print("right:");
            System.out.println(rightStick);
        }

I’ll update this thread when I get results.

It doesn’t look like you’re feeding the watchdog, which means your control is expiring after only half a second. I’d suggest commenting it out entirely, changing .setEnabled(false), or making sure you put in a statement to feed it periodically by calling feed().

As the comment above mentioned, /* is for when you need to make a long block comment – you need to replace that with //

The Java starter guide is slightly outdated as well, I’d suggest using the WPILib Cookbook if you haven’t seen it already.

http://www.wbrobotics.com/attachments/article/11/WPILibCookbook.pdf

Thanks for all the replies!

My responses don’t seem to be going through, so if suddenly 5 replies come out of this from me, I apologize. We got the code to work, but still can’t seem to get it to drive. I’ve gotten a response out of button presses with the suggested code. I left the whole block regarding watchdog off as it’s in the autonomous section, anyway, which we are currently not working with. In fact, let me post the following to clarify what lines we’re working with at this point:



/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. 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 edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.Relay.Value;
/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the SimpleRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class AwesomO extends SimpleRobot {
    
    RobotDrive drive = new RobotDrive(1,2);
    Joystick leftStick = new Joystick(1);
    Joystick rightStick = new Joystick(2);
    Relay firingMechanism;
    
    public void robotInit() {   
        firingMechanism = new Relay(1);
    }
    
    public void autonomous() {
        //not using autonomous atm
    }

    public void operatorControl() {
        while (true && isOperatorControl() && isEnabled()) // loop until change
        {
            drive.tankDrive(leftStick, rightStick); // drive w/ joysticks
            Timer.delay(0.005);
            System.out.println("Left: "+leftStick.getX()+", "+leftStick.getY());
            System.out.println("Right: "+rightStick.getX()+"' "+rightStick.getY());
            
            if(rightStick.getTrigger()){
                firingMechanism.set(Value.kReverse);
            }
            if(leftStick.getTrigger()){
                firingMechanism.set(Value.kForward);
            }
        }
    }
}

Currently everything works except driving. It reads the controller positions as well as pushes out relay commands (we can see blinks on the controller of red and green), however, the jaguar’s are still not responding. Do they only work whenever watchdog is correctly configured? I can throw watchdog.setenabled(false) into robotInit.

Actually, they do end the block comment. below that is the ‘for’ loop containing the active autonomous routine.

Bah! These messages aren’t going through. Test? Can I post yet?

Yes

Code looks all good from what I can tell. Why not try

drive.tankDrive(leftStick.getY(), rightStick.getX());

instead of passing the joystick objects?

I’ll give that a shot and see if it changes anything this afternoon and update this post on its success or failure.

Thanks for the help! We are much further along today than we were yesterday. Just getting some response out of the machine saying that it sees our joysticks is a big leap forward to me.

What are the LEDs of the jaguars doing?

That did it. The jaguars were blinking as if they were receiving no signal. I started nosing around at the wiring and found that the signal cables were reversed. Thanks guys. The final problems found were as follows:

24v was being handed out to the ni9201 instead of 12v.
the command cables from the sidecar were plugged in backwards.
The getX(),getY() needed to be added.

After all that, it’s driving and receiving commands. Thank you guys for helping me tackle getting this thing up and running. For reference, the final successful code for our tank drive template is as follows:


/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. 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.                                                               */
/*----------------------------------------------------------------------------*/

/* 
 * Ground Zero Template
 * This Template is to be utilized to troubleshoot the robot. Please make no
 * changes to this code. It's to be copied and branched off of for new projects
 * and is for reference only.
*/

package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.Relay.Value;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the SimpleRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class GroundZeroTemplate extends SimpleRobot {
    
    RobotDrive drive = new RobotDrive(1,2);
    Joystick leftStick = new Joystick(1);
    Joystick rightStick = new Joystick(2);
    
    Relay firingMechanism;
    
    public void robotInit() {
        firingMechanism = new Relay(1);
    }
    
    /**
     * This function is called once each time the robot enters autonomous mode.
     */
    public void autonomous() {
        /*getWatchdog().setEnabled(true);
        getWatchdog().setExpiration(0.5);
        drive.drive(1,0);
        Timer.delay(2);
        drive.drive(0,0);*/
        for (int i = 0; i < 4; i++) {
            drive.drive(0.5, 0.0); // drive 50% fwd 0% turn
            Timer.delay(2.0); // wait 2 seconds
            drive.drive(0.0, 0.75); // drive 0% fwd 0% turn
        }
    }

    /**
     * This function is called once each time the robot enters operator control.
     */
    public void operatorControl() {
        while (true && isOperatorControl() && isEnabled()) // loop until change
        {
            drive.tankDrive(leftStick.getY(), rightStick.getX()); // drive w/ joysticks
            Timer.delay(0.005);
            System.out.println("Left: "+leftStick.getX()+", "+leftStick.getY());
            System.out.println("Right: "+rightStick.getX()+"' "+rightStick.getY());
            
            if(rightStick.getTrigger()){
                firingMechanism.set(Value.kReverse);
            }
            if(leftStick.getTrigger()){
                firingMechanism.set(Value.kForward);
            }
        }
    }
}