View unanswered posts | View active topics It is currently Sat Oct 25, 2014 9:27 am






Reply to topic  [ 5 posts ] 
multitasking 
Author Message
Rookie

Joined: Thu Dec 26, 2013 8:17 pm
Posts: 9
Post 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.


Sat Jan 11, 2014 8:38 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post 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?


Sat Jan 11, 2014 3:51 pm
Profile
Rookie

Joined: Thu Dec 26, 2013 8:17 pm
Posts: 9
Post 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.


Sun Jan 12, 2014 10:43 am
Profile
Rookie

Joined: Thu Dec 26, 2013 8:17 pm
Posts: 9
Post Re: multitasking
Thanks for the help with the code. Did not know what to call the internal timer. We can Score!!!!


Mon Jan 13, 2014 10:47 am
Profile
Rookie

Joined: Fri Oct 24, 2014 6:51 am
Posts: 1
Post 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.

_________________
Xandra


Fri Oct 24, 2014 6:58 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.