Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   counting in seconds for the autonomous mode?? (http://www.chiefdelphi.com/forums/showthread.php?t=27353)

10intheCrunch 31-03-2004 02:29

Re: counting in seconds for the autonomous mode??
 
Well, we have had problems when using those generated PWMs, especially if they are called quickly. We've observed fluctuations in the motor we're trying to adjust as well as induced outputs on other PWMs that are generated. Switching to PWMs 1-12 solved these problems.

While it may not be a bad idea in theory to call G_PWMs quickly, for practical application with the robots we are building, its unnecessary and possibly detrimental. Do you really need to update your actual motor output at faster than 38hz?

KenWittlief 31-03-2004 07:48

Re: counting in seconds for the autonomous mode??
 
Quote:

from TedP: Having interrupt-controlled timing that is triggered by an interrupt generated by the terminal count of a hardware timer timed fairly precisely to go off every 100th of a second (or even finer) seems much simpler than using a counter to do this timing...
setting up a hardware timer and writing an interrupt routine seems much simpler than putting
Code:

    auton_time++;
in your code

?!

you gotta remember lots of students are struggling just to understand this stuff, and dont normally use uP hardware everyday :^)

Pattyta 31-03-2004 08:32

Re: counting in seconds for the autonomous mode??
 
would this code work u think?? we're going to use a stopwatch to determine how long it actually takes us in average. the only think we are doing in autonomous mod is driving to the 10 pt ball and hopefully noking it down.

void User_Autonomous_Code(void)
{
/* Initialize all PWMs and Relays when entering Autonomous mode, or else it
will be stuck with the last values mapped from the joysticks. Remember,
even when Disabled it is reading inputs from the Operator Interface.
*/
pwm01 = pwm02 = pwm03 = pwm04 = pwm05 = pwm06 = pwm07 = pwm08 = 127;
pwm09 = pwm10 = pwm11 = pwm12 = pwm13 = pwm14 = pwm15 = pwm16 = 127;
relay1_fwd = relay1_rev = relay2_fwd = relay2_rev = 0;
relay3_fwd = relay3_rev = relay4_fwd = relay4_rev = 0;
relay5_fwd = relay5_rev = relay6_fwd = relay6_rev = 0;
relay7_fwd = relay7_rev = relay8_fwd = relay8_rev = 0;

while (autonomous_mode) /* DO NOT CHANGE! */
{
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
{
counter++;
Getdata(&rxdata); /* DO NOT DELETE, or you will be stuck here forever! */

/* Add your own autonomous code here. */

// counter calculated as (38*12)

if ( counter < 456 ) // still less than 12 seconds have elapsed
{


if (rc_dig_in01 == 0 && rc_dig_in02 == 0)
{
pwm13 = pwm14=137;
pwm15= pwm16= 137;
}

if (rc_dig_in01 == 1 && rc_dig_in02 ==0)
{
pwm13 = pwm14= 128;
pwm15= pwm16= 132;
}

if (rc_dig_in01 ==0 && rc_dig_in02 == 1)
{
pwm13 = pwm14=132;
pwm15= pwm16=128;
}

}


Generate_Pwms(pwm13,pwm14,pwm15,pwm16);

Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */
}
}
}

Mark McLeod 31-03-2004 08:41

Re: counting in seconds for the autonomous mode??
 
Quote:

Originally Posted by TedP
You can Generate_Pwms() as fast as you can as well because those are the FAST PWMs. They can be handled specially.

Actually this is not true and is not a good idea to do blindly.
It isn't a matter of how fast our controller can spit out PWM updates, but a matter of how fast the device at the receiving end is designed to be updated. The victor speed controllers are not designed for a 2ms update rate. I believe they update at 60Hz or 17ms.

Use the Generate_Pwms() at the slow-loop 26ms rate or create a separate timing loop to update them at 17ms minimum for fastest updates.

[edit] I double checked and the victor does at least one type of update at 60Hz, but IFI notes imply a faster PWM update rate. I haven't been able to discover documentation on what that rate might be, other than 2ms is too fast.

Mark McLeod 31-03-2004 09:06

Re: counting in seconds for the autonomous mode??
 
Quote:

Originally Posted by Pattyta
would this code work u think??

You can make counter local to this routine. Nowhere else does it have to be seen.

I might add an initialization for counter, e.g.,
Code:

void User_Autonomous_Code(void)
{
unsigned int counter=0;
...
while (autonomous_mode) /* DO NOT CHANGE! */

[edit] The following is not germane to this case you should just be aware of the pitfall.
Even if you initialized counter when you declare it, e.g., static unsigned int counter=0; You'll have trouble during the practice sessions when you run twice in a row. You'd have to be sure to reset the RC between runs. Explicitly setting it before the auto loop avoids this potential pitfall.

[edit]
Actually "static" isn't required in this case, since you never leave the routine. I only tend to use it as a matter of convention (Our functions aren't written to take control away from the main loop).
You can in this case declare "unsigned int counter=0;" in the local routine and be fine. I still prefer explicit initialization though.

KenWittlief 31-03-2004 09:15

Re: counting in seconds for the autonomous mode??
 
Quote:

Originally Posted by Pattyta
would this code work u think?? ...

looks like you got the right idea - I would punch up your pwm outputs higher when you want the motors on- they are just barely running the way you have it - start with maybe 1/4 or 1/3 power (pwm=170) and see what it does

BTW at most regionals they have a carpet setup in a back hallway where you can test your auton code - you usually have to sign up for a time slot, but it really helps to be able to test it, tweak your code, test it again...

it looks good - your on the right path.

Alan Anderson 31-03-2004 10:12

Re: counting in seconds for the autonomous mode??
 
Quote:

Originally Posted by TedP
See page 18 of:

http://www.innovationfirst.com/FIRST...10-29-2003.pdf

on IFI's website... It warns that devices connected to the PWM outputs may have trouble with the fast changing PWM outputs and to check those device specifications, but there's nothing about the RC that makes this a bad idea.

The RC is only one component of the system. The usual device connected to a PWM output is a Victor speed controller, and multiple teams have discovered that Victors don't handle fast updates very well.
Quote:

After all, aren't Putdata and Generate_Pwms called in the default fast routines anyway?
No, the only thing called in the default fast routine is Process_Data_From_Local_IO(), and that's empty. The Generate_Pwms() and Putdata() functions are called in the default slow routines, once per communication packet.

gnormhurst 31-03-2004 12:55

Re: counting in seconds for the autonomous mode??
 
Regarding pwm13-16: See this thread, and see Kevin Watson's FAQ especially the first really long question.

I stay away from PWM13-16. 38 Hz is fast enough for me!


All times are GMT -5. The time now is 20:59.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi