Re: Threading problems
"Anders Lyhagen" <[email protected]> Mon, 29 Mar 2004 15:51:52 +0200
| Newsgroups | gmane.comp.cybernetics.webot.contest |
|---|---|
| Message-ID | <001d01c41595$04a06f30$f1447f3e@Anders> |
Sorry, my mistake..I had an update method that did camera_get_image after
each robot_step, thus when update was called from a thread the problem
occured. Now it works fine. Thanks.
/Anders.
> Hi,
>
> It seems the following threaded program works fine on my Windows XP
> machine with Webots 4.0.20 (see attachment). What error (if any) do you
> get ?
>
> -Olivier
>
> Anders Lyhagen wrote:
>
> >Hi,
> >
> >The problem occurs when you make a call (from a thread) to any method
> >in the webots API (camera_get_image, servo_set_position, robot_step
> >etc).
> >I solved the image processing the way you mentioned but I would like to
> >thread some movements as well, however, that is
> >impossible (with XP). Might install Linux though..
> >
> >Best,
> >Anders L
> >
> >
> >
> >>Hi,
> >>
> >>I could reproduce this problem and tryed to fix it but it is not
> >>easy...
> >>Strangely enough, this problem occurs only under Window. The program
> >>appear to work fine under Linux... Actually under Windows the same
> >>OpenGL context cannot be shared among different threads, instead
> >>different OpenGL context should be used in each thread which cause some
> >>problems with initialization and cleanup which is done by the main
> >>thread...
> >>
> >>It would be possible to create a special subclass the java Thread that
> >>would work with camera, but it would complicate the programming API.
> >>
> >>Instead, I would recommand you that only the main Thread should do the
> >>image acquisition, i.e., camera_enable() and subsequent
> >>camera_get_image() while you can distribute the image processing on
> >>other Threads. The int array receiving the image should be global
> >>variable to be shared between threads. Of couse, this requires some
> >>basic Thread synchronization to work well.
> >>
> >>-Olivier
> >>
> >>Olivier Michel wrote:
> >>
> >>
> >>
> >>>Anders Lyhagen wrote:
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>>Hi,
> >>>>
> >>>>Does anyone know why this code yields a "cannot activate openGL
> >>>>context"
> >>>>error?
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>I recently made the Webots API MT-safe, but this was not enough to fix
> >>>that problem. It seems that the OpenGL context is not inherited in
> >>>subsequent Java Threads. I will try to sort that out as it is
> >>>becoming a
> >>>recurrent question... Thanks for the source code which is very simple
> >>>and shows nicely the problem.
> >>>
> >>>-Olivier
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>>import com.cyberbotics.webots.Controller;
> >>>>public abstract class Judoka0 extends Controller {
> >>>> static int camera;
> >>>>
> >>>> public static void reset() {
> >>>> camera = robot_get_device("camera");
> >>>> }
> >>>>
> >>>> public static void main() {
> >>>> camera_enable(camera, 64);
> >>>>
> >>>> Sensors sensors = new Sensors();
> >>>> sensors.setPriority(Thread.MIN_PRIORITY);
> >>>> sensors.start();
> >>>>
> >>>> while(true)
> >>>> robot_step(64);
> >>>> }
> >>>>
> >>>> static class Sensors extends Thread {
> >>>> public void run() {
> >>>> while(true) {
> >>>> int[] img = camera_get_image(camera);
> >>>> try {
> >>>> thread.sleep(200);
> >>>> }
> >>>> catch(Exception e){}
> >>>> }
> >>>> }
> >>>> }
> >>>>}
> >>>>
> >>>>Best regards,
> >>>>Anders.L
> >>>>
> >>>>
> >
> >
> >
> >
> >
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
----------------------------------------------------------------------------
----
> import com.cyberbotics.webots.Controller;
> import java.io.*;
>
> public abstract class Judoka0 extends Controller {
> public static void die() {
> System.out.println("die method called");
> }
> static int joint;
> public static void reset() {
> joint=robot_get_device("back_1");
> }
> public static void main() {
> servo_enable_position(joint,64);
> Motion motion = new Motion();
> motion.setPriority(Thread.MIN_PRIORITY);
> motion.start();
> while(true) robot_step(64); // run one step
> }
> static class Motion extends Thread {
> public void run() {
> float pos=0;
> while(true) {
> servo_set_position(joint,pos);
> pos+=0.05;
> try {
> Thread.sleep(200);
> } catch(Exception e) {}
> }
> }
> }
> }
>
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/pU_rlB/TM
---------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/webots-contest/
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/