![]() |
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 |
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).
|
Well then how do you do so?
|
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. |
Re: Functions
Code:
class myRobot : SimpleRobot { |
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 |
Re: Functions
Quote:
|
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:
|
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.
|
If I wanted to put said functions in there own header file and pass a Jaguar reference into them how would I do so
|
| All times are GMT -5. The time now is 01:21. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi