![]() |
More automonous help:ending stuff
OK! I got a line sensor code (verrrrrry basic) and I would like to now a few things:
1. I know the robot will arrive at the T in under 15 secs, so how do I stop it and do something different? 2. If I stop it, we would like to raise our arm (on winch), which is on a PWM. 3. How would I stop the arm? Same way as # 1? Code:
|
Re: More automonous help:ending stuff
Ok...well it's difficult to tell you exactly what to do without knowing your robot, but I'll try. There isn't a timing component in your code, it looks like, it just follows the line as far as it can, turning motors to different values when certain sensors see the line. Without some form of timing you won't be able to tell it to stop when you want, or time when the arm raises up/stops.
The simplest form of timer you can have is a program cycle counter, which will operate *around* 40hz, or about 25ms per count (its actually more like 28.something). So, add in a variable "count" (int count = 0; in your initialization) somewhere, and at the end of the loop say "count++;". Then, check when the count is higher than a certain number (the time you want to stop, or raise the arm, or stop raising the arm), and set the pwm values to something different that you want. Make sure to set those values lower in the loop than the sensor code, or they will get overridden. You'll probably just have to time it yourself, or count the number of times a certain sensor sees the line (as in did it just turn?), and then raise the arm. There are better ways of controlling the robot based on time and other factors, but its probably more complicated than you really have time for right now. Hope I helped. |
Re: More automonous help:ending stuff
Thanks, but can you be more specific. Put timer where in ins? Could you give and example, I can change the code but I can't write it...++ means add twice to me
|
Re: More automonous help:ending stuff
In your User_Initialization create a variable called count (you can create it anywhere but that's probably the best spot for now), with this syntax:
int count = 0; Then at the bottom of the while(autonomous_mode) loop in your code, right above Putdata(&txdata), put in count++; ++ in C means the same thing as "count = count + 1;", so you are incrementing it by one every time you pass through that loop. Multiply count by 40 and you have *approximately* the amount of time autonomous has been running. You'll have to time it and do the math yourself, but when you want it to break off, say something like (below your line following code): if(count > 200){ pwm01 = 254; pwm02 = 254; } else if(count > 300){ pwm01 = 0; pwm02 = 0; } else if (count > 320){ pwm01 = 127; pwm02 = 127; } That won't do much, just go forward and stop after a little over 2 seconds, but hopefully you get the picture on what you can do. Adjust values to your desire, and good luck. |
Re: More automonous help:ending stuff
I think you'll need to declare that int as 'static' -- otherwise it won't be remembered from one cycle to the next:
Code:
static int count = 0;Code:
// this is global: |
Re: More automonous help:ending stuff
Barry,
Let me reply to your first question. I created an auto mode with a "sequence of events" that were timed. I created two files, 'myAuto.c' and 'myAuto.h' (not really -- I'm simplifying). (BTW, the code examples below haven't been compiled and they probably have at least typo bugs.) In the .h file I made a list of named states using the C 'enum' construct: Code:
// myAuto.hAlso in myAuto.h I #define some constants. Code:
// machine cycles at about 38 Hz.Okay, myAuto.c has a static int counter that counts each timed phase. Something like this: Code:
// myAuto.cHope that helps! -Norm |
Re: More automonous help:ending stuff
Wow, I get a head ache reading all that... but I think I get it.
1. Put that static count in 2. Add the PWM for the winch on the timer 3. Calculate the figures One more thing. If say at 2000 I tell PWM 13 & 15 to shut off and the at 2000 tell PWM 3 (winch) to raise till (lets say) 2750 will the timer interfere with any of the line sensors? Does the position of the timer code affect it? |
Re: More automonous help:ending stuff
Quote:
|
Re: More automonous help:ending stuff
Quote:
I haven't really been following along completely, ;) but unless the line sensors/PWM part try modify what the timer is at, you should be fine. :) |
Re: More automonous help:ending stuff
Here is the final code (drum roll please)
Code:
One more thing... I attached a screenshot of where I placed the counter (in the user instalizationz). I this the right spot? Thank you all who answered my questions...This site has been our only programming resource for our team. :) |
Re: More automonous help:ending stuff
Quote:
Code:
static int count = 0;Code:
count++;Code:
/* Hey! There are 3435 loops in 15 minutes */Let's say you want to start the arm after 12 seconds and run it for 2 seconds. Change "1000" to "456" (38 * 12) and "1005" to 532 (38 * (12+2) ). Does that make sense? I take it that this is a line-following routine, and the three inputs are three line sensors(?). Consider that your timing test Code:
else if (count > 1000){How about wrapping the tests on the sensors inside an "if" statement so that they only run if the time is not yet up to a certain point: Code:
if ( count < 456 ) // still less than 12 seconds have elapsedBTW, your algorithm (for line following?) seems to have a case where it will stop the motors: Code:
if (rc_dig_in01 == 0 && rc_dig_in02 == 0 && rc_dig_in03 == 0)-norm |
Re: More automonous help:ending stuff
Quote:
Makes me want to cross-post this in the "Why I hate C" thread. :ahh: |
Re: More automonous help:ending stuff
There was already a message here which showed how to do some simple state-based autonomous code. THIS IS THE RIGHT WAY TO DO THINGS.
Your autonomous code effectively moves through a series of states. You stay in a state until ready to transition out of this state. Each state have have specific outputs (like a "Moore machine") or have outputs which directly depend on inputs (like a "Mealey/Mealy machine"). There is no reason to have to make your outputs entirely Mealy. Add a state variable -- it really does help. A simple example can also be found in one of our team's (1014) code: http://www.osufirst.org/twiki/bin/vi...04RegionalCode If you look in the user_routines_fast.c in the autonomous section, you'll see the whole thing is based on state. Because we have position feedback, we transit out of states once we reach a particular position. However, this could just as easily be time. In general, it's nice to setup an interrupted-based timer that keeps a moderately real-time clock running on your machine and to use that as feedback timing your operations and calculating important characteristics like speed. Keep your code in terms of state and you'll have a much nicer time coding, especially when adding states, maintaining states, and doing simple things like stopping. Sorry that the 1014 autonomous code has little commenting -- one of the nice things about the states (and the speed controllers) is that we could write our autonomous code on the fly at competition and it was easy to debug there. We never intended to have autonomous code... we just felt it was good to add it in since so few robots at our regional had any. |
Re: More automonous help:ending stuff
Just looked at my code way up there and realized that i had >'s instead of <'s...sorry for the confusion.
|
Re: More automonous help:ending stuff
HI,
I don't have time to write something lengthly, so I will write one thing: - I placed count++ whatever in user_routines. Is this the right spot? Canadian regoinal starts THURS but we leave TOMORROW, but our hotel has internet so post the answer please |
| All times are GMT -5. The time now is 03:09. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi