Go to Post You have to start at the bottom to get to the top, usually. - Kyle [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 21-02-2011, 19:57
IRunOnJava IRunOnJava is offline
Registered User
FRC #2265 (Fe Maidens)
Team Role: Electrical
 
Join Date: Mar 2010
Rookie Year: 2009
Location: NY
Posts: 1
IRunOnJava is an unknown quantity at this point
Unhappy Last minute autonomous help

My team is scrambling to create a working autonomous.

Our code, so far, is a modified version of the Java sample line tracker. We had to change our code to work off of two sensors because, unfortunately, one of our three line sensors came broken.
We understand that all the sample code does is move the robot forward for 8 seconds, but even with this sample code loaded on the robot, our robot does zilch. We're just trying to get our robot to show some sign of life while put in autonomous mode.
Can anybody help us out? All suggestions are appreciated.

Here's what we have loaded, autonomous-wise:

Code:
    public void autonomous() {

        getWatchdog().setEnabled(false);
        getWatchdog().feed();
        //Timer.reset();  //Resets the timer
        //Timer.start();  //Starts the timer
        int binaryValue; 
        int previousValue = 0; // the binary value from the previous loop
        double steeringGain; // the amount of steering correction to apply

        // the power profiles for the straight and forked robot path. They are
        // different to let the robot drive more slowly as the robot approaches
        // the fork on the forked line case.
        double forkProfile[] = {0.70, 0.70, 0.55, 0.60, 0.60, 0.50, 0.40, 0.00};
        double straightProfile[] = {0.7, 0.7, 0.6, 0.6, 0.35, 0.35, 0.35, 0.0};
        double powerProfile[];   // the selected power profile

        // set the straightLine and left-right variables depending on chosen path
        boolean straightLine = ds.getDigitalIn(1);
        powerProfile = (straightLine) ? straightProfile : forkProfile;
        double stopTime = (straightLine) ? 2.0 : 4.0; // when the robot should look for end
        boolean goLeft = !ds.getDigitalIn(2) && !straightLine;
        System.out.println("StraightLine: " + straightLine);
        System.out.println("GoingLeft: " + goLeft);


        boolean atCross = false; // if robot has arrived at end


        // time the path over the line
        Timer timer = new Timer();
        timer.start();
        timer.reset();

        int oldTimeInSeconds = -1;
        double time;
        double speed, turn;

        // loop until robot reaches "T" at end or 8 seconds has past
        while ((time = timer.get()) < 8.0 && !atCross) {
            int timeInSeconds = (int) time;
            // read the sensors
            int leftValue = left.get() ? 1 : 0;
            //int middleValue = middle.get() ? 1 : 0;
            int rightValue = right.get() ? 1 : 0;
            // compute the single value from the 3 sensors. Notice that the bits
            // for the outside sensors are flipped depending on left or right
            // fork. Also the sign of the steering direction is different for left/right.
            if (goLeft) {
                binaryValue = leftValue * 4 + rightValue;
                steeringGain = -defaultSteeringGain;
            } else {
                binaryValue = rightValue * 4 + leftValue;
                steeringGain = defaultSteeringGain;
            }

            // get the default speed and turn rate at this time
            speed = powerProfile[timeInSeconds];
            turn = 0;

            // different cases for different line tracking sensor readings
            switch (binaryValue) {
                case 1:  // on line edge
                    turn = 0;
                    break;
                case 5:  // all sensors on (maybe at cross)
                    if (time > stopTime) {
                        atCross = true;
                        speed = 0;
                    }
                    break;
                case 0:  // all sensors off
                    if (previousValue == 0 || previousValue == 1) {
                        turn = steeringGain;
                    } else {
                        turn = -steeringGain;
                    }
                    break;
                default:  // all other cases
                    turn = -steeringGain;
            }
            // print current status for debugging
            if (binaryValue != previousValue) {
                System.out.println("Time: " + time + " Sensor: " + binaryValue + " speed: " + speed + " turn: " + turn + " atCross: " + atCross);
            }

            // set the robot speed and direction
            robotDrive.arcadeDrive(speed, turn);

            if (binaryValue != 0) {
                previousValue = binaryValue;
            }
            oldTimeInSeconds = timeInSeconds;

            Timer.delay(0.01);
        }
        // Done with loop - stop the robot. Robot ought to be at the end of the line
        robotDrive.drive(0,0);
    }
Reply With Quote
  #2   Spotlight this post!  
Unread 21-02-2011, 20:06
davidthefat davidthefat is offline
Alumni
AKA: David Yoon
FRC #0589 (Falkons)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: California
Posts: 792
davidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud of
Re: Last minute autonomous help

You say two? Good luck with that, it can be done, but you will require either gyros or encoders. Keep a record of the speeds, or the angle it has veered off to. Mount a line tracker in the front, and the other one in the back so it always is triggered. Do some calculations. I too have to work on the autonomy. I will be writing my own from scratch.
__________________
Do not say what can or cannot be done, but, instead, say what must be done for the task at hand must be accomplished.
Reply With Quote
  #3   Spotlight this post!  
Unread 21-02-2011, 21:33
alexhenning alexhenning is offline
WPILib Developer
FRC #0348
 
Join Date: Apr 2010
Rookie Year: 2003
Location: MA
Posts: 49
alexhenning will become famous soon enough
Re: Last minute autonomous help

We don't use line tracking, we use encoders we drive a fixed distance straight and place a piece.

Since you're running so late. try code that powers your drive forward at say 1/3 power for 5 seconds. Tune it until it just bumps the wall and then place a piece. Make sure you keep a good battery, but I think that's your best bet for a last minute autonomous BEFORE you ship.

Alternatively, look up teams going to your first regional and see if there's anyone like my team who hasn't used there line sensors and wouldn't mind giving you one.
Reply With Quote
  #4   Spotlight this post!  
Unread 21-02-2011, 21:58
Patrickwhite's Avatar
Patrickwhite Patrickwhite is offline
May the North be with you
FRC #0610 (The Coyotes)
Team Role: Programmer
 
Join Date: Dec 2008
Rookie Year: 2008
Location: Toronto
Posts: 88
Patrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of light
Re: Last minute autonomous help

Are you getting any response when you deploy? If the robot does nothing, the robot is probably quitting unexpectedly, which you would receive. As for working with two photosensors, if you are dead set on using them (instead of other sensors or dead reckoning as has been suggested) I would place them directly adjacent to each other, so they can both be tripped by the tape at the same time and working with that. There may be some interference however (one receiving the reflected light from the other and returning a false positive) and it obviously won't be ideal.
__________________
while(!going.isTough());
tough.exit();

What will we do tonight, Warfa?
The same thing we do every night, Patrick. Sit and wait for Electrical.
Reply With Quote
  #5   Spotlight this post!  
Unread 26-02-2011, 03:06
AlexD744 AlexD744 is offline
Registered User
FRC #0744 (744 Shark Attack)
Team Role: Alumni
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Ft. Lauderdale, FL
Posts: 638
AlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond repute
Re: Last minute autonomous help

Personally I find the encoders a more reliable way of making an autonomous algorithm. You simply drive until you hit a certain number of encoder counts. Then you move your manipulator. Then you drive some more. Then you place. Then you reverse.
If you're using the Iterative Robot template, the easiest way to do this is do create different state machines for the drive and each of your mechanisms. Then you create a main state machine that simply feeds these other machines values and waits for the drive or manipulator to be in place. Once the structure was created, fine tuning the numbers only took a few hours, and now we can place on any of the high pegs and the middle second level pegs reliably (as long as we're using a fresh battery that is).
__________________
www.sharkattack744.com
Reply With Quote
  #6   Spotlight this post!  
Unread 26-02-2011, 12:41
davidthefat davidthefat is offline
Alumni
AKA: David Yoon
FRC #0589 (Falkons)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: California
Posts: 792
davidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud of
Re: Last minute autonomous help

Quote:
Originally Posted by AlexD744 View Post
Personally I find the encoders a more reliable way of making an autonomous algorithm. You simply drive until you hit a certain number of encoder counts. Then you move your manipulator. Then you drive some more. Then you place. Then you reverse.
If you're using the Iterative Robot template, the easiest way to do this is do create different state machines for the drive and each of your mechanisms. Then you create a main state machine that simply feeds these other machines values and waits for the drive or manipulator to be in place. Once the structure was created, fine tuning the numbers only took a few hours, and now we can place on any of the high pegs and the middle second level pegs reliably (as long as we're using a fresh battery that is).
I personally would disagree with you on that: because our robot is driven by chain, there are a lot of noise in the encoders from the chain jerking around. I suggest one day just put the robot on blocks and let the motor run through from 0 to 255 PWM and graph the encoder data vs the PWM. You will be surprised at the noise.
__________________
Do not say what can or cannot be done, but, instead, say what must be done for the task at hand must be accomplished.
Reply With Quote
  #7   Spotlight this post!  
Unread 26-02-2011, 12:52
alexhenning alexhenning is offline
WPILib Developer
FRC #0348
 
