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

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
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)?

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.

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

You can use a timer and when performing MoveRight() set the timer on 5 seconds, and after timer ends, perform Moveleft().

Related

Multithreaded Webserver in C++ [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to do a multithreaded Webserver with scheduling and synchronization in C++.This is an assignment problem and I am not asking the code.I have done till the socket connection in server but I dont know how to proceed.I just want some hints or flow for the program.
Here are the few questions I have
1) I have done till socket accept().So when new connection comes I have to fork() and then close the connections of the child process.Is that right?
2) How must I make sure the program is synchronized wth so many threads running?
3) I must have 2 thread pools.1 pool of workers and in the other 2,1 each for acepting connection and inserting the request to ready queue.How can this be done?
I am not asking the code.I just need some hints and guidance.Thanks a lot.
Very interesting course work , if you get you head around this one a lot of concepts will become clear namely concurrency and one of its major use cases I.e. networking!
I used the following article myself to get a quick summary of my options in network concurrency in Linux
http://m.linuxjournal.com/content/three-ways-web-server-concurrency?page=0,0
This article give very high level intros to concepts tha thou will need like copy on write for forked processes and as a result separate address spaces negating sync in certain cases, once you have read this you will have more specific question that you can as once you start getting your hands dirty starting with the code in this article.

How does one make something real time? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
This might be a really stupid question, but I can't find any info on this, and I can't find out what to search for.
How do you make something real time? For example, say we have a game, how does it run continuously without us calling a tick() method at different parts of the program?
If you are developing the program to run at a time in particular the best way I know of is to develop it to run at a particular loop rate using timed delays.
IE:
while(forever) {
do something
test how long it took
take up the remainder amount of time for the loop to run at a rate (ie 100Hz)
}
If you are desperate for real time applications you can develop and use QNX:
http://www.qnx.com/
But this certainly wouldn't be a good environment for programming games.

C : printf changes course of program [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I've got a program that simulates collisions (circles) using openGL, GLUT, GLUI. Everything worked fine but when I changed my code a bit it began to do weird things.
I have 2 buttons, "play" and "step", "play" simulates the collisions updated with a timer, "step" also simulates but you've got to click it in order to go further.
Originally it did that but now the "play" button acts the same as "step". If I add a printf in my timer callback it all works perfectly...
What can I do ?
In my timer_cb I only have got :
// printf("something\n");
glutPostRedisplay();
glutTimerFunc(getDeltaT(), timer_cb, 0);
The I/O routines, like printf, introduce a sensible delay by calling them. To answer with a certain degree of correctness you show us the User Interface code, but I think I can guess...
Are you using threads? Maybe it can be a concurrency bug because the execution of the button event handler is not synchronized with the update logic?

A countdown timer in OpenGL [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I wish to creat a countdown timer in OpenGL. So I am just looking for a function that will be called every second based on the system clock which will decrease a set variable. I tried fiddling with glutTimerfunc but itcalls back only once. I need a similar setup but one that calls back multiple times.
Timers and timer functions are neither defined by C++ nor by OpenGL but rather by the operating system you are using.
However, since GLUT seems to define one, and you are using it, here we go:
In your timer function passed to glutTimerFunc, just call glutTimerFunc with the same parameters again. That way you will end up creating an infinite loop of timer callbacks.
Use some global variable or the int value passed to the timer function to determine when to break the loop.

How to start programming with threads in MFC C++? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
i need to create new thread (diffrent class) using cwinthread or afxbeginthreads. i have no idea how to start and which one of them i need to use. help please...
thanks
There are two types of thread in MFC:
worker threads simply perform a task in the background then exit
user-interface threads which have a message pump i.e. you can PostMessage to it
When I used it in MFC a long time ago I very much disliked not being able to create the class because they force you to do it with their factory, and thus you cannot initialise it with parameters it needs to use to execute, as InitInstance() on it also takes no parameters (I think). In other words you really cannot pass them any context data unless you create them suspended, which I found I always had to do.
Worker-threads are the kind of thing I also would prefer to do without MFC since I intensely disliked the intrusiveness of MFC into non-GUI code, i.e. I didn't mind it so much as a Widgets library but found once you put it your project you were "stuck" with it.
I have had to support MFC projects but any new code areas within the project I would stay away from MFC and even use Win32API if possible.
Hi you can read this article http://msdn.microsoft.com/en-us/library/69644x60(v=vs.80).aspx and this one in class