Go to Post It is great to see your friends and other teams succeed. - Bob Steele [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 02-11-2012, 10:37 AM
inkspell4's Avatar
inkspell4 inkspell4 is offline
Registered User
FRC #3650 (Robo Raptors)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Maryland
Posts: 326
inkspell4 will become famous soon enough
Functions

In C++ is there a way to incorporate your own functions into the code for use in autonomous?
For example creating a void for moving backwards that would then be used in autonomous.

Thanks in Advance
__________________
Chesapeake Regional : 2013, 2012, 2011
Rookie Year: 2011
2013 RoboRaptors Team 3650 Programming Team Captain
Team Website : http://www.roboraptorsfrcteam3650.com/index.html
_____________________________________________
Reply With Quote
  #2   Spotlight this post!  
Unread 02-11-2012, 06:28 PM
Supernovapsy Supernovapsy is offline
Registered User
FRC #1334
 
Join Date: Feb 2012
Location: Canada
Posts: 18
Supernovapsy is an unknown quantity at this point
Re: Functions

Yes, definitely. You can create a function that tells a robot to go straight or turn or whatever, and call them in the autonomous function of the main program. The robot will automatically do what the function says when it is in autonomous mode (just don't stand in front of it when that happens).
Reply With Quote
  #3   Spotlight this post!  
Unread 02-11-2012, 07:12 PM
inkspell4's Avatar
inkspell4 inkspell4 is offline
Registered User
FRC #3650 (Robo Raptors)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Maryland
Posts: 326
inkspell4 will become famous soon enough
Well then how do you do so?
__________________
Chesapeake Regional : 2013, 2012, 2011
Rookie Year: 2011
2013 RoboRaptors Team 3650 Programming Team Captain
Team Website : http://www.roboraptorsfrcteam3650.com/index.html
_____________________________________________
Reply With Quote
  #4   Spotlight this post!  
Unread 02-12-2012, 12:29 AM
Supernovapsy Supernovapsy is offline
Registered User
FRC #1334
 
Join Date: Feb 2012
Location: Canada
Posts: 18
Supernovapsy is an unknown quantity at this point
Re: Functions

It's really up to you what to do depending on your robot's capabilities.

For example, you can make a function called Straight(), which sets the motors all going forward, and make another called Right(), which sets the motors turning in opposite directions. You then call them one after the other separated by a timer in the autonomous part of your program. This also depends on what kind of project you are using, whether it is SimpleRobot, IterativeRobot, or CommandBasedRobot.
Reply With Quote
  #5   Spotlight this post!  
Unread 02-12-2012, 12:39 AM
WizenedEE's Avatar
WizenedEE WizenedEE is offline
Registered User
AKA: Adam
FRC #3238 (Cyborg Ferrets)
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Anacortes, WA
Posts: 395
WizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to all
Re: Functions

Code:
class myRobot : SimpleRobot {
  RobotDrive drivetrain;

  void MoveFwd2Sec() {
    drivetrain.ArcadeDrive(1, 0);
    Wait(2);
    drivetrain.ArcadeDrive(0,0);
  }
public:
  void Autonomous() {
    MoveFwd2Sec();
  }
};
Reply With Quote
  #6   Spotlight this post!  
Unread 02-12-2012, 07:51 AM
inkspell4's Avatar
inkspell4 inkspell4 is offline
Registered User
FRC #3650 (Robo Raptors)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Maryland
Posts: 326
inkspell4 will become famous soon enough
So it has to go before the public portion of the class

Can anyone else also post an example they have used on their robot
__________________
Chesapeake Regional : 2013, 2012, 2011
Rookie Year: 2011
2013 RoboRaptors Team 3650 Programming Team Captain
Team Website : http://www.roboraptorsfrcteam3650.com/index.html
_____________________________________________
Reply With Quote
  #7   Spotlight this post!  
Unread 02-13-2012, 09:08 AM
inkspell4's Avatar
inkspell4 inkspell4 is offline
Registered User
FRC #3650 (Robo Raptors)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Maryland
Posts: 326
inkspell4 will become famous soon enough
Re: Functions

Quote:
Originally Posted by inkspell4 View Post
So it has to go before the public portion of the class

Can anyone else also post an example they have used on their robot
Let me rephrase this where must a/the function be declared and initialized if it was being added into the simple robot example code again please post and examples you might have
__________________
Chesapeake Regional : 2013, 2012, 2011
Rookie Year: 2011
2013 RoboRaptors Team 3650 Programming Team Captain
Team Website : http://www.roboraptorsfrcteam3650.com/index.html
_____________________________________________
Reply With Quote
  #8   Spotlight this post!  
Unread 02-14-2012, 10:56 AM
DjScribbles DjScribbles is offline
Programming Mentor
AKA: Joe S
FRC #2474 (Team Excel)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Niles MI
Posts: 284
DjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to behold
Re: Functions

Just to try to add some clarity, you don't ever initialize a function, you can declare and define a function. It's typically good practice (probably a matter of opinion, but isn't neccessary) to declare your function before you define it; alternatively, you can simply define the function without declaring it at all (in which case the definition is the declaration)

Code:
class SomeRobot
{
void NewFunction(void); //declartion of new function prior to definition
... some other stuff...
void NewFunction(void) //definition of new function
{
  ...some action to run during autonomous...
}

void OtherFunction(void) //Definition of OtherFunction(which is also the declaration)
{
... some stuff... 
}
public:
Autonomous()   
{
   NewFunction();
   OtherFunction();
   LastFunction();
}

void LastFunction(void)  //you can also declare it later, inside a class it doesn't need to declared before it's used
{
 ... some stuff...
}
}

Last edited by DjScribbles : 02-14-2012 at 11:02 AM. Reason: fixed a copy paste error
Reply With Quote
  #9   Spotlight this post!  
Unread 02-14-2012, 10:45 PM
theprgramerdude theprgramerdude is offline
WPI Freshman
AKA: Alex
FRC #2503 (Warrior Robotics)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2008
Location: Brainerd, Minnesota
Posts: 347
theprgramerdude has much to be proud oftheprgramerdude has much to be proud oftheprgramerdude has much to be proud oftheprgramerdude has much to be proud oftheprgramerdude has much to be proud oftheprgramerdude has much to be proud oftheprgramerdude has much to be proud oftheprgramerdude has much to be proud oftheprgramerdude has much to be proud oftheprgramerdude has much to be proud of
Re: Functions

You just have to declare what the function is before you call it. If you wish, you could just declare the function prototype in the class definition, then write the actual code down at the bottom of the file for organization.
__________________
Attending: MN Duluth Regional
Reply With Quote
  #10   Spotlight this post!  
Unread 02-16-2012, 09:05 PM
inkspell4's Avatar
inkspell4 inkspell4 is offline
Registered User
FRC #3650 (Robo Raptors)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Maryland
Posts: 326
inkspell4 will become famous soon enough
If I wanted to put said functions in there own header file and pass a Jaguar reference into them how would I do so
__________________
Chesapeake Regional : 2013, 2012, 2011
Rookie Year: 2011
2013 RoboRaptors Team 3650 Programming Team Captain
Team Website : http://www.roboraptorsfrcteam3650.com/index.html
_____________________________________________
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 07:10 PM.

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