View unanswered posts | View active topics It is currently Sat Apr 04, 2020 11:55 am

Reply to topic  [ 4 posts ] 
Author Message

Joined: Thu Jul 08, 2010 3:50 pm
Posts: 18
Post Multitasking
I have written this code to make two motors run at the same time while checking the POT values of two seperate POTs, however, there is something wrong because the tasks don't fully complete. Can you see something wrong or do you have a better way of preforming this action?

initialize.c [2.84 KiB]
Downloaded 417 times
Fri Jul 16, 2010 5:46 pm

Joined: Mon Mar 15, 2010 4:24 pm
Posts: 124
Post Re: Multitasking
I looked this over and I think you really need to add some comments to the code, since it's not clear what you're trying to do.

One of the first problems is that you only need to start each task once, not in a loop in main. Just start each task, then put something like


at the end to allow your program to run for 10 seconds. Later you can make it run forever.

Inside the tasks, though, there are too many nested while loops, I think, and you need to put waits in the loops. I'm guessing that you don't really want while loops, but just simple if statements? But I can't tell what you're trying to do exactly.

Maybe you could simplify things and just work on one task at a time. Once you figure out how it works, then the other task should be easy.

If you're really just trying to do something once for each motor to initialize it, you shouldn't be using tasks at all but simply defining them as functions such as "void One()" and calling the function like "One()". Of course, you can't have infinite loops in the functions or they will never finish.


Fri Jul 16, 2010 8:27 pm

Joined: Thu Jul 08, 2010 3:50 pm
Posts: 18
Post Re: Multitasking
I've added comments to allow you to know what i'm trying to do. I tried to use if's, but it seems as though the while's work when each task is in a stand-alone program, but when I add each section of code to a task the robot does nothing. I'm not quite clear on the whole task command so maybe i'm doing something completely wrong. Thank you for all your help.

walk.c [3.82 KiB]
Downloaded 437 times
Sat Jul 17, 2010 12:27 am

Joined: Thu Jul 08, 2010 3:50 pm
Posts: 18
Post Re: Multitasking
It works!! I just added a wait in the main task and that did the trick. Thanks for your help.

Sat Jul 17, 2010 1:48 am
Display posts from previous:  Sort by  
Reply to topic   [ 4 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.