0

I have implemented genetic algorithm (Java) that works on Webots simulated e-puck (PRO 7.0.3, OS X). What I want to do now is to display a graph that would show how fitness score is changing over time.

I have been trying to use JFreeChart, but unfortunately displaying a new frame from inside Webots simulation is not allowed.

I have been looking into using Display node to generate graph manually but this is just very tedious and limited.

Do you know of any other ways to do that? Or maybe of ways to force Webots to allow JFrames?

Anna Pawlicka
  • 757
  • 7
  • 22
  • You may wanna take a look at this sample in your Webots release : _WEBOTS_HOME/projects/samples/curriculum/worlds/advanced_genetic_algorithm_ .It generates a graph using Display node. – ye9ane Mar 18 '13 at 11:45

1 Answers1

1

You don't need to use any java library for displaying the graph. Simply add a Display node to your world:

Display {
  rotation 1 0 0 3.14
  width 128
  height 128
  windowPosition 0 1
}

and initialize it in your controller :

 display = wb_robot_get_device("display");
 width = wb_display_get_width(display);
 height = wb_display_get_height(display);
 wb_display_fill_rectangle(display,0,0,width,height);
 wb_display_set_color(display,LIGHT_GREY);

This will create a square panel in the bottom left of your scene that is capable of showing 2D contents during the simulation. You may find some usage examples of display in projects included in your Webots release.

After initialization ,you can simply add pixels,lines,polygons,text and ... to the display panel.Visit the link I mentioned earlier for Java API.
FabienRohrer
  • 1,794
  • 2
  • 15
  • 26
ye9ane
  • 1,959
  • 3
  • 18
  • 31