Go to Post This pic became proof that engineers should never give up thier day jobs! :p - Jay H 237 [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 Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-02-2011, 07:35
professorX professorX is offline
Registered User
AKA: Xavier
FRC #1660 (The Harlem Knights)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2005
Location: New York
Posts: 62
professorX is an unknown quantity at this point
Wink Issue with autonomous mode and some newbie questions

Hi,

Our code for autonomous is not working properly. We programmed the robot to drive straight for 3 seconds and then stop. Instead of driving forward for 3 seconds and then stopping, the robot waits 10 seconds and drives forward for half a second, then waits another 10 seconds and then drives forward for half a second. We believe that it has to be something wrong with feeding the watchdog since we receive the watchdog not fed error on the dashboard.

4 Questions.
1. Could anyone take a look at the code below and tell us what our problem is with the autonomous code?
2. Also, if someone could take a look at our line sensor code to see if it will work or not, that would be great
3. I'm new to netbeans, how do you save as project (not .java file) on a usb drive or on a different location from where it was originally saved?
4. How can I debug the code using System.out.println? It never prints out anything. Are there other ways for debugging the code or knowing what values you get from sensors?

Code:
package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.AnalogTrigger;
import edu.wpi.first.wpilibj.DigitalInput;
/**
 * 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 Team1660Robot extends SimpleRobot {

    public Team1660Robot (){
        getWatchdog().setExpiration(.5);
       

    }


    /**
     * This function is called once each time the robot enters autonomous mode.
     */

    AnalogTrigger Bumper = new AnalogTrigger (1);
    Joystick rightjoystick = new Joystick(1);
    Joystick leftjoystick = new Joystick(2);
    RobotDrive robotdrive = new RobotDrive(1,2,3,4);

    DigitalInput Mid;
    DigitalInput Right;
    DigitalInput Left;
    
    Timer timer = new Timer();
    double straight = 0;
    double standardRobotSpeed = 0.5;
    double stop = 0;
    double velocity = 3;

    public void Team1660Robot(){
        Mid = new DigitalInput(2);
        Right = new DigitalInput(1);
        Left = new DigitalInput(3);
        getWatchdog().setExpiration(.5);
        getWatchdog().setEnabled(true);
    }

       public void autonomous() {
getWatchdog().setEnabled(true);
getWatchdog().feed();
       // robotdrive.tankDrive(.5,.5);
        //getWatchdog().setEnabled(false);
       // getWatchdog().feed();
       // robotdrive.tankDrive(.5,.5);
        for(int i =0; i < 10; i=+1){
            getWatchdog().feed();
            robotdrive.drive(1,0);
            Timer.delay(3);
            getWatchdog().feed();
        }
        robotdrive.drive(0,0);
        //giveADogABone(3);
       // robotdrive.tankDrive(0,0);
        //bumper();
       // followTheLine();

    }
    public void followTheLine() {
        Timer Clock = new Timer();
        robotdrive.tankDrive(.5, .5);
        Timer.delay(10);
        robotdrive.drive(0, 0);
        
        Clock.start();
        Clock.reset();
        //Clock.stop();

        if(true)
        {
            robotdrive.drive(1, 0);
            Timer.delay(5);
            robotdrive.drive(0, 0);
        }
       
        //boolean End = true;
        /*
        for(int i=0;i<10000;++i) {

            boolean MidValue = Mid.get() ? true: false;
            boolean RightValue = Right.get() ? true: false;
            boolean LeftValue = Left.get() ? true : false;
            double Velocity;
            double direction;
            if (MidValue == true && LeftValue == false && RightValue== false) {
                Velocity = 5;
                direction = 0;
                // Go Straight, tape is in center
            } else if (MidValue == true && LeftValue == true && RightValue == false){
                Velocity = .25;
                direction = -0.5;
               // Go left if tape is on slight Left//
            } else if (MidValue == true && LeftValue == false && RightValue == true){
                Velocity = .25;
                direction = 0.5;
                //Go right if tape is on slight Right//
            } else if (MidValue == false && LeftValue == true && RightValue == false){
                Velocity = .25;
                direction = -0.7;
                //Go Left if tape is on extreme Left//
            } else if (MidValue == false && RightValue == true && LeftValue == false){
                Velocity = .25;
                direction = 0.7;
                //Go Right if tape is on extreme Right//
            } else {
                Velocity = .25;
                direction = -1;


            }

           robotdrive.drive(-Velocity,-direction);

           if(Clock.get()>15)
               break;
           /* if (UseWhite) {
                A = RedValue *2 + WhiteValue *4 + BlackValue;
            } else if (UseBlack) {
                A = RedValue *2 + BlackValue *3 + WhiteValue;
            }
               else if (UseRed){
                   A = RedValue * 2 + BlackValue + WhiteValue;

            A=2;

            Velocity =2* powerProfile[timeInFull];
           turn = 0;

           switch (A) {
               case 2:
                   turn = 0;
               break;
               case 6:if(time > ClockStop) {
                   End = true;
                   Velocity = 0.0;
               }

               break;
               default: if  (A != B) {
                System.out.println("Time: " + time + " Sensor,Case: " + A + " Velocity: " + Velocity + " turn: " + turn + " End: " + End);
                   }

               break;
               Velocity = robotdrive.getVelocity;
               if (A != 0) { A = B;}
        }
        }
            *
            */


        //}

        //robotdrive.drive(stop,straight);
    }


    public void giveADogABone(double timeToWait) {
         double WatchdogDelay = 4.9;
         while (timeToWait > 0){
             getWatchdog().feed();
             if (timeToWait < WatchdogDelay){
                 Timer.delay (timeToWait);
                }
             else {
                 Timer.delay (WatchdogDelay);
             }
             timeToWait = timeToWait - WatchdogDelay;
         }
     }



    /**
     * This function is called once each time the robot enters operator control.
     */
    public void operatorControl() {
        getWatchdog().setEnabled(true);


        while(isEnabled() && isOperatorControl())
        {
            getWatchdog().feed();
            robotdrive.tankDrive(leftjoystick, rightjoystick);

            if( rightjoystick.getRawButton(8) == true) {
                getVelocity();
            }
        }
    }

    public double distance_to_time (double distance){
        double time = distance / velocity;
        return (time);
    }

    public void getVelocity (){


        robotdrive.drive(standardRobotSpeed,straight);
        //5 is the seconds to test
        Timer.delay(5);
        robotdrive.drive(stop,straight);
    }
    public void bumper(){
        int x = 1;

        while (x == 1){
            if(Bumper.getTriggerState() == false){
                robotdrive.drive(standardRobotSpeed,straight);
            }
            else {
                x = 2;
                robotdrive.drive(stop,straight);
            }
        }
    }
        }
