Go to Post Sometimes it is more appropriate for an individual to listen than it is for him to speak. - JVN [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 04-12-2013, 14:44
PANTHERPROJECT's Avatar
PANTHERPROJECT PANTHERPROJECT is offline
Registered User
FRC #2064 (The Panther Project)
Team Role: Webmaster
 
Join Date: Dec 2013
Rookie Year: 2007
Location: Southbury, Middlebury
Posts: 14
PANTHERPROJECT will become famous soon enoughPANTHERPROJECT will become famous soon enough
Re: Help with Test Robot program (NetBeans)

Thank you both for your help but it still doesn't work and at this point I do not know if it is a electrical or programming issue. Any other advice?
Reply With Quote
  #2   Spotlight this post!  
Unread 04-12-2013, 14:56
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,561
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Help with Test Robot program (NetBeans)

Quote:
Originally Posted by PANTHERPROJECT View Post
Thank you both for your help but it still doesn't work and at this point I do not know if it is a electrical or programming issue. Any other advice?
It would help to post your modified code.
Reply With Quote
  #3   Spotlight this post!  
Unread 11-12-2013, 15:15
PANTHERPROJECT's Avatar
PANTHERPROJECT PANTHERPROJECT is offline
Registered User
FRC #2064 (The Panther Project)
Team Role: Webmaster
 
Join Date: Dec 2013
Rookie Year: 2007
Location: Southbury, Middlebury
Posts: 14
PANTHERPROJECT will become famous soon enoughPANTHERPROJECT will become famous soon enough
Re: Help with Test Robot program (NetBeans)

Updated code:

[code]package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Victor;
//import edu.wpi.first.wpilibj.PWM;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.SpeedController;
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 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 static RobotDrive driveTrain;
private static GenericHID leftJoystick;
private static GenericHID rightJoystick;
private SpeedController leftVictor;
private SpeedController rightVictor;
//private static PWM rightPWM;
//private static PWM leftPWM;
private boolean m_robotMainOverridden;

/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
public void robotInit() {
leftJoystick = new Joystick(2);
leftVictor = new Victor (1);
//leftPWM = new PWM (2);
rightJoystick = new Joystick(1);
rightVictor = new Victor (1);
//rightPWM = new PWM (1);
driveTrain = new RobotDrive(leftVictor, rightVictor);
}

/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {

}

/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() {
getWatchdog().setEnabled(true);
getWatchdog().setExpiration(0.2);
while (isOperatorControl() && isEnabled()) {
//driveTrain.arcadeDrive(rightJoystick);
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);
}
}
getWatchdog().feed();
}

public void robotMain() { // supplied default robotMain
System.out.println("Information: No user-supplied robotMain()");
m_robotMainOverridden = false;
}

public void autonomous() { // supplied default autonomous()
System.out.println("Provided Autonomous() method running");
}

public void operatorControl() { // suppled default operatorControl()
System.out.println("Provided OperatorControl() method running");
}

public void startCompetition() {
robotMain();
if (!m_robotMainOverridden) {
while(true) {
// Wait for robot to be enabled
while (isDisabled()) {
Timer.delay(.01);
}
// Now enabled - check if we should run Autonomous code
if (isAutonomous()) {
autonomous();
while (isAutonomous() && !isDisabled()) {
Timer.delay(.01);
}
} else {
operatorControl(); // run the operator control method
while (isOperatorControl() && !isDisabled()) {
Timer.delay(.01);
}
}
}
}
}
}[code]
Reply With Quote
  #4   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
  #5   Spotlight this post!  
Unread 31-12-2013, 11:31
PANTHERPROJECT's Avatar
PANTHERPROJECT PANTHERPROJECT is offline
Registered User
FRC #2064 (The Panther Project)
Team Role: Webmaster
 
Join Date: Dec 2013
Rookie Year: 2007
Location: Southbury, Middlebury
Posts: 14
PANTHERPROJECT will become famous soon enoughPANTHERPROJECT will become famous soon enough
Re: Help with Test Robot program (NetBeans)

Thank you so much for you help! It worked perfectly and everything makes much more sense now
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:59.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi