View Single Post
  #7   Spotlight this post!  
Unread 11-12-2013, 18:25
Domenic Rodriguez's Avatar
Domenic Rodriguez Domenic Rodriguez is offline
Registered User
FRC #0316 (LuNaTeCs)
Team Role: College Student
 
Join Date: Sep 2010
Rookie Year: 2011
Location: Grove City, PA
Posts: 213
Domenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura about
Re: Help with Test Robot program (NetBeans)

After looking over the updated code, I have come up with some more points for you to consider:

- When subclassing IterativeRobot, there is no need to override the robotMain(), autonomous(), operatorControl(), or startCompetition() methods. operatorControl() and autonomous() are used by the SimpleRobot class, and robotMain() and startCompetition() have already been setup in the IterativeRobot class

- IterativeRobot is an iterative style of programming as the name implies. The teleopPeriodic() method will be automatically called at a fixed interval (about 20 ms). This means that the method needs to return quickly, so you shouldn't place any loops inside of it.

- Since the periodic methods are called repeatedly, any setup code should be placed in an init method. The IterativeRobot framework provides a robotInit() method that is called once at the start of the program as well as an init method called at the start of each game period (autonomousInit(), teleopInit(), disabledInit(), testInit()).

- Some of the variables for your robot class were prefaced with the 'static' keyword and thus class variables. While this shouldn't break your code, you will usually want to use instance variables instead of class variables for the main robot class.

- You are still using the watchdog. While I don't have documentation to back me up, I believe most would agree that it is usually better to avoid using the watchdog these days. The RobotDrive method has built in methods for handling safety/timeouts. See the code example at the end of my post.

- Inside your teleopPeriodic() method there seems to be a conflict with controlling the motors. You start by calling driveTrain.tankDrive() which sets the left and right motors. But then underneath you have a series of if statements that sets both motors to one of two values:

Code:
public void teleopPeriodic() {
    driveTrain.tankDrive(leftJoystick, rightJoystick);

    if(leftJoystick.getTrigger()) {
        leftVictor.set(0.7);
    } else {
        leftVictor.set(0.0);
    }

    if(rightJoystick.getTrigger()) {
        rightVictor.set(0.7);
    } else {
        rightVictor.set(0.0);
    }
}
Every time this runs, you end up setting both motors to either 0.7 or 0.0, overriding the tank drive. Removing the else statements should fix this problem, allowing the motors to default to the joystick values when their respective buttons are not pressed.

Below is a modified version of your code with these changes made. One other thing I changed was moving the constructors to the variable declarations to save space.
Code:
package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.SpeedController;

/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the IterativeRobot
* 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 TestRobot extends IterativeRobot {
    private Joystick leftJoystick = new Joystick(2);
    private Joystick rightJoystick = new Joystick(1);
    private SpeedController leftVictor = new Victor(2);
    private SpeedController rightVictor = new Victor(1);
    private RobotDrive driveTrain = new RobotDrive(leftVictor, rightVictor);

    /**
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
     */
    public void robotInit() {
        driveTrain.setSafetyEnabled(true);
        driveTrain.setExpiration(0.2);
    }

    /**
     * This function is called periodically during operator control
     */
    public void teleopPeriodic() {
        driveTrain.tankDrive(leftJoystick, rightJoystick);

        if(leftJoystick.getTrigger()) {
            leftVictor.set(0.7);
        }

        if(rightJoystick.getTrigger()) {
            rightVictor.set(0.7);
        }
    }
}
Phew, that was more than I thought it would be when I started writing this post. Sorry for the wall of text. One last thing: when using the code tags, make sure the second tag has a slash after the opening bracket like this "[/code]".
__________________

LuNaTeCs - Learning Under Nurturing Adults Teaching Engineering Concepts and Skills - Small and Mighty!

FRC 316 LuNaTeCs - Student (2011-2014), Lead Programmer (2011-2014), Team Captain (2013-2014), Operator (2013), Drive Coach (2014), Mentor (2015-????)
'11 Philly Regional Finalists, '13 Chestnut Hill Finalists, '13 Lenape Champions, '13 Archimedes Division, '14 Chestnut Hill Champions, '14 Lenape Champions
FTC 7071 EngiNerds - Founding Advisor (2013-2014) | FRC 5420 Velocity - Founding Advisor (2015)
Grove City College Class of '18, Electrical/Computer Engineering (B.S.E.E)

Reply With Quote