Join Date: Apr 2010
Rookie Year: 2003
Location: MA
Posts: 49
alexhenning will become famous soon enough
Re: Last minute autonomous help

Quote:
Originally Posted by davidthefat View Post
I personally would disagree with you on that: because our robot is driven by chain, there are a lot of noise in the encoders from the chain jerking around. I suggest one day just put the robot on blocks and let the motor run through from 0 to 255 PWM and graph the encoder data vs the PWM. You will be surprised at the noise.
My team used encoders and we have a reliable autonomous even though our robot has chain. The noise is minimal, I haven't graphed it, but after ~30 successful runs, I wouldn't worry about it unless your chain is really lose or otherwise acting up.

The other thing about encoders is that with some math, you can convert it to feet. You know how far back you start, so drive N feet forward and then place the piece. All the fiddling is with the arm then.
Reply With Quote
  #8   Spotlight this post!  
Unread 28-03-2011, 00:58
PriyankP's Avatar
PriyankP PriyankP is offline
Registered User
FRC #0188 (Woburn Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Toronto, Canada
Posts: 87
PriyankP has much to be proud ofPriyankP has much to be proud ofPriyankP has much to be proud ofPriyankP has much to be proud ofPriyankP has much to be proud ofPriyankP has much to be proud ofPriyankP has much to be proud ofPriyankP has much to be proud ofPriyankP has much to be proud of
Re: Last minute autonomous help

Quote:
Originally Posted by alexhenning View Post
My team used encoders and we have a reliable autonomous even though our robot has chain. The noise is minimal, I haven't graphed it, but after ~30 successful runs, I wouldn't worry about it unless your chain is really lose or otherwise acting up.

The other thing about encoders is that with some math, you can convert it to feet. You know how far back you start, so drive N feet forward and then place the piece. All the fiddling is with the arm then.
Sorry to bring up this relatively old topic but I was wondering how are you using encoders to go to a certain distance? Do you just have PID and Setpoint encoders to some number? Or are you using something else too?

Any other teams out there willing to share how they use their encoders in autonomous?
__________________
Champs Schedule Highlighter App [CD Thread]

#### XYZ Regional Finalists
Reply With Quote
  #9   Spotlight this post!  
Unread 28-03-2011, 17:50
alexhenning alexhenning is offline
WPILib Developer
FRC #0348
 
Join Date: Apr 2010
Rookie Year: 2003
Location: MA
Posts: 49
alexhenning will become famous soon enough
Re: Last minute autonomous help

