Real time programming in robotics with c++

c++, real-time, robotics

Solution

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.

Problem

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)?

Original source