ROBOTC.net forums
http://robotc.net/forums/

multitasking
http://robotc.net/forums/viewtopic.php?f=52&t=7668
Page 1 of 1

Author:  sprtmed [ Sat Jan 11, 2014 8:38 am ]
Post subject:  multitasking

I can not get the encoders to work. (see previous post) :evil:
going to try this.

need robot to move forward
motor[right] = 20;
motor[left] = 20;
wait1msec(5000);

while it is doing that task, I need it to move a servo from 1 to 225.

if (SensorValue)(IR) = 5)
servo(basket) = 225;

else
servo(basket) = 1;


I do not want the robot to stop until it has timed out, I want the ir sensor to trigger the servo to move during the 5 second run of the robot.

I need a while loop, but where do I put it?
How do I make the 5 sec run a condition?
I wish my encoders worked.

Author:  MHTS [ Sat Jan 11, 2014 3:51 pm ]
Post subject:  Re: multitasking

sprtmed wrote:
I do not want the robot to stop until it has timed out, I want the ir sensor to trigger the servo to move during the 5 second run of the robot.

I need a while loop, but where do I put it?
How do I make the 5 sec run a condition?
I wish my encoders worked.

Instead of calling wait1Msec(5000) that makes the robot to sleep for 5 seconds and doing nothing else, you need to have the robot just loop and watch the clock until it reaches 5 seconds. While it is watching the clock, it could also watch the IR at the same time. Something like this. BTW, when you compare for equity, you need to use a double equal "==". A single equal is an assignment operator, not a logical compare operator.
Code:
motor[right] = 20;
motor[left] = 20;
ClearTimer(T1);
while (time1[T1] < 5000)
{
    if (SensorValue[IR] == 5)
    {
        servo[basket] = 255;
    }
    else
    {
        servo[basket] = 1;
    }
    wait1Msec(20);
}
motor[right] = 0;
motor[left] = 0;

How do the encoders not work? Are they not reading correctly? Or is your code not behaving correctly? If so, how did it behave and what was the code?

Author:  sprtmed [ Sun Jan 12, 2014 10:43 am ]
Post subject:  Re: multitasking

Thank you again for your quick response. We tried the encoders on my recent "bat out of hell" post. We have a match this weekend and this is my last resort. We will be at the mercy of a battery charge, but I think we can score some points with this method. Trust me in the fact that I redid everything with the encoders. May try again after this coming weekend.

Author:  sprtmed [ Mon Jan 13, 2014 10:47 am ]
Post subject:  Re: multitasking

Thanks for the help with the code. Did not know what to call the internal timer. We can Score!!!!

Author:  Xandra [ Fri Oct 24, 2014 6:58 am ]
Post subject:  Re: multitasking

There's actually a different command for that. For the instantaneous Tetrix battery level, you use externalBattery. For the average Tetrix battery level, you use externalBatteryAvg.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/