View Single Post
  #15   Spotlight this post!  
Unread 15-01-2008, 08:24
JBotAlan's Avatar
JBotAlan JBotAlan is offline
Forever chasing the 'bot around
AKA: Jacob Rau
FRC #5263
Team Role: Mentor
 
Join Date: Sep 2004
Rookie Year: 2004
Location: Riverview, MI
Posts: 723
JBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond repute
Send a message via AIM to JBotAlan Send a message via Yahoo to JBotAlan
Re: Getting constant motor power with IR board

NOTE: Programmers with more experience than I, feel free to chime in...I've learned that my methods are sometimes not the shortest/best route from A to B...

Also note that the post above mine is in easyC--it looks like you are using MPLAB. That's all right, just as long as you don't try to insert easyC snippets into your MPLAB project.

Quote:
Originally Posted by Nightfall831 View Post
i am not surprised at the result i am getting, but all attempts to create constant motion have failed. the only way i can think of is to have the remote cause a variable to be "true" and so that

Code:
while (variable = true)
     {
          pwm03 = pwm04 = 1;
          pwm07 = pwm08 = 255;
     }
or something to that effect

any suggestions?
That's basically what you want to do; if you want an IR command to send the robot x amount of feet forward, a simple way of doing this would be to define a variable used for time.

Now, if you define said variable inside the function (where you are writing the code snippets you posted), the variable will lose its value every time the function is called. There are two ways to fix this problem. One way (the preferred method, I'd say) is to define the variable as static--instead of
Code:
int variable;
you'd put
Code:
static int variable;
What this does is it makes the variable hold onto its value even when the processor isn't calling the function. Another way to make the variable keep its value is to define it outside of the function. Instead of putting the "int variable;" inside your function, you can put it at the top of the file, where it will hold its value between function calls. Note that this method should only really be used if more than one function need access to this variable; otherwise the first method I mentioned provides better readability.

Once you have the variable defined, one way of doing what you desire is to use that variable as a countdown to when the robot is going to stop. That way, when you recieve an IR signal, you can set it to a value that means "1 second" (will not be 1--let me explain in a moment), and each loop, the robot will subtract 1 from that value. Once the counter reaches 0, it will shut off the motors and stop subtracting.

Realize that if you write this code inside of Process_Data_From_Master_uP (sorry if I have the function name wrong...I don't have MPLAB in front of me right now) or it calls the function that executes this code, it will run about every 23 milliseconds--a millisecond is a thousandth of a second. Using that bit of information, you can calculate how big your counter should be: 5 seconds = 5000 milliseconds / 23 milliseconds per tick = 217 ticks.

I would post some sample code, but I'd like to see you try to write it first--I want you to know this inside-and-out before the first regional.

Let me know if you need more help.
JBot
__________________
Aren't signatures a bit outdated?