Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Real time programming in robotics with c++ [closed]

I am working on a robotics project with C++ and OpenCV. In this step, I have faced a problem which consists of:

I have two methods moveRight() and moveLeft() that I called successively in my code, but the problem is that the second one does not run, because the first one needs time (the time of robot movement), but when I put Sleep(5000) between them (I guessed that five seconds are enough for the movement), all is OK.

What is a programming solution that avoid the use of Sleep (because it makes some other problems)?

like image 763
Houssem Badri Avatar asked Dec 13 '12 08:12

Houssem Badri


2 Answers

You can try to add a layer of indirection. Add a queue of actions to perform, enqueue actions to moveLeft and moveRight, and somewhere else (different thread) execute actions from the queue correctly by waiting for previous action to complete before you do next action. Ideally you need a way to check if action is finished, so you can code it in a event based fashion.

like image 172
Karthik T Avatar answered Sep 20 '22 08:09

Karthik T


You should never "guess" in robotics. You should KNOW, MEASURE how long your movement takes and use that in your code. For instance call moveRight() often and have it check how long it has been running. Make it return true when it's running and use that as a condition to call moveLeft()

like image 35
RedX Avatar answered Sep 21 '22 08:09

RedX