Reply With Quote
  #2   Spotlight this post!  
Unread 11-02-2011, 09:07
Robby Unruh's Avatar
Robby Unruh Robby Unruh is offline
*insert random dial-up tone here*
FRC #3266 (Robots R Us)
Team Role: Coach
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Eaton, OH
Posts: 338
Robby Unruh will become famous soon enough
Re: Issue with autonomous mode and some newbie questions

Your problem lies here:
Code:
for(int i =0; i < 10; i=+1){
    getWatchdog().feed();
    robotdrive.drive(1,0);
    Timer.delay(3);
    getWatchdog().feed();
}
You're using a timer delay in a loop. That means that everytime the loop is called (which is two, for whatever reason) you will have a 3 second delay. Plus, since you're wanting to drive for a set amount of time in autonomous, why not use the nifty Timer class?

Code:
Timer timer = new Timer(); // you should put this in your constructor.

public void autonomous() {
    while(isAutonomous()) {
        timer.start();
        while(timer.get() < 3) { // while the timer is < 3, drive forward.
            robotDrive.drive(1,0);
            timer.stop(); // stop the timer after 3 seconds
        }
        robotDrive.drive(0,0); // stop the robot from driving any further.
    }
}
__________________
[Robots R Us #3266]
2015: Georgia Southern Classic (Winners / Thanks 1319 & 1648!), Queen City
2014: Crossroads, Queen City
2013: Buckeye, Queen City, Crossroads
2012: Buckeye, Queen City

2011: Buckeye
2010: Buckeye
Reply With Quote
  #3   Spotlight this post!  
Unread 11-02-2011, 13:49
professorX professorX is offline
Registered User
AKA: Xavier
FRC #1660 (The Harlem Knights)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2005
Location: New York
Posts: 62
professorX is an unknown quantity at this point
Re: Issue with autonomous mode and some newbie questions

Quote:
Originally Posted by Robby Unruh View Post
Your problem lies here:
Code:
for(int i =0; i < 10; i=+1){
    getWatchdog().feed();
    robotdrive.drive(1,0);
    Timer.delay(3);
    getWatchdog().feed();
}
You're using a timer delay in a loop. That means that everytime the loop is called (which is two, for whatever reason) you will have a 3 second delay. Plus, since you're wanting to drive for a set amount of time in autonomous, why not use the nifty Timer class?

Code:
Timer timer = new Timer(); // you should put this in your constructor.

public void autonomous() {
    while(isAutonomous()) {
        timer.start();
        while(timer.get() < 3) { // while the timer is < 3, drive forward.
            robotDrive.drive(1,0);
            timer.stop(); // stop the timer after 3 seconds
        }
        robotDrive.drive(0,0); // stop the robot from driving any further.
    }
}
I thought the timer delay pauses the code. Since the motors weren't told to stop before the timer delay so it should continue straight for 3 seconds. And it should do it 10 times according the for loop.
I think the issue is that the watchdog is not being fed during the pause so the robot shuts down. Could this be the issue and how could it be fixed?
Reply With Quote
  #4   Spotlight this post!  
Unread 11-02-2011, 14:18
mwtidd's Avatar
mwtidd mwtidd is offline
Registered User
AKA: mike
FRC #0319 (Big Bad Bob)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 2003
Location: Boston, MA
Posts: 714
mwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond repute
Re: Issue with autonomous mode and some newbie questions

email me at mwtidd@gmail.com

I converted your code to my ADK which does most the work for you.

Lets you focus on the important stuff.
__________________
"Never let your schooling interfere with your education" -Mark Twain
Reply With Quote
  #5   Spotlight this post!  
Unread 11-02-2011, 14:34
Robby Unruh's Avatar
Robby Unruh Robby Unruh is offline
*insert random dial-up tone here*
FRC #3266 (Robots R Us)
Team Role: Coach
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Eaton, OH
Posts: 338
Robby Unruh will become famous soon enough
Re: Issue with autonomous mode and some newbie questions

Quote:
Originally Posted by professorX View Post
I thought the timer delay pauses the code. Since the motors weren't told to stop before the timer delay so it should continue straight for 3 seconds. And it should do it 10 times according the for loop.
I think the issue is that the watchdog is not being fed during the pause so the robot shuts down. Could this be the issue and how could it be fixed?
In autonomous, watchdog must be set to false.

Code:
Watchdog.getInstance().setEnabled(false);
Might be your problem.
__________________
[Robots R Us #3266]
2015: Georgia Southern Classic (Winners / Thanks 1319 & 1648!), Queen City
2014: Crossroads, Queen City
2013: Buckeye, Queen City, Crossroads
2012: Buckeye, Queen City

2011: Buckeye
2010: Buckeye
Reply With Quote
  #6   Spotlight this post!  
Unread 12-02-2011, 21:12
professorX professorX is offline
Registered User
AKA: Xavier
FRC #1660 (The Harlem Knights)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2005
Location: New York
Posts: 62
professorX is an unknown quantity at this point
Re: Issue with autonomous mode and some newbie questions

Thanks for the help. I will let you know how it goes when I test out the code on Monday.

Can someone answer questions 3 & 4 in the first post?
3. How do you save as project (not .java file) on a usb drive or on a different location from where it was originally saved?
4. How can I debug the code using System.out.println? It never prints out anything. Are there other ways for debugging the code or knowing what values you get from sensors?

Last edited by professorX : 12-02-2011 at 23:30.
Reply With Quote
  #7   Spotlight this post!  
Unread 13-02-2011, 01:53
lusterlink's Avatar
lusterlink lusterlink is offline
Registered User
FRC #1160 (FireBird Robotics)
Team Role: Programmer
 
Join Date: Aug 2010
Rookie Year: 2009
Location: USA
Posts: 9
lusterlink is an unknown quantity at this point
Re: Issue with autonomous mode and some newbie questions

Quote:
Originally Posted by professorX View Post
Thanks for the help. I will let you know how it goes when I test out the code on Monday.

Can someone answer questions 3 & 4 in the first post?
3. How do you save as project (not .java file) on a usb drive or on a different location from where it was originally saved?
4. How can I debug the code using System.out.println? It never prints out anything. Are there other ways for debugging the code or knowing what values you get from sensors?
I believe one way to achieve saving a project in an alternative location is to simply go to the project directory. Copy the project in question and paste it into the usb drive. There might be more elegant methods built into Netbeans, but I haven't found them.

The System.out.println function output should show right up in the Netconsole. Are you getting any output in the Netconsole (e.g. the cRIO spitting out all its boot up stuff)?
__________________
Reply With Quote
  #8   Spotlight this post!  
Unread 13-02-2011, 21:12
drakesword drakesword is offline
Registered User
AKA: Bryant
FRC #0346 (Robohawks)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: USA
Posts: 200
drakesword is on a distinguished road
Re: Issue with autonomous mode and some newbie questions

Quote:
Originally Posted by professorX View Post
Thanks for the help. I will let you know how it goes when I test out the code on Monday.

Can someone answer questions 3 & 4 in the first post?
3. How do you save as project (not .java file) on a usb drive or on a different location from where it was originally saved?
4. How can I debug the code using System.out.println? It never prints out anything. Are there other ways for debugging the code or knowing what values you get from sensors?
3.) As stated above copy the project folder.

4.) println will print to the netconsole (eg the output section of netbeans while it is running). If you don't see output you may need to check your subnet mask. If it is not 255.0.0.0 then you will not see output from the robot.

I also agree that it appears that you are tripping the watchdog. You set the watchdog to get hungry every 0.5 seconds but only feed it every 3.
Reply With Quote
  #9   Spotlight this post!  
Unread 13-02-2011, 22:17
Robby Unruh's Avatar
Robby Unruh Robby Unruh is offline
*insert random dial-up tone here*
FRC #3266 (Robots R Us)
Team Role: Coach
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Eaton, OH
Posts: 338
Robby Unruh will become famous soon enough
Re: Issue with autonomous mode and some newbie questions

4) I use to stop my builds before switching over to the driver station. I actually only (very) recently discovered that I can keep it running to debug my code!

So to answer your question, let's say I have a teleop function like so:

Code:
public void operatorControl() {
    while(isOperatorControl()) {
        System.out.println("This code will show up a million times when I enable Teleop from the driver station!");
    }
}
I was shocked that it actually worked. haha
__________________
[Robots R Us #3266]
2015: Georgia Southern Classic (Winners / Thanks 1319 & 1648!), Queen City
2014: Crossroads, Queen City
2013: Buckeye, Queen City, Crossroads
2012: Buckeye, Queen City

2011: Buckeye
2010: Buckeye
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 00:39.

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