Go to Post Coming up next on Pimp My Ride.....Yo man, here is the real deal. A two-oh-oh-six Segway I-one-eighty, with stock rims, stock fenders, and two 3 horse motors that red-line at twelve point five miles per hour. Get ready, because I'm going pimp this ride! - artdutra04 [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
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 07-02-2016, 14:42
alexusaywla alexusaywla is offline
Registered User
AKA: Alexus
FRC #6155 (ElektraBots)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2016
Location: San Antonio, TX
Posts: 13
alexusaywla is an unknown quantity at this point
Autonomous

I have some code written for autonomous but when I deploy the code nothing happens. Why is this? Can someone please tell me what I need to include or provide an example?

void RobotInit()
{
SmartDashboard:utNumber("auton", 0);
}


void Autonomous()
{
autonomous = SmartDashboard::GetNumber("auton", 0);

if(autonomous == 1)
{
cout << "ONE!";
Robot.SetSafetyEnabled(false);
Robot.Drive(0.5, 0);
Wait(2);
Robot.Drive(0, 0);

}
else if(autonomous == 2)
{
cout << "TWO!";
}
else{cout << "NONE!";}
}


void OperatorControl()
{
Reply With Quote
  #2   Spotlight this post!  
Unread 15-02-2016, 01:51
cantdecide cantdecide is offline
Registered User
FRC #5773 (YAFL Mechatronics)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2016
Location: Turkey
Posts: 31
cantdecide is an unknown quantity at this point
Re: Autonomous

Are you changing the "auton" parameter from SmartDashboard? You need to tab away from the input box after changing its value for the changes to come through. Try putting a SmartDashboard::PutNumber right after the GetNumber in Autonomous() with a different name in order to make sure that you're reading the number correctly. Also, I'd suggest not using cout since I'm not sure if you can view console output without Riolog. Try using another SmartDashboard variable for that.

On other small flaws I can see, I suggest using a while loop that runs while the robot is autonomous and enabled around drive code instead of blindly waiting. I'm not sure if just waiting would cause any issues with the code you have right now but if your method gets more complex and requires cleanup after it's complete, you're probably going to need to switch to IterativeRobot or have a while loop. And I'm also not sure why you added a SetSafetyEnabled(false).
Reply With Quote
  #3   Spotlight this post!  
Unread 15-02-2016, 07:38
rich2202 rich2202 is offline
Registered User
FRC #2202 (BEAST Robotics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Wisconsin
Posts: 1,171
rich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond repute
Re: Autonomous

Two possible problems:

1) Isn't it "AutonomousPeriodic()" and not "Autonomous()"
2) "wait (2)" might give you heartbeat problems. If your periodic code hangs for 2 seconds, FMS might think you have crashed and disable your robot. It is better to set a timer and check the timer each time AutonomousPeriodic is called.
Reply With Quote
  #4   Spotlight this post!  
Unread 15-02-2016, 12:00
cantdecide cantdecide is offline
Registered User
FRC #5773 (YAFL Mechatronics)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2016
Location: Turkey
Posts: 31
cantdecide is an unknown quantity at this point
Re: Autonomous

Quote:
Originally Posted by rich2202 View Post
1) Isn't it "AutonomousPeriodic()" and not "Autonomous()"
I believe that OP is using SampleRobot, hence OperatorControl() and not OperatorPeriodic().
Reply With Quote
  #5   Spotlight this post!  
Unread 15-02-2016, 22:53
alexusaywla alexusaywla is offline
Registered User
AKA: Alexus
FRC #6155 (ElektraBots)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2016
Location: San Antonio, TX
Posts: 13
alexusaywla is an unknown quantity at this point
Smile Re: Autonomous

Quote:
Originally Posted by cantdecide View Post
Are you changing the "auton" parameter from SmartDashboard? You need to tab away from the input box after changing its value for the changes to come through. Try putting a SmartDashboard:utNumber right after the GetNumber in Autonomous() with a different name in order to make sure that you're reading the number correctly. Also, I'd suggest not using cout since I'm not sure if you can view console output without Riolog. Try using another SmartDashboard variable for that.

On other small flaws I can see, I suggest using a while loop that runs while the robot is autonomous and enabled around drive code instead of blindly waiting. I'm not sure if just waiting would cause any issues with the code you have right now but if your method gets more complex and requires cleanup after it's complete, you're probably going to need to switch to IterativeRobot or have a while loop. And I'm also not sure why you added a SetSafetyEnabled(false).
Quote:
Originally Posted by rich2202 View Post
Two possible problems:

1) Isn't it "AutonomousPeriodic()" and not "Autonomous()"
2) "wait (2)" might give you heartbeat problems. If your periodic code hangs for 2 seconds, FMS might think you have crashed and disable your robot. It is better to set a timer and check the timer each time AutonomousPeriodic is called.
Quote:
Originally Posted by cantdecide View Post
I believe that OP is using SampleRobot, hence OperatorControl() and not OperatorPeriodic().
Thanks for the help guys! I never actually saw these until now but I've figured everything out with my autonomous. I'm not even sure what the heck I did before but I understand my new code and it works great. Also, I apologize if quoting each of your posts is a nuisance, I'm not yet sure how to technically reply to all of you at once.
Reply With Quote
  #6   Spotlight this post!  
Unread 16-02-2016, 14:05
dibblec's Avatar
dibblec dibblec is offline
Registered User
AKA: Mr. C
FRC #4824 (BerryBotics)
Team Role: Mentor
 
Join Date: Dec 2013
Rookie Year: 2013
Location: Indiana
Posts: 20
dibblec is an unknown quantity at this point
Re: Autonomous

Quote:
Originally Posted by alexusaywla View Post
Thanks for the help guys! I never actually saw these until now but I've figured everything out with my autonomous. I'm not even sure what the heck I did before but I understand my new code and it works great. Also, I apologize if quoting each of your posts is a nuisance, I'm not yet sure how to technically reply to all of you at once.
Would you mind reposting your code for the benefit of the community?
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:15.

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