|
Re: Help needed with coding simultaneous movement (EasyC/VEX)
Alrighty. First off, it should automagically not move when the RC is off or unconnected. I believe everything goes to neutral and center when the RC is off unless autonomous is enabled. At any rate, your options are to use a timer based solution or some kind of pseudo-loop.
Timer:
start a timer at the beginning of your program before the while loop.
get its value every while loop and assign it to "time" for instance.
toss in an if statement and make the condition time > ### (however many milliseconds you want between swings one side to the other)
inside that if one, preset the timer back to 0, then set the servo PWM to one way or another. use an if-else and have it based on which way the servo currently is.
This will work and is basically how I was timing the movement of my slapdash ball chambering servo. The problem I was have was that my code took forever to get through the while (1) loop. about 200 ms. so I couldn't look for time slices smaller than that. Which frustrated my attempts to shoot balls as fast as possible.
Pseudo-for loop:
have a variable called "i" put an assignment for i=(i+1)%## in your while loop. ## is the number of loops through your while loop before it rolls over, so it's the period.
put in if i == whatever statements and set the servo PWM here.
advantage of this, is you can make it move to intermediate positions at every value of i. disadvantage is I've no idea what the timing of that while(1) loop is, so you'll be sort of guessing how fast it's going.
EDIT:
Using that idea above, to modify the two loops I've suggested:
Timer: Stop the timer if the robot's not moving, start the timer if the robot is moving.
Pseudo: put an if statement around the assignment, so it only runs if the robot is running.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.
Lone Star Regional Troubleshooter
Last edited by Kevin Sevcik : 09-08-2006 at 20:30.
|