I want to do some automation. I put Automation(); in the user routines fast.c under the ‘insert auto in here’. Does this need to be Automation(void);?
I put Automation(); in the userroutines.h. Does this need to be automation(void);?
What would be an example of why the void is used? I know it is something like if the function returns output but do I need to expressly say this function has run?
I put my my automation function in user_routines.c defining it as void automation(void) {
Please tell me if all that I said is o.k.
Now how do I make it so that I can put Automation in its own .c file? Will it need its own .h? Do I have to define the .c file in ht userroutines.h? How will it know to use automation.h? to get to automation.c? to get to automation().
Now, how do I test this auto code without being in a match? Do I just move the call to automation from urf.c to ur.c?
I think you need to learn a bit more about C and C function prototyping. A good link repository is on the AVRFreaks Forum.
You could just move the functions from user_routines_fast.c to user_routines.c, or you can create an autonomous jumper. I forget specifically what pins you need to jump on the OI, but a quick search should bring it up.
user_routines_fast.c is for auton and user_routines.c is for manual driving.
make a .c file and a .h file(make sure when saving)
the header file or .h is for defining variables and the function prototypes such as
void Automation(void);
but when you use the function in the program its just Automation();
look at how the the user_routines.c and user_routines.h are set up.
In the Automation.c put:
#include “user_routines.h” #include “Automation.h”
put all the includes that you see in user_routines.c
void Automation(void)
{
//put the code here
}
in user_routines_fast.c (and where ever else you call it) put the #include “Automation.h” with all the others.
for the header file (Automation.h) to work you have to put
#ifndef _user_program_h #define _user_program_h
//Define variables here (this not needed but it is for organization)
//Define function prototypes here(this also is commented out like the line above)
Thanks for not sabatoging me wink Well, one more question, since I just found out that it take slighly longer to go out to other.c files for 1 single function than to just put in a separate subroutine, I just want to know how to create my own subroutine here is what I did, tell me if I am right please:
void Automation(void)
{ Code here
}
Now, do I need to specifically do something like this or does it only run it once unless it has a loop in itself ~[or if it is in a loop, will it get run more than once?]:
void Automation(void)
{
int automationhasrun=0
if automationhasrun=0
{ Code here
automationhasrun=1
}
else {}
}
The subroutine is right but you have to put a function prototype in the user_routines.h
ex. void Automation(void); like the others already there
Now place this subroutine below all others in user_routines.c
Then call it like inside the function, void Process_Data_From_Master_uP(void)
and comment out the Default_Routine()
ex. (to allow you to control when the auton on and off)
if(p1_sw_trig==1)
Autonomous();
else
Default_Routine();
//basicly you have to hold the trigger to execute the auton.
No that wont work because it will only execute the auton once for a fraction of a second (26.2 ms to be exact) because the next time the automationhasrun = 1 so it wont run again;
DON’T DO THIS BECAUSE YOU DON’T HAVE CONTROL OVER IT.
The trigger control above will let you control the running of the auton.
No that wont work because it will only execute the auton once for a fraction of a second (26.2 ms to be exact) because the next time the automationhasrun = 1 so it wont run again;
DON’T DO THIS BECAUSE YOU DON’T HAVE CONTROL OVER IT.
But if I did use the variable, wouldn’t it ensure that the subroutine just runs 1 time and never again until the robot is powered on? If I wanted a subroutine to run just one time in default_routines, would this need be used?
while (autonomous_mode) /* DO NOT CHANGE! */
{
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
{
Getdata(&rxdata); /* DO NOT DELETE, or you will be stuck here forever! */
/* Add your own autonomous code here. */
Generate_Pwms(pwm13,pwm14,pwm15,pwm16);
Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */
}
}
Like here won’t it continuously loop the Auto code(An any subroutines in it) until it realizes ‘hey, I am not in auto mode anymore’?
And what does the generat_pwms part do? Aren’t they already initialized?
But if I did use the variable, wouldn’t it ensure that the subroutine just runs 1 time and never again until the robot is powered on? If I wanted a subroutine to run just one time in default_routines, would this need be used?
I don’t completely understand your question?
It has to execute more than one cycle because a cycle only runs for a fraction of a second.
Now if you just want to run it once and set a bunch of pwm values then it will work but if you want to adjust these values later then it can’t because it is not executing.
Like here won’t it continuously loop the Auto code(An any subroutines in it) until it realizes ‘hey, I am not in auto mode anymore’?
First, yes it will and it is controlled by that switch mechanism you make for the operator interface.
In the real competion that loop autonomous_mode will execute for however long they singnal it to run in autonomous (10 sec for this years game).
If you make that switch mechanism you can run this loop for as long as you want. While the switch is on.
What I gave you before just lets you test auton without haveing to make that switch box. It lets you control how long the auton runs because you don’t know when the robot starts acting crazy.
But FOR THE COMPETETION if you want he auton to work you have to put it in this user_routines_fast.c
Second the pwms 13-16 are different as they are generated by the user processor while all the others are generated by the master processor. They referesh faster ever 2ms rather than the 17ms for the 1-12 pwms. They are hardware generated. They are to fast for the servos.
I hope it answeres your questions, but if it doesn’t then could you explain your quesiton differently?