the Robot Construction Kit
To show how to create a simple GUI, a small example is used which consists of three elements. A window, a button and a text field. The text field displays the status of the robot and if someone clicks on the button the GUI is sending a command to the robot.
The following code is generating the window, the button and the text field. The underlying library is qtruby. Please see qtruby for more informations about how to use the Qt ruby binding.
require 'vizkit' #loading library window = Qt::Widget.new #create window button = Qt::PushButton.new(window) #create button button.move(10,10) #set pos text_field = Qt::TextEdit.new(window) #create text field text_field.move 10,70 #swret pos window.show #show window #start deployment orocos.run 'my_deployment' do task = Orocos::TaskContext.get 'mytask' task.start #connect an output port to a code block #the output port is read with 8 Hz by default task.mystatus.connect_to do |data,port_name| text_field.setText data.status.to_s #the data object must be returned data end #connect an input port to a qt signal writer = task.my_input.writer button.connect(SIGNAL('clicked()')) do sample = writer.new_sample sample.field1 = "123" writer.write sample end #run qt main loop Vizkit.exec end
In the example above the connection between the text field and the output port of the task is done via a code block which is triggered by a QTimer with a default update frequency of 8 Hz. If it is necessary to retrieve all samples from a port which has a higher update frequency, a buffered connection can be used or the update frequency can be changed.
task.port.connect_to :type=> buffer, :size => 10, :update_frequency => 10 do |data,port_name| data end
In the next example Vizkit is used to display the images taken by a camera. If Vizkit cannot find a specialised widget to visualize a message a tree view widget is used to display all data fields. This mechanism can easily be extended by custom widgets (see this page)
require 'vizkit' Orocos.run 'my_camera' do camera = Orocos::TaskContext.get 'camera' camera.start Vizkit.display camera.frame Vizkit.exec end