Go to Post All the robots win, because we built them and they work. ;) - synth3tk [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 18-02-2010, 23:47
adamdb adamdb is offline
Registered User
#1583
 
Join Date: Feb 2005
Location: Parker, CO
Posts: 63
adamdb has a spectacular aura aboutadamdb has a spectacular aura aboutadamdb has a spectacular aura about
Multi-threading issue?

We are trying to run the camera code on a separate thread. We are basically using the Target class as-is from the CircleTrackerDemo program and have pulled out the relevant bits of code from the main program that call it. The code is as follows:
Code:
public class CameraThread extends Thread
{

    private double kScoreThreshold = .01;
    private AxisCamera cam;
    private Target[] targets;
    private boolean targetFound = false;
    private boolean active = false;

    public CameraThread()
    {
        // Setup camera
        cam = AxisCamera.getInstance();
        cam.writeResolution(AxisCamera.ResolutionT.k320x240);
        cam.writeBrightness(0);
    }

    public void run()
    {
        while (true)
        {
            if (active)
            {
                if (cam.freshImage())
                {
                    ColorImage image;
                    try
                    {
                        image = cam.getImage();

                        Thread.yield();
                        targets = Target.findCircularTargets(image);
                        Thread.yield();
                        image.free();
                        if (targets.length == 0 || targets[0].m_score < kScoreThreshold)
                        {
                            this.targetFound = false;
                        }
                        else
                        {
                            this.targetFound = true;
                        }
                    }
                    catch (AxisCameraException ex)
                    {
                        ex.printStackTrace();
                    }
                    catch (NIVisionException ex)
                    {
                        ex.printStackTrace();
                    }
                }
            }
            else
            {
                targetFound = false;

                try
                {
                    Thread.sleep(5);
                }
                catch (InterruptedException ex)
                {
                    ex.printStackTrace();
                }
            }
        }
    }

    public void setActive(boolean active)
    {
        this.active = active;
    }

    public boolean isActive()
    {
        return active;
    }

    public boolean isTargetFound()
    {
        return targetFound;
    }

    public Target[] getTargets()
    {
        return targets;
    }
}
As you can see we set this up so we can tell the thread whether or not to be "active", which just determines whether or not it gets a new image from the camera and goes through the ellipse detection routines.

Our problem is that anytime the "active" flag is true in this routine and it is doing its thing getting images from the camera and detecting targets (which does work), our motor outputs become "jerky" as though the processor is off doing something else and can't feed the motor outputs. The motors actually turn off briefly before resuming their previous speed. We are using all Jaguars for motor control and are using the CAN network. I would think that once we send the command out the CAN network to a motor that the Jaguars would keep the speed the same unless told differently.

We do have the watchdog timeout set at .75 seconds, and we never see the "Watchdog not fed" message. We tried adding frequent "Thread.yield()" statements in this class and in the Target class, but if anything that seemed to make the problem worse. We tried taking all of the Thread.yield() calls out entirely, and tried liberal Thread.sleep(1) calls (which usually works in multi-threaded PC apps) with no change in behavior.

This thread can be running, but with the active flag set to false and we do not see the issue, so it has to be something to do with the camera code itself.

So, does this look like it should work? Is anyone else seeing similar issues using code from the CircleTrackerDemo app? Is anyone else multi-threading the camera code in a similar or different way?

As always any suggestions are appreciated.
__________________
Adam Bryant
Programming Mentor
Team 1583
Ridge View Academy Rambotics
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Threading nickmagus C/C++ 12 05-02-2009 14:41
Threading on the CRIO dpeterson3 Programming 4 04-01-2009 17:56
Threading tool not working.... strange? q_prof Inventor 3 20-02-2006 00:14
Muti-threading Ryan M. Programming 19 26-04-2004 09:10


All times are GMT -5. The time now is 09:42.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi