====== Software ====== Here you will find information about the software used in the seminar. Specifically: * The [[playerstage|Player/Stage/Gazebo project]] ([[http://playerstage.sourceforge.net/index.php?src=doc|documentation]]). * [[qt|QT]] from Trolltech * New demo is the light sensor trainer. * Obsolete old demo application: [[nahd|NAHD]], or "Not Another Hair Dryer", or "Hair dryer 3000!!" * YARP NEW!! * [[phidget_yarp|Phidget software 11.2011]] * [[python_signals| Python + filters + fft + gnuplot]] * [[python_qt| Python + Qt]] * Examples for I@C winter semester 2010: * {{:fastdev:phidgets.txt|Config file for player server}} * {{:fastdev:phidgets_matplotlib.py|Phidgets and matplotlib}} * {{:fastdev:phidgets_fft.py|Phidgets and FFT}} * {{:fastdev:phidgets_svm.py|Phidgets and SVM}} (tested, it works fine!) Some [[ml|Machine Learning]] information is helpful. ===== Instalation procedure for player in Ubuntu Linux Desktop version 9.04 (Jaunty) ===== * Install Ubuntu in you machine. * Setting up your system for compiling player. * Open a terminal and start typing the following commands: sudo apt-get update sudo apt-get install xstow autoconf pkg-config libtool automake build-essential libusb-dev swig python-dev libjpeg62-dev mkdir local mkdir local/DIR mkdir local/src mkdir local/src/player mkdir local/src/phidgets cd * Setting up environment variables. It is necessary to edit the ".bashrc" file of your home directory. You can use any editor for this. gedit .bashrc You have to add the following lines at the beginning of the file: export PYTHON_VERSION=$(readlink $(which python)) export PATH=${HOME}/local/bin:${PATH} export LD_LIBRARY_PATH=${HOME}/local/lib:${LD_LIBRARY_PATH} export LIBRARY_PATH=${LD_LIBRARY_PATH}:${LIBRARY_PATH} export CPATH=${HOME}/local/include:${CPATH} export LDFLAGS="-L${HOME}/local/lib ${LDFLAGS}" export PKG_CONFIG_PATH=${HOME}/local/lib/pkgconfig export CMAKE_INCLUDE_PATH=${CPATH} export CMAKE_LIBRARY_PATH=${LIBRARY_PATH} export PYTHONPATH=${HOME}/local/src/yarp2/example/swig/build/:${HOME}/local/src/player/pypc-gen:${HOME}/local/lib/python/site-packages:${HOME}/local/lib/${PYTHON_VERSION}/site-packages:${PYTHONPATH} export YARP_DIR=${HOME}/local/src/yarp2/build * After this you have to reload your session. * Download the Phidgets driver from {{fastdev:phidget21_b.tar.gz|here}}. A new version of this library is {{:fastdev:phidget21-10.12.2008.tar.bz2|here}}. Put this file into the /home/youruser/local/src/phidgets directory. cd local/src/phidgets tar -xzf phidget21_b.tar.gz (Change accordingly if you used the newer library) cd phidget21/ autoreconf ./configure --prefix=${HOME}/local/DIR/phidgets make make install cd cd local/DIR xstow phidgets cd * Download {{fastdev:030_phidgets.rules.txt|this}} file to your home directory and copy it to the /etc/udev/rules.d/ directory. (This gives permision to normal users to use the phidgets usb devices) cd sudo cp 030_phidgets.rules.txt /etc/udev/rules.d/030_phidgets.rules sudo /etc/init.d/udev restart * Install package dependencies for playerstage: sudo apt-get install libltdl3-dev libboost-thread-dev libboost-signals-dev libgtk2.0-dev swig python-dev libgeos-dev libgsl0-dev * Download the player source code. There are two possibilities here. One is to download the bleeding edge player subversion version with the following commands (ATTENTION: the svn version of player for 14.10.2009 doesn'f work together with the python bindings, use {{:fastdev:player-svn-10.12.2008.tar.bz2|this one}} instead): cd local/src/player svn co https://playerstage.svn.sourceforge.net/svnroot/playerstage/code/player/trunk player cd * The other way is to download the player code from {{:fastdev:player-svn-29.10.2008.tar.gz|here}} which is known to work. There is even an older version of player that is known to work {{fastdev:player-cvs-120607b.tar.gz|here}}, this version is only recommended under special circunstances. Put the file inside of the /home/youruser/local/src/player directory, and then do the following for decompressing the archive: (NEW!!: You can download a newer version of player that has support for the servo, advanced servo and motor control phidgets {{:fastdev:player-svn-10.12.2008.tar.bz2|here}} cd local/src/player tar -xzf player-svn-29.10.2008.tar.gz (Change accordingly if you used another player compressed file) cd * Once you have the player source code decompress you can proceed to compile it: * Compiling player: cd local/src/player/player mkdir build cd build ccmake ../ * Here you get a menu-like interface for configuring the player compilation procedure * Press "c" to initialize the cmake environment. This searches for all necessary libraries and dependencies in your system, if something is missing you will get an error. * Configure the instalation directory changing the entry "CMAKE_INSTALL_PREFIX" to /home/youruser/local/DIR/player * Then you have to select what you want in your player server. * Please select the following drivers: * ENABLE_DRIVER_ACR120U=ON * ENABLE_DRIVER_PHIDGETACC=ON * ENABLE_DRIVER_PHIDGETIFK=ON * ENABLE_DRIVER_PHIDGETRFID=ON * ENABLE_DRIVER_READLOG=ON * ENABLE_DRIVER_WRITELOG=ON * Then press "c" wait some seconds and press "c" again to configure the new settings * Then press "g" to generate the compilation process recipes. * Execute the following commands: make make install cd cd local/DIR xstow player cd * Player is ready! * Connect the phidget devices to the USB ports. * Let's run the player server: sudo chmod -R o+rw /dev/bus/usb/* player local/src/player/player/config/phidgetIFK.cfg (Player should run without error messages) * Player keeps running in this terminal and it will print any error messages in there if something happens. * Player includes an application for testing. Open another console and execute the following commands: cd local/src/player/player/build/client_libs/libplayerc++/test/ ./playerc++_test --speech:0 The test program execute several checks. If you have connected the Phidgets interface kit you will see the message "Hellow world!" and the some numbers in the LCD screen of the phidget. ===== Setting up QT ===== * Install the appropiate packages cd sudo apt-get install libqt4-dev kdevelop qt4-designer qt4-dev-tools python-qt4-dev pyqt4-dev-tools libtclap-dev * Execute kdevelop kdevelop ==== Setting up your proyect ==== * Go to Proyect->New Proyect.. * Choose C++->QMake->Basic Qt4 Application * In properties. Application name: yourproyectname, Location: /home/your_username/local/src/ * Next * Fill in the Authors information and the type of license you want to use. * next->next->finish * Now you have your initial proyect code. This is only a "hello from QT 4!" program. You can compile it with Build->Build Proyect (The first time you do this you will be asked for running qmake, please do that) * You can run it with Build->Execute Main Program * Now we have to configure the proyect to use some libraries (like libplayer client libraries) * Open the lateral tab called "Qmake Manager" * Select the "src" directory and right click on it. * Select "Subproyect Settings" * Inside the "Configuration" Tab mark the Qt4 libraries: GUI and QtAssistant. If you need something else just mark that also. * Inside the "Includes" Tab add the directories "${HOME}/local/include/player-2.2/" and "${HOME}/local/include/" * Inside the "Libraries" Tab add the external library dir "${HOME}/local/lib" and the following external libraries: "-lplayerc++" "-lplayererror" * Then the subproyect settings are ready. You can push the "OK" button to leave this window. ==== The skeleton phidget program ==== Now we are going to put into work the code from the workshop. * Copy {{fastdev:skeleton.tar.gz|this}} file to the src directory inside of your kdevelop proyect directory. Then execute in a terminal inside of the "src" directory of the kdevelop proyect directory ("local/src/proyect_name/src)the following command: tar -xzf skeleton.tar.gz * Add the main.h header file to the proyect. In the QMake Manager right click "HEADERS" then select "add existing files". Then open "main.h". * Add the "gui.ui" designer file to the proyect. In the QMake Manager right click "FORMS" then select "add existing files". Then open "gui.ui" * Now you can compile your proyect again. (Press F8) * Start the player server. (look above) * Start the Qt4 application. Connect a slider resistor to the 0 analog input of the phidgetIFK. It should print "**Test* * X.XXV" where X.XX is the voltage measured by the phidgetIFK from the slider. Also you should see the slider progress bar in the GUI changing according to the position of the slider. ==== Python applications ==== If you want to run Python clients you first need to get special bindings for player, the included python bindings for player are not recommended. Before starting this section, please update your ".bashrc" file with the current environmental variables described at the beggining of this page and restart your session. * To get the python bindings install the packages "git-core", "python-ply" and "curl" and execute the following: cd local/src/player git clone http://www9.in.tum.de/~kleinehe/pypc-gen.git export IDIR=/home/user/local/src/player/player cd pypc-gen cat kludge.h $IDIR/libplayercore/player.h $IDIR/build/libplayercore/player_interfaces.h $IDIR/client_libs/libplayerc/playerc.h | ./pypc-gen > pyplayerc.py * Test: Install the package "ipython". ipython is an "improved" python interpreted. Then start ipython. apt-get install ipython ipython * Then you get the ipython command line. You can start putting commands. Let's try to just connect to a player server. import pyplayerc as p client=p.Client(None, "localhost", 6665) client.connect() client.set_replace_rule(-1,-1,-1,-1,True) client.datamode(p.PLAYERC_DATAMODE_PULL) * Let's try to read data from a analog input from the phidgets aio=p.Aio(client,0) aio.subscribe(p.PLAYERC_OPEN_MODE) client.read() aio.voltages_count aio.voltages * Every time that you want an updated data from the phidget you have to do a client.read() command before you get the new data. * aio.voltages_count and aio.voltages contain the number of voltage inputs and the voltage values from those inputs. * For closing the program nicely aio.unsubscribe() del aio client.disconnect() * Python is very nice for prototyping, is similar to Matlab in the command line but you get access to real hardware much easier * There are QT bindings for python. ==== Data collection phidget program for Weka ==== * Copy {{fastdev:skeleton_data_collection.tar.gz|this}} file to the src directory inside of your kdevelop proyect directory. Then execute in a terminal inside of the "src" directory of the kdevelop proyect directory ("local/src/proyect_name/src)the following command: tar -xzf skeleton_data_collection.tar.gz This will overwrite the original skeleton. You have to recompile. * When you have your training data files ready according to Weka specifications. You can run several testes to see the behavior of each of them. * Install weka. Look in there webpage. Weka may be in ubuntu already. You need a java runtime environment. * Execute weka: java -jar weka.jar * Go to Application->Explorer * Open File. Select your data file. * Go to Classify tab. Choose a classifier and then press start. You should look for the correctly classified Instances inside of the Stratified cross-validation. Than value should be a good starting point to evaluate each learning algorithm. ==== Applying the learning algorithm inside of your program ==== * Find a good usefull library that implements that specific algorithm. * Maybe you could run in the necessity of changing from one programming language to another for implementation. * Or you can try to implement one learning algorithm (if there are no libraries for it). Some times they are not difficult to implement. {{:fastdev:testann.tar.gz|Take a look in this code}} You need to install a package called libfann1-dev ==== YARP ==== === Instalation === sudo apt-get install libace-dev libcv-dev libavdevice-dev ffmpeg cd cd local/src svn co https://yarp0.svn.sourceforge.net/svnroot/yarp0/trunk/yarp2 cd yarp2 mkdir build cd build ccmake ../ * Press "c" * Change the install prefix to /home/user/local/DIR/yarp2 * Press "c" * Select the yarpmod_ffmpeg_graber and opencv_grabber (ON) * Press "c" twice and then "g" make make install cd cd local/DIR xstow yarp2 * For the python bindings: cd locar/src/yarp2 cd example/swig mkdir build cd build ccmake ../ * Press "c" * If you get an error related to YARP_DIR, fix the entry for this value to /home/user/local/src/yarp2/build and try "c" again * Select the bindings for python and press "c" twice * Press "g" make cp _libpyyarp.so _yarp.so === Example Summer === * We use python for this example * Open a console and run "yarp server". Leave this console running * Type "ipython" in another console, then in the ipython interpreter, type the following: import yarp as y y.Network.init() input=y.BufferedPortBottle() output=y.BufferedPortBottle() input.open("/summer/in") output.open("/summer/out") While True: inputbottle=input.read(False) if inputbottle: outputnumber=inputbottle.get(0).asDouble()+inputbottle.get(1).asDouble() outputbottle=output.prepare() outputbottle.clear() outputbottle.addDouble(outputnumber) else: y.Time.delay(0.001) * In this moment the python application is in an infinite loop waiting for data in the input port * Start two extra consoles * In the first new console execute: "yarp write ... /summer/in" * In the second new console execute: "yarp read ... /summer/out" * New in the first new console you can type "10 10" and you will see the result in the second new console. * Basically the summer module is processing the data that is writen in the /summer/in port and the results are published in the /summer/out * With this you can easily make small simple modules and test them without having the whole system in one single file. Also allows to segment work between colleges and to separate processing in different computers. * You can interface this system with player. You comunicate with the hardware using player and between your own processing modules using YARP.