![]() |
Auto mode... need help
Hey guys,
ok i doign some stuff in automode.. nothing tooo cool.. but its a start. Basicaly all i am doing is driving the robot forward and backwards. Now.. i have it program in "if" statements example. if (count == 1) { pwm01 = 254; } sooo... i need a timer. count is what the time is. Sorta confusing but at 1 second its goign to go forward. But the problem i am having is creating code for the timer. Does the orignal code have a timer programmed already ? or should i make my own. let me know:) |
Re: Auto mode... need help
The easiest way to do this is to increment a variable every time you get new data from the master processor.
Default Autonomous: Code:
while (autonomous_mode) /* DO NOT CHANGE! */Code:
static int i;Code:
while (autonomous_mode) /* DO NOT CHANGE! */Code:
int time;Code:
int time;Hope this helps, and sorry for the long post. ;) |
Re: Auto mode... need help
That assumes that your code will take the same time as the default code does. Maybe you have some intensive stuff and each loops takes longer than the 26.2 ms loop. Your code works effectivly for most things though. teh_pwnerer795, if you wanted to use the chips timer post back and ill post code for using that.
|
Re: Auto mode... need help
I used a simpler approach this year and had no issue with it. :)
I would doubt that you could tax the processor to the point that the autonomous code would take longer than 26.2ms |
Re: Auto mode... need help
Quote:
I would suggest using real timers. For more information, take a look at IFI's white-paper (PDF). They have a very nice explanation of how to use the timers built into the PIC. |
Re: Auto mode... need help
Awesome.
I know rite now my code isnt very intensive at the moment.. but i do tend to have long code.. lol my engineering program for turing was 1500 lines when someppls were 100. but got it down to 150 once i got some logic into it!!:)...but ye i'll keep u posted if it works or not... |
Re: Auto mode... need help
Code:
int time;no problem for the post... im sorta confused.. if the computer cycles at 26.2 ms... will it not cycle rougly 38 times in a second? if so... your code.. where 'i' is increased by 1 every cycle, when it reaches 1 second.. i == 38..... if so... time == 4 roughly at 1 second... shouldnt u divide it by 4? to get 1 second??? srry if i confused you:P lol srry just trying to understand the logic behind 'time' |
Re: Auto mode... need help
Quote:
OMG i am such an idiot I GET IT NOW:):D SOO SRRY:) hm.. another question... how do i round? i remember doing it in java... not suer if its the same in C |
Re: Auto mode... need help
Quote:
Actually the problem as mentioned before is its very unlikely to take that long. If memory serves it loops as fast as possible, so it could run anywhere from about 12ms to 26.2 and it will change depending on your autonomous code, if its really time sensitive, you should use the hardware timer, and its just good to know how to use that anyway. |
Re: Auto mode... need help
Quote:
If you really needed the decimal part, you could use the float type instead of int. There are some problems with doing this discussed here, and I wouldn't really recommend doing this on the RC. EHaskins offered up some good suggestions, but there is a slight annoyance with it. What happens if you have a 10 step time based routine and you need to change the first duration to be a little longer or shorter? You have to change them all. One way to fix it would be to use constants, and make them relative to each other. Code:
#define AUTO_STEP1_END (10)Code:
#define NOT_DONE 0Here's another perk. If you want to add a delay between step 2 and 3, you could change the enum to have PROG_STEP_2A between PROG_STEP_2 and 3. Then, in your switch, you could do something like Code:
...Code:
... |
Re: Auto mode... need help
Quote:
|
Re: Auto mode... need help
Quote:
Hope this helps, Paul |
Re: Auto mode... need help
Quote:
|
Re: Auto mode... need help
I have to say, after a season and a half of asking the strategy guy how long he wants it to go out, then stepping into Calculator, then punching the wrong numbers, then typing the wrong number I just calculated into my code (now converted to 26.2ms cycles), then seeing it totally mess up when I put it on the field...having a *real* timer is SO nice. I implemented the hardware timer, so now I have a Windows-style GetTickCount() type function, and it works very accurately. The scouts tell me that the bot needs to be in front of the other bot in 2 seconds: I give them 2 seconds. Not 2000ms / 26.2ms = 76 cycles--blech. Those never worked right for me.
What I haven't solved yet is the overflow issue. What data type do I use to hold the huge number? I have no idea. I can't reset the tick count to 0 each time it hits the upper limit my code is waiting for because I have more than one part of my code using this tick count. I think I'll use the hugest data type I can get--I'll have to look it up; I don't know C in and out. JBot |
Re: Auto mode... need help
Here's some code for an interrupt-driven timer.
Call Timer_1_Initialize() in the User_Initialization routine in user_routines.c, add the call to the interrupt handler to user_routines_fast.c. Time is in the timer_ variables. Mike Code:
/*******************************************************************************Code:
/*******************************************************************************Add this to the InterruptHandlerLow() routine in user_routines_fast.c Code:
|
| All times are GMT -5. The time now is 18:00. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi