Docstoc

Robotics _ Automation

Document Sample
Robotics _ Automation Powered By Docstoc
					The University of Western Australia
Dept. of Electrical & Electronic & Computer Engineering
Kingdom / Bräunl




          Robotics & Automation
                                 ENGT4314

                                   Tutorial 2

What direction will the omni robot drive with the following wheel configurations?
Which direction will the force be applied at each wheel?




What are the advantages of simulation over real experimentation?
What are the disadvantages of simulations over real experimentation?


What are the advantages of legged robots over wheeled robots?
What are the disadvantages of legged robots over wheeled robots?
FLTK

           “FLTK (pronounced "fulltick") is a cross-platform C++ GUI toolkit for UNIX /Linux
                                                                                     ®
                                                                                       (X11), Microsoft
                                                                                               ®          ®



           Windows , and MacOS X. FLTK provides modern GUI functionality without the bloat and supports
                    ®             ®



           3D graphics via OpenGL ...” (http://www.fltk.org/index.php, 11-08-08)
                                      ®




We will use FLTK to create a Windows GUI in one of the upcoming labs, in addition to OpenGL, which will
be covered in a following tutorial.


Installing Dev-C++
           Open devcpp-4.9.9.2_setup.exe and install, available from the tutorial zip file or from
the net.


Installing FLTK 1.1.4 DevPack
           Once Dev-C++ is installed you can open fltk-1.1.7.cm.devpak




Now we are ready to use FLTK.
Creating a FLTK project in Dev-C++:

Open Dev-C++ and open the create new project dialogue, click on the GUI tab.




Select FLTK and enter a project name, and click OK.

A simple Hello World example project will be created where you can replace the contents of
the main function with your own code.


The Hello World Example:
       #include <FL/Fl.H>
       #include <FL/Fl_Window.H>
       #include <FL/Fl_Box.H>

       int main (int argc, char ** argv)
       {
         Fl_Window *window;
         Fl_Box *box;

           window = new Fl_Window (300, 180);
           box = new Fl_Box (20, 40, 260, 100, "Hello World!");

           box->box (FL_UP_BOX);
           box->labelsize (36);
           box->labelfont (FL_BOLD+FL_ITALIC);
           box->labeltype (FL_SHADOW_LABEL);
           window->end ();
           window->show (argc, argv);

           return(Fl::run());
       }
Some common Widgets:
Fl_Window
Creates an actual windows in which can contain other widgets (e.g. the box widget above).

Constructors:
Fl_Window::Fl_Window(int w, int h, const char *title = 0)
Fl_Window::Fl_Window(int x, int y, int w, int h, const char *title = 0)

Parameters:
      x,y,w,h : horizontal position (pixels), vertical position, width and height respectively.
      *title : pointer to a null terminated constant string containing the title.

Common Methods:
     show() : Displays the window and bring it to the front.
     hide() : Hides the window from the display


Buttons:
There are several button types available in fltk:
       Fl_Button - A standard push button.
       Fl_Check_Button - A button with a check box.
       Fl_Light_Button - A push button with a light.
       Fl_Repeat_Button - A push button that repeats when held.
       Fl_Return_Button - A push button that is activated by the Enter key.
       Fl_Round_Button - A button with a radio circle.




      Figure: Button types in fltk (http://www.fltk.org/doc-1.1/common.html , 11-8-08)

Each button type has the same constructor:
         Fl_xx_Button(x, y, width, height, "label");

The behaviour of the button can be assigned using the type method.

       button->type(FL_NORMAL_BUTTON);
       lbutton->type(FL_TOGGLE_BUTTON);
       rbutton->type(FL_RADIO_BUTTON);

To determine the state of a radio button or a toggle button use the value() method. Use
set() and clear() to set the value of toggle buttons and setonly() to set a radio button. See
the fltk documentation for more information.
Text:
Below are some of the text widgets.
      Fl_Input - A one-line text input field.
      Fl_Output - A one-line text output field.
      Fl_Multiline_Input - A multi-line text input field.
      Fl_Multiline_Output - A multi-line text output field.

Output widgets allow a user to select text and copy but the field is read-only to the user and
cannot be changed. Obviously this restriction does not apply to input fields.

Use the following constructor:
       Fl_Input *input = new Fl_Input(x, y, width, height, "label");

And use value to set
      input->value("Hello World...");


Valuators:
Provide a visual way of receiving numerical input from the user, including sliders, and round
knobs, etc.

        Fl_Counter - A widget with arrow buttons that shows the current value.
        Fl_Dial - A round knob.
        Fl_Roller - An SGI-like dolly widget.
        Fl_Scrollbar - A standard scrollbar widget.
        Fl_Slider - A scrollbar with a knob.
        Fl_Value_Slider - A slider that shows the current value.
                                  Figure: Different Valuators
Set the range of the widget using minium(double number) and maximum(double number) and
get/set the value of the widget by using value().



Widget Events by using Callbacks:
You can capture events by using a callback, call back is simply passing a function which
FLTK will call when an event occurs for example If a user clicks on a button. By default a
callback will occur when the value of a widget changes, however you can change this
behaviors by using the when() method of the widget for more information see the FLTK
documentation.

       void xyz_callback(Fl_Widget *w, void *data) {
       ...
       }

       int xyz_data;

       button->callback(xyz_callback, &xyz_data);

The callback function should always have the same arguments Fl_Widget *w, void *data.
The first parameter is a pointer to the widget, and the second is a pointer to optional data
which you can specify when you initialize the callback.

Another example of using callbacks from last year’s tutorial.
       #include <stdio.h>
       #include <stdlib.h>
       #include <FL/Fl.H>
       #include <FL/Fl_Window.H>
       #include <FL/Fl_Button.H>

       void button_callback(Fl_Widget *w, void *data) {
                printf("button pressed\n");
       }

       int main(int argc, char **argv) {
         Fl_Window *window = new Fl_Window(400,320,argv[0]);
         Fl_Button * b = new Fl_Button(20,270,100,30,"Button");
         b->callback(button_callback);
         window->show(argc, argv);
         return Fl::run();
       }




Problem 1
Create the following GUI using FLTK, use Fl_Window, Fl_Button, Fl_Output, each widget
should be 50x50 pixels, and the window is 300x180. Note that the reference point for FLTK
(ie (0,0) ) is in the top left corner.




Problem 2
Using the gui created in problem 1, add a single call back function so that each button will
change the value of the output widget to match the text on the button. Hint use the label and
value methods.
Solution
     #include <FL/Fl.H>
     #include <FL/Fl_Window.H>
     #include <FL/Fl_Button.H>
     #include <FL/Fl_Input.H>
     #include <FL/Fl_Output.H>
      Fl_Window *window;
      Fl_Button *buttonUp;
      Fl_Button *buttonRight;
      Fl_Button *buttonDown;
      Fl_Button *buttonLeft;
      Fl_Output *out;

     void buttonCallback(Fl_Widget *w, void *data) {
        out->value(w->label());
     }


     int main (int argc, char ** argv)
     {

         window = new Fl_Window (300, 180,"Buttons");
         buttonUp = new Fl_Button (125,10,50,50,"UP");
         buttonRight = new Fl_Button (175,60,50,50,"R");
         buttonLeft = new Fl_Button (75,60,50,50,"L");
         buttonDown = new Fl_Button (125,110,50,50,"Dwn");
         out = new Fl_Output(125, 60, 50, 50);

         buttonUp->callback(buttonCallback,(void*) 0);
         buttonRight->callback(buttonCallback,(void*) 0);
         buttonLeft->callback(buttonCallback,(void*) 0);
         buttonDown->callback(buttonCallback,(void*) 0);
         window->end ();
         window->show (argc, argv);

         return(Fl::run());
     }