Quote:
Originally Posted by PriyankP View Post
Sorry to bring up this relatively old topic but I was wondering how are you using encoders to go to a certain distance? Do you just have PID and Setpoint encoders to some number? Or are you using something else too?

Any other teams out there willing to share how they use their encoders in autonomous?
I have two encoders hooked up to jaguars running CAN one for the left side and the other for the right side. The autonomous does P (No need for ID) so that it slows down as it gets closer until it hits the wall going pretty slowly. This runs reliably as long as it's lined up and the left and right sides act the same. i.e. You jam both joysticks forward and it actually drives straight-ish.

Here's the relevant code.
Code:
	    leftDist = bot.dt.getLeftDist() - leftStart;
	    rightDist = bot.dt.getRightDist() - rightStart;
	    
	    double left = gain * ((distance - leftDist) / distance);
	    double right = gain * ((distance - rightDist) / distance);
	    
	    bot.dt.drive(left, right, bot.gyro);
distance is the distance you wish to travel in feet.
gain is the initial value that gets toned down as you drive (Currently using 0.7)

Hopefully the rest of the code is clear enough that it makes sense. If you have anymore questions feel free to ask. Also, you can PM me if you want to see our full autonomous code.
Reply With Quote
  #10   Spotlight this post!  
Unread 28-03-2011, 21:31
PriyankP's Avatar
PriyankP PriyankP is offline
Registered User
FRC #0188 (Woburn Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Toronto, Canada
Posts: 87
PriyankP has much to be proud ofPriyankP has much to be proud ofPriyankP has much to be proud ofPriyankP has much to be proud ofPriyankP has much to be proud ofPriyankP has much to be proud ofPriyankP has much to be proud ofPriyankP has much to be proud ofPriyankP has much to be proud of
Re: Last minute autonomous help

Quote:
Originally Posted by alexhenning View Post
I have two encoders hooked up to jaguars running CAN one for the left side and the other for the right side. The autonomous does P (No need for ID) so that it slows down as it gets closer until it hits the wall going pretty slowly. This runs reliably as long as it's lined up and the left and right sides act the same. i.e. You jam both joysticks forward and it actually drives straight-ish.
I was thinking of putting on two encoders to get the base to stop within 6 inches of the target distance without overshooting and without travelling slowly. Not sure if that's possible yet because we don't have encoders on the base yet but I would imagine I'll need I and D. The biggest problem that I'll have is momentum because I plan on running the auto at close to full speed.

If you don't mind, can you please send me the code that has to do with your base? I'm sure I can learn from it as I can't find many resources that explain the concepts. :O
__________________
Champs Schedule Highlighter App [CD Thread]

#### XYZ Regional Finalists
Reply With Quote
  #11   Spotlight this post!  
Unread 28-03-2011, 21:50
alexhenning alexhenning is offline
WPILib Developer
FRC #0348
 
Join Date: Apr 2010
Rookie Year: 2003
Location: MA
Posts: 49
alexhenning will become famous soon enough
Re: Last minute autonomous help

Quote:
Originally Posted by PriyankP View Post
I was thinking of putting on two encoders to get the base to stop within 6 inches of the target distance without overshooting and without travelling slowly. Not sure if that's possible yet because we don't have encoders on the base yet but I would imagine I'll need I and D. The biggest problem that I'll have is momentum because I plan on running the auto at close to full speed.

If you don't mind, can you please send me the code that has to do with your base? I'm sure I can learn from it as I can't find many resources that explain the concepts. :O
Chiefdelphi has a number of helpful post on PID, for starters: http://www.chiefdelphi.com/media/papers/1823

Is there any reason you can't overshoot? Fast speed to wall, then slowly backing up 6 inches may be better, unless it smashes your arm or something. Don't forget, you have 15 seconds, consistent even if slow is better than inconsistent and fast.

Hope that helps a bit.
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 11:14.

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