System.out.println output jumbled

Hi,
We are trying to print out info to console using System.out.println and see the output look jumbled. We are using command based template and want to have the robot run image funcs and output particle reports when a button on joystick is pressed. I found a post that mentioned outputting too fast will cause problems so we added some delays(maybe not enough?) but still see issues. The thread is this one, posts 10 & 11:
http://www.chiefdelphi.com/forums/showthread.php?t=89740&highlight=crio+console+output

Anyone have suggestions/ideas about what to do to make printing debug info work?

The code that prints stuff while running in a command looks like this:

   private void printParticleReports(String str, BinaryImage img) {
        try {
            System.out.println("* " + str + "*********************************************");
            ParticleAnalysisReport] reports =
                    img.getOrderedParticleAnalysisReports();
            for (int i = 0; i < reports.length; i++) {
                ParticleAnalysisReport r = reports*;
                System.out.println("Particle(" + (i + 1) + "/" + reports.length
                        + ")
" + r.toString());
                System.out.println("");
                Timer.delay(.2);
            }
            System.out.println(img.getNumberParticles()
                    + "  " + Timer.getFPGATimestamp());
            System.out.println("**********************************************");
            Timer.delay(.2);
        } catch (NIVisionException ex) {
            ex.printStackTrace();
        }
    }

One example of jumbled output looks like this:

-> arg 1
[cRIO]
[cRIO] * bigobj*********************************************
[cRIO] 031250000000000444 , 0.0 )
[cRIO] Area : 301746.0
[cRIO] percent : 98.224609375
[cRIO] Bounding Rect : ( 0 , 0 ) 640480
[cRIO] Quality : 98.33023755987878
[cRIO]
[cRIO]
[cRIO] Particle(1/2)
[cRIO] Particle Report:
[cRIO] Image Height : 480
[cRIO] Image Width : 640
[cRIO] Center of mass : ( 319 , 240 )
[cRIO] normalized : ( -0.0Particle(2/2)
[cRIO] Particle Report:
[cRIO] Image Height : 480
[cRIO] Image Width : 640
[cRIO] Center of mass : ( 323 , 31 )
[cRIO] normalized : ( 0.009374999999999911 , -0.8708333333333333 )
[cRIO] Area : 272.0
[cRIO] percent : 0.08854166666666666
[cRIO] Bounding Rect : ( 294 , 29 ) 55
7
[cRIO] Quality : 95.77464788732394
[cRIO]
[cRIO]
[cRIO] 2 146.245212
[cRIO] **********************************************
[cRIO]
[cRIO] 652 )
[cRIO] Area : 307200.0
[cRIO] percent : 100.0
[cRIO] Bounding Rect : ( 0 , 0 ) 640480
[cRIO] Quality : 100.0
[cRIO]
[cRIO]
[cRIO] Particle(1/1)
[cRIO] Particle Report:
[cRIO] Image Height : 480
[cRIO] Image Width : 640
[cRIO] Center of mass : ( 319 , 239 )
[cRIO] normalized : ( -0.0031250000000000444 , -0.004166666666666vexhull
********************************************
[cRIO]
[cRIO] * con1 146.837495
[cRIO] **********************************************
[cRIO]
[cRIO]
[cRIO] * filtered*********************************************
[cRIO] 0 147.054589
[cRIO] **********************************************
[cRIO]

Thanks.*

System.out.println is never advisable to use on the cRIO as the method gets called ridiculously fast and that’s why the output gets jumbled.

I suggest you use the new smart dashboard for any output.
Check out WPILIBJ docs for more info:
http://www.wbrobotics.com/javadoc/edu/wpi/first/wpilibj/smartdashboard/SmartDashboard.html

Basically import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard in whatever file you’re outputting from and then instead of System.out.println, run SmartDashboard.putString(“key”, “value”) and replace String with whatever datatype you’re outputting.

We found last year that the newer router has a habit of reversing the order of packets. When it receives several packets “at once”, it sends the most recent one first. It may be assuming that all UDP traffic is audio/video, and the right thing to do is to always send to most recent data.

That was really fun when another part of the system managed to send break up all system output into 1 character packets - all output came out in reversed order!

In any case, now that output is buffered into larger chunks, it’s still possible that if several packets hit the router at the same time it may reverse their order.

If you have time, look into the difference between TCP and UDP. System output (e.g. the “netconsole”) uses UDP to broadcast to all interested clients on the local network.

Oh, and hi Maciej!

I didn’t even look to see who posted the question :]

Thanks for the suggestions and ‘Hi Derek’ :).

Printing to stdout is a well known debug technique :slight_smile: that works in any language and doesn’t require any extra tools. I’d like to stick with it because it is simple. I found if I added more delays and printed smaller messages I could cut down on the jumbling. We will just have to be a bit more careful how we print debug data.

Using SmartDash (or any other dashboard) can be a little cumbersome. I cannot get text to break/wrap into multiple lines. So you lose newlines and get one really long line. Is there a way to make text wrap in text boxes?

Maybe you could write a custom widget to display text but its not something anyone on my team has time (or interest?) in doing right now. We might look into the tcp/udp thing too after build season but it’s not one of those glamorous things that the students on my team want to work on. Everyone wants to program the shiny new sensor/thingy :).

-Maciej