Go to Post A thread already exists (and boy, does it exist!) on the topic: - Billfred [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: 639
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
  #12   Spotlight this post!  
Unread 29-03-2011, 19:19
JosephC's Avatar
JosephC JosephC is offline
FF: Breakfast Company
AKA: Joseph Cupchack
no team (FiM Volunteer Extraordinaire)
 
Join Date: Sep 2010
Rookie Year: 2011
Location: Waterford, Michigan
Posts: 1,752
JosephC has a reputation beyond reputeJosephC has a reputation beyond reputeJosephC has a reputation beyond reputeJosephC has a reputation beyond reputeJosephC has a reputation beyond reputeJosephC has a reputation beyond reputeJosephC has a reputation beyond reputeJosephC has a reputation beyond reputeJosephC has a reputation beyond reputeJosephC has a reputation beyond reputeJosephC has a reputation beyond repute
Re: Last minute autonomous help

At the Waterford District we used encoders, drove a set amount of cycles forward, and then had our arm code place our tube, except it only worked 50% of the time because our field people liked to not line it up straight so it went off to the side quite a bit.

At Ann Arbor we used line trackers to keep our robot straight while using encoders to set our distance. But our field people would have it too far forward or back so it still wasn't reliable.

At Troy we're looking forward to trying to use a camera positioned on our arm to locate the top peg and score, with little or no use for the encoders or line trackers.

As for only using 2 line trackers I wouldn't recommend it. Last year we tried that and sent half of a competition trying to borrow one after 5 unsuccessful matches.
__________________
Referee: 2015 - ?
Field Reset/Supervisor: 2013 - ?
68 Team Member: 2011 - 2013
Reply With Quote
  #13   Spotlight this post!  
Unread 29-03-2011, 20:16
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: Last minute autonomous help

Did any other team not use encoders/ultrasonic for their autonomous?

My team only had line sensors, we're counting on timers to do the rest of the work for us (arm).

And if so, how well did the timers work out for your team? Do you think we would have enough time to implement encoders on our robot in the pits?
__________________
[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
  #14   Spotlight this post!  
Unread 30-03-2011, 19:20
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 Robby Unruh View Post
Did any other team not use encoders/ultrasonic for their autonomous?

My team only had line sensors, we're counting on timers to do the rest of the work for us (arm).

And if so, how well did the timers work out for your team? Do you think we would have enough time to implement encoders on our robot in the pits?
In the past we've run autonomous without encoders, the biggest problem we had was that performance (especially for turning) varied on battery charge, so that if we didn't regularly switch out the batteries we'd have issues. As long as your conscious of batteries and keep them charged, there shouldn't be any issues, as long as it worked consistently during testing.

How long would it take to implement encoders? Assuming you plan for it, it should be quick and doable with one or two runs to the practice field.
BEFORE YOU GET THERE
1. If you ave the encoders at your shop and can solder the wires so that you can plug it straight into jags or digital sidecar
2. Figure out where you're mounting the encoders (cimple boxes?) and the gear ratio to the wheels
3. Figure out the diameter of the wheel and the gear ratio between the
4. Using the diameter of the wheel and gear ratio to calculate how many feet you go in one rotation of the encoder
5. Write code using the above equation and P(and possibly ID) to get to your target position (I think starting location is ~19 feet from the driver station)
6. Double check your code.
WHEN YOU GET THERE
1. Attach encoders to robot
2. Wire encoders
3. With robot on blocks check that autonomous behave sanely (have somebody on the Estop)
4. Test on practice field (have somebody on the Estop)
5. Assuming that the behavior was close enough to sane..
6. Continue testing on practice field and matches until it's consistently scoring.
(Similar applies to arm.... might need more math though)

Hopefully that helps, the great thing about sensors is that you can write alot of code ahead of time. Good luck if you go through with using encoders.
Reply With Quote
  #15   Spotlight this post!  
Unread 30-03-2011, 23:08
Dacilndak's Avatar
Dacilndak Dacilndak is offline
Matt'); DROP TABLE Users; --
AKA: Matthew Haney
FRC #3729 (Red Knights)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Denver, Colorado
Posts: 12
Dacilndak is an unknown quantity at this point
Re: Last minute autonomous help

Quote:
Originally Posted by Robby Unruh View Post
Did any other team not use encoders/ultrasonic for their autonomous?

My team only had line sensors, we're counting on timers to do the rest of the work for us (arm).

And if so, how well did the timers work out for your team? Do you think we would have enough time to implement encoders on our robot in the pits?
Our team is using 3 front-mounted light sensors with great success. No encoders, no ultrasonic, no timers.

We're using C++. Our autonomous program manages a state machine that gets input from the light sensors and decides what to do based on them. Our algorithm is as follows:

Light sensor values (L/C/R)-----------------------State to execute
000--------------------------------------------------move() - go forward until you see the line
010--------------------------------------------------move() - this is ideal, we're on the line
100--------------------------------------------------correctLeft() - move left to see the line
110--------------------------------------------------also correctLeft()
001 and 011----------------------------------------correctRight()
101--------------------------------------------------at the fork; correctLeft() or correctRight() based on a switch on the robot
111-------------------------------------------------placeTube()

After executing placeTube(), the program quits the state machine and retreats back several feet, then turns on the spot (~180 degrees, but it's not perfect since we don't have encoders or a gyro). Generally, getting the tube on the rack takes about ten seconds, and we're only driving the motors at 40% for drive and 60% for turn.
__________________
Team 3729 - Raiders - Programming Team Co-Captain
2011 Colorado Regional Semifinalist
2011 Colorado Regional Rookie All-Star Award
2011 Colorado Regional Highest Rookie Seed Award
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 13:16.

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