ControlP5 Overwriting Screen when writing to the screen with a text("ccc") Command

edited December 2015 in Library Questions

Actually have to two issues. The first is pretty much described in the question. I created a button that writes text to the screen using text("" + q[3]*rad2deg, 280, 360) in the button function as follows:

     public void controlEvent(ControlEvent theEvent) {
     //println(theEvent.getController().getName());

    }

    public void Button1() {
          println("a button event from colorB: ");
            fill(255,0,0); 
            textSize(12);
            text("" + q[0]*rad2deg, 170, 360);
            text("" + q[1]*rad2deg, 170, 380);    
            text("" + q[2]*rad2deg, 170, 400);
            text("" + q[3]*rad2deg, 280, 360);
            text("" + q[4]*rad2deg, 280, 380);
            text("" + q[5]*rad2deg, 280, 40); 

        }

On release of the button the values flashes on the screen and then disappears. Not sure how to fix this issue. I did a web search but nothing. I am using processing 3 with the latest library. I have attached a screen shot of the GUI for reference. The offending fields are t0 through t6. Ultimate intent to have these update as the calculations for robot arm position is calculated. Also tried to this with a ControlP5 textfield and textarea but they don't update until after the last iteration is completed and only shows the last iteration.

Heres the actual link: https://drive.google.com/file/d/0BwzZjH9KYYMDcXBHWkdrdU1yZEk/view?usp=sharing

v/R Mike

Answers

  • edited December 2015

    DISCLAIMER: I dunno ControlP5 so my help here is very limited. 8-X

    • In all Processing versions, the actual canvas drawing happens under the "Animation Thread".
    • And while that process is taking place, canvas shouldn't be concurrently modified!
    • And though in older Processing versions disobeying that rule wouldn't have any serious consequences most of the time, P3 is much more strict about it! :-SS
    • Place println(Thread.currentThread()); inside your Button1() callback function for debugging.
    • If you don't see anything like Thread[Animation Thread,5,main], you can't use any Processing API dealing w/ canvas there. Including your fill(), textSize() & text()! :-\"
    • Rather you should delegate those for draw() callback.
    • Maybe via some boolean variable in order to flag the action.
  • edited December 2015

    Hi GoToLoop.
    Thanks for getting back to me so fast. Did as you suggested but No Joy. The print returned exactly Thread[Animation Thread,5,main]. Thanks for suggestion - just learned something new.

    Mike

  • line 6 gets only called once

    so no use to use text() here (because draw runs 60 times per second and clears the screen)

    so after line 6 set a boolean showText = true;

    now in draw() check if(showText) and if so do the text() you have in line 6 now

  • gotoloop wrote that but too brief for you

  • Answer ✓

    Yea, I hinted about the boolean variable.
    And although it's not about the "Animation Thread" anymore now, there's still the fact that background() erases everything as @Chrisir mentioned! :-\"

  • Hey All,

    @GoToLoop, from your post i did not try the boolean because I assumed the problem laid elsewhere and not in printing text to the screen from the function. However, with that said I moved the text commands to the draw function with the boolean as you and @Chrisir suggested and of course it worked. I also tried one other thing based on @GoToLoop's identification of what happens with Background(). I moved the backgrond(230) to setup and left the text in the button function. It worked as well. However, the text now looks like garbage - tried smooth(8) but did not work. Any ideas on this one.

    thanks for your help.

  • edited December 2015

    If you don't have any background() executed after setup(), things gonna be drawn over & over.
    Even those always drawn at the same place can still get some blur result due to accumulation of color blending and anti-aliasing.

  • You are a wealth of info, I mean it, for understanding the issue. Got this one solved but now I another issue with ControlP5. If you checked the image you will see a Run Script button. Basically this runs a series of commands to execute a Inverser Kinematic calculation and moves the arm then for now just displays the angles on the screen. Tried to write to the screen with the text() but it does not pdate until after the last move. Will post this as a separate issue.

    thanks again.

  • Hello,

    you wrote:

    Tried to write to the screen with the text() but it does not pdate until after the last move.

    It is true: draw() updates / outputs the screen only once at the end of draw().

    This is not a bug though but intentionally.

    println() works throughout during draw() while text() works only at its end.

    A workaround:

    You wrote:

    this runs a series of commands

    if you had the commands in an ArrayList named "commands" you could go through it. Now with a for-loop in draw() you won't see your text till the very end.

    But when you use the fact that draw() in-build runs automatically 60 times per second you could use a var "index" or so for the ArrayList and in draw say index++;

    to slow down just say frameRate(12); or so.

    Best, Chrisir ;-)

  • Will give it try at some point to see if it works. The arraylist is good since at somepoint i am planning on using G-Codes to move the arm. Just seems like a lot of effort to get values displayed.

    Thanks for the help, CyberMerln

Sign In or Register to comment.