Go to Post Winning a competition is great, but seeing kids who never thought they had a chance before suddenly discover a brand new future would be the most amazing experience. - MissInformation [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 23-03-2016, 17:23
SPQLrobotics SPQLrobotics is offline
Registered User
FRC #5941
 
Join Date: Oct 2015
Location: Everett
Posts: 4
SPQLrobotics is an unknown quantity at this point
Need Help With Encoders

Our team, 5941, has struggled to get autonomous working. This is our code for autonomous:

public void autonomousInit() {
autoState = -1;
t.start();
lastTime = t.get();
}

/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {
switch (autoSelected) {
case "doNothing":
break;
default:
case defaultAuto:
LowBarAuton();
//encoderAuto();
break;
// case "spybot":
// SpyBotAuton();
// break;
// case "rampWithStuff":
// RampAuton();
// break;
}
}

public void LowBarAuton() {
switch (autoState){
default:
lastTime = t.get();
autoState = 0;
end1.set(0.5);
end2.set(0.5);
break;
case 0:
pneumatic.set(-0.75);
if ( t.get() - lastTime > 2){
autoState = 1;
lastTime = t.get();
}
break;
case 1:
pneumatic.set(0.0);
leftSide.set(0.4);
rightSide.set(-0.4);
if ( t.get() - lastTime > 5){
autoState = 2;
lastTime = t.get();
}
break;

case 2:

rightSide.set(0.0);
leftSide.set(0.0);
autoSelected = "doNothing";
break;
}

}

public void encoderAuto(){
pneumatic.set(-0.75);
Timer.delay(2.0);
pneumatic.set(0.0);
if (encLeft.getDistance() < 4 && encRight.getDistance() > -4 && !forwardDone){
leftSide.set(0.4);
rightSide.set(-0.4);
} else if (encLeft.getDistance() >= 4 && encRight.getDistance() <= -4 && !forwardDone) {
forwardDone = true;
leftSide.set(0.0);
rightSide.set(0.0);
encLeft.reset();
encRight.reset();
Timer.delay(1.0);
}else if (encLeft.getDistance() > -4 && encRight.getDistance() < 4 && !backwardDone && forwardDone) {
leftSide.set(-0.4);
rightSide.set(0.4);
}else if (encLeft.getDistance() <= -4 && encRight.getDistance() >= 4 && !backwardDone && forwardDone) {
backwardDone = true;
leftSide.set(0);
rightSide.set(0);
autoSelected = "doNothing";
}
}

The LowBarAuton() is supposed to drive under the low bar, then back up to the other side so that as soon as teleop starts we can clear that defense. It is using timers.

encoderAuto() is attempting to do the same thing as LowBarAuton(), only using encoders instead of timers. Neither have worked.


I also am attaching the full code, in the event that this code is not enough. Help would be appreciated.
Attached Files
File Type: java Robot.java (10.8 KB, 18 views)
Reply With Quote
  #2   Spotlight this post!  
Unread 24-03-2016, 21:50
Sasha_Nut's Avatar
Sasha_Nut Sasha_Nut is offline
Registered User
AKA: Emilija Kaupaite
FRC #4103 (Roborioles)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Avon, IN
Posts: 15
Sasha_Nut is an unknown quantity at this point
Re: Need Help With Encoders

I only work in C++, but I can attempt to help.
You say that the autonomouses are not working. Are they not activating, or are they doing something but not what you want them to do? (For any of them.)
Reply With Quote
  #3   Spotlight this post!  
Unread 24-03-2016, 22:12
JohnFogarty's Avatar
JohnFogarty JohnFogarty is offline
FTC, I have returned.
AKA: @doctorfogarty @GarnetSq
FTC #11444 (FTC# 11444 (Garnet Squadron)
Team Role: Mentor
 
Join Date: Aug 2009
Rookie Year: 2006
Location: SC
Posts: 1,554
JohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond repute
Re: Need Help With Encoders

First off you need to read the documentation on Switches in Java and then take a look at your code.

https://docs.oracle.com/javase/tutor...ts/switch.html

Now, on to the first code segment where I see issues.

Code:
public void autonomousPeriodic() {

switch (autoSelected) {

case "doNothing":
break;

default:

case defaultAuto:
LowBarAuton();
//encoderAuto();
break;

// case "spybot":
// SpyBotAuton();
// break;
// case "rampWithStuff":
// RampAuton();
// break;

}
}
Your default case needs to be at the end of the switch statement I believe, and you need a "break;" after the "default:".

You do that correctly in your LowBarAuton() method. Your programmer has assumed that the case "defaultAuto" was set to the default case and I do not believe it has been.
__________________
John Fogarty
2010 FTC World Championship Winner & 2013-2014 FRC Orlando Regional Winner
"Head Bot Coach" FRC Team 4901 Garnet Squadron

Former Student & Mentor FLL 1102, FTC 1102 & FTC 3864, FRC 1102, FRC 1772, FRC 5632
2013 FTC World Championship Guest Speaker
Reply With Quote
  #4   Spotlight this post!  
Unread 24-03-2016, 22:28
remulasce remulasce is offline
Registered User
no team
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Mtn View
Posts: 136
remulasce is a splendid one to beholdremulasce is a splendid one to beholdremulasce is a splendid one to beholdremulasce is a splendid one to beholdremulasce is a splendid one to beholdremulasce is a splendid one to beholdremulasce is a splendid one to behold
Re: Need Help With Encoders

Please give us more information about what happens when you try to run your autonomous. Specifically:

Does the code compile?
Does the code deploy & appear to run on the robot?
Does the robot move at all when you try autonomous?
How much of what you expect to happen happens when you run auto?
Can you run other, simpler autonomous modes correctly? (eg. just move fwd 3 seconds)

This will greatly help us as we try to help you.
__________________
Student 294: 2007-2011
Mentor 597: 2013-2015
Google SWE: 2015-
Reply With Quote
  #5   Spotlight this post!  
Unread 24-03-2016, 22:28
Sasha_Nut's Avatar
Sasha_Nut Sasha_Nut is offline
Registered User
AKA: Emilija Kaupaite
FRC #4103 (Roborioles)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Avon, IN
Posts: 15
Sasha_Nut is an unknown quantity at this point
Re: Need Help With Encoders

Going along with what JohnFogarty was saying, in your LowBarAuton, the default has to be at the end of the switch.
Reply With Quote
  #6   Spotlight this post!  
Unread 24-03-2016, 22:41
remulasce remulasce is offline
Registered User
no team
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Mtn View
Posts: 136
remulasce is a splendid one to beholdremulasce is a splendid one to beholdremulasce is a splendid one to beholdremulasce is a splendid one to beholdremulasce is a splendid one to beholdremulasce is a splendid one to beholdremulasce is a splendid one to behold
Re: Need Help With Encoders

So after a brief review, I can tell you the code looks really messy.

But, nothing actually appears incorrect in the autonomous sequence. Which is why we need the reason why you think it's wrong.

It's perfectly valid in Java to put default: before the case:es. You're doing it really messily in LowBarAuton, but it does work.

Again. Please tell us exactly how you are trying to run autonomous and how it "fails". We can't help you solve something you haven't told us about.
__________________
Student 294: 2007-2011
Mentor 597: 2013-2015
Google SWE: 2015-
Reply With Quote
  #7   Spotlight this post!  
Unread 26-03-2016, 15:16
SPQLrobotics SPQLrobotics is offline
Registered User
FRC #5941
 
Join Date: Oct 2015
Location: Everett
Posts: 4
SPQLrobotics is an unknown quantity at this point
Re: Need Help With Encoders

To answer all questions at once, the code compiles and runs, the arm will lower (the motor called pneumatic lowers our pneumatic arm, as it has to start at an angle to be within the bumpers). The robot will then not move at all. We are attempting to have it move forward through the low bar and back, which is about 4 wheel rotations for the encoders - the time was an estimate and just a test for movement. We are going to move the default to the end of the code. The only time we actually got movement was using a while loop with encoders, but the robot continuously drove forward and the loop delayed driver control in teleop.
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 09:31.

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