Go to Post cue Dave Lavery with some witty response - Taylor [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 02-12-2013, 15:58
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
Help with Test Robot program (NetBeans)

I am running a test program on my team's test robot and the victors keep blinking even when the robot is enabled. As far as I know, the victors are not receiving information but according to my program they should. I've been working to solve this problem for a very long time now so I've changed the victors, PWM and wires but still no luck. I don't think there is a problem with program but here it is:

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.RobotBase;
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 RobotBase {
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() {
driveTrain = new RobotDrive(2,1);
leftJoystick = new Joystick(2);
leftVictor = new Victor (1);
//leftPWM = new PWM (2);
rightJoystick = new Joystick(1);
rightVictor = new Victor (1);
//rightPWM = new PWM (1);
}

/**
* 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);
}
}
}
}
}
}

please give me any advice that you can come up with thank you!

- Team 2064
Captain/Programmer
Reply With Quote
  #2   Spotlight this post!  
Unread 02-12-2013, 16:35
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 431
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: Help with Test Robot program (NetBeans)

Your class extends RobotBase, which isn't a problem, except for that you've written your auto and teleop code inside of methods which are never called. If you take a look at the linnked javadoc for RobotBase, you will see that it has no notion of robotInit, autonomousPeriodic, or teleopPeriodic methods.

If you wanted to continue to extend RobotBase, you need to call these methods appropriately from your startCompetition method.

However, I would suggest you take a look at the IterativeRobot class. If your TestRobot class extended IterativeRobot, then you should be able to get rid of the startCompetition method in your code. robotInit, and the auto/teleopPeriodic metyhods would be called as described in the javadoc. Currently though you have while loops inside your teleopPeriodic method. If you use the iterative robot project, the auto and teleopPeriod methods are already going to be called periodically (50 times per second per javadoc), so you want them to complete quickly. If there are loops in these methods you want to be sure they won't take longer than 20ms to complete.

Alternatively, if you want to have while loops in your teleop or auto methods, take a look at the SimpleRobot class.


Also, I would recommend not using the watchdog, at least not until you get everything up and running. It's just one more thing that could go wrong and confuse the issue. For example, it's currently not being fed inside your while loop in the teleopPeriodic method, so the robot should stop working after 0.2 sec. per your code.

Hopefully that gets you moving in the right direction. In the future use the "[code]" tags around your code so it's easier for people to read.
__________________
http://team2168.org
Reply With Quote
  #3   Spotlight this post!  
Unread 02-12-2013, 16:48
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)

One thing I noticed that might affect your PWM outputs is that you are using the wrong constructor for RobotDrive. When you pass the RobotDrive constructor port numbers as the parameters, it creates internal instances of the Jaguar class for the speed controllers. Your code then creates Victors using the same PWM ports as the Jaguars that RobotDrive created:
Code:
driveTrain = new RobotDrive(2, 1);
leftVictor = new Victor(2);
rightVictor = new Victor(1);
Instead, you should create your Victors first, and then pass them to the RobotDrive constructor:
Code:
leftVictor = new Victor(2);
rightVictor = new Victor(1);
driveTrain = new RobotDrive(leftVictor, rightVictor);
Also, as opposed to using the watchdog, you may want to use the MotorSafety methods provided by the RobotDrive class.The RobotDrive#setSafetyEnabled() and RobotDrive#setExpiration() methods should provide similar functionality without using the global watchdog.
__________________

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)


Last edited by Domenic Rodriguez : 02-12-2013 at 16:56. Reason: Added info on MotorSafety methods
Reply With Quote
  #4   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
  #5   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,572
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
  #6   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
  #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
  #8   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 12:44.

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