14 January 2012

Unity3d - Removing Render Texture alpha

 If you want to apply the Render Texture to a GUITexture object so it will be sized to the screen with other GUITexture objects. But GUITextures don't have indpendent materials or shaders so you won't be able to remove the alpha which is added to the render texture. Just setting the color of the GUITexture and the Render Texture camera to white and 100% still leaves the Render Texture transparent. So you can remove the alpha values from that render texture using the following script.




var alpha = 1.0;
private var mat : Material;

function Start ()
{
    mat = new Material(
        "Shader \"Hidden/Clear Alpha\" {" +
        "Properties { _Alpha(\"Alpha\", Float)=1.0 } " +
        "SubShader {" +
        "    Pass {" +
        "        ZTest Always Cull Off ZWrite Off" +
        "        ColorMask A" +
        "        SetTexture [_Dummy] {" +
        "            constantColor(0,0,0,[_Alpha]) combine constant }" +
        "    }" +
        "}" +
        "}"
    );
}

function OnPostRender()
{
    GL.PushMatrix();
    GL.LoadOrtho();
    mat.SetFloat( "_Alpha", alpha );
    mat.SetPass(0);
    GL.Begin( GL.QUADS );
    GL.Vertex3( 0, 0, 0.1 );
    GL.Vertex3( 1, 0, 0.1 );
    GL.Vertex3( 1, 1, 0.1 );
    GL.Vertex3( 0, 1, 0.1 );
    GL.End();
    GL.PopMatrix();

Apply this script to camera of whose render texture is to be taken.

Installing Kinect on Windows(OpenNI) with Unity Wrapper

Real application of Kinect starts when you integrate it with any gaming engine. For a head start, OpenNI provides a wrapper in C# to be used in Unity3D gaming engine. They have also given a sample code for Ogre. You can start working on them after few simple steps of installation.

The fastest way to get started with this is to install the Zigfu bundle and Wrapper for OpenNI in Unity.
1. Download and install the latest zigfu development bundle from http://www.zigfu.com/devtools.html. This bundle install OpenNI, NITE and sensor drivers for kinect.
2. Now download the Zigfu Unity3D wrapper and extract it in your project. It contains sample scenes for help.
Now you can start developing your own motion sensing applications and games.

If you want to go with the latest OpenNI drivers and wrappers, you'll have to install them individually.
1. Download OpenNI module from http://75.98.78.94/Downloads/OpenNIModules.aspx. Select "OpenNI Binaries" in the first drop down box, then select the stable/unstable release and then download the specific module according to your system. If you want to work with PCL also, download this module from http://pointclouds.org/downloads/windows.html in the OpenNI column.
2. Now select the "OpenNI Compliant Middleware Binaries"  and download the middleware binary for your system.
3. Select the "OpenNI Compliant Hardware Binaries" and download stable/unstable release according to your system. If you want to work with PCL, you'll have to download it separately from http://pointclouds.org/downloads/windows.html under the sensor column.
4. Install all these downloaded binaries in the order in which they were downloaded.
5. Now you'll have to download the Unity3d wrapper from https://github.com/OpenNI/UnityWrapper according to your version of binaries.
6. Extract this and include in your project to get started with using kinect for application development.
7. Or you can download the Sinbad sample in Ogre from https://github.com/OpenNI/SampleAppSinbad to get started in Ogre gaming engine.

12 January 2012

Unity3d - Displaying output of one camera as background of other camera

Unity is an integrated authoring tool for creating 3D video games or other interactive content such as architectural visualizations or real-time 3D animations. Unity's development environment runs on Microsoft Windows and Mac OS X, and the games it produces can be run on Windows, Mac, Xbox 360, PlayStation 3, Wii, iPad, iPhone, as well as the Android platform. It can also produce browser games that use the Unity web player plugin, supported on mac and Windows but not Linux. The web player is also used for deployment as Mac widgets.

I was working with a problem where I needed to display the output of one camera as the background image of the other camera. The concepts used in this method are applicable at lot of places during the game development like showing the mirror effect in car races or the score board. 

I would suggest to go through the following links before using this method. The following links will give a rough idea about the Camera, GUI Texture, Render Texture and Layers in Unity.

Setup your scene with the Main Camera showing your game objects. After this follow these steps to create the background using a different Camera  -

1. Create a new camera (GameObject->Create Other-> Camera), and name it "Background Camera".

2. Create a new GUI Texture (GameObject->Create Other->GUI Texture), and name it "Background Image".

3. Click the "Layer" dropdown menu in the Background Image's inspector pane, and select "Add Layer".

4. In the next free "User Layer" slot, create a new layer name called "Background Image". This will be directly under the layer named "Terrain" if you haven't yet added any others.

5. Select your Background Image in the hierarchy, and give it the desired texture, and set the x, y, width and height under "Pixel Inset" so that it fills the screen appropriately.

6. Near the top of the inspector window, Use the layer dropdown menu to assign your "Background Image" layer that you defined earlier to this game object.

7. Now select your Background Camera in the hierarchy, and adjust these settings in the inspector:
   * Un-check Flare Layer and Audio Listener (but leave GUILayer enabled)
   * Set Clear Flags to Solid Color
   * Set Depth to -1
   * Set Culling Mask, first to "Nothing", and then to "Background Image"

8. Now Select your other (Main) camera and in the inspector:
   * Set its Clear Flags to "Depth Only"
   * Click its culling mask setting, and un-check "Background Image". This should result in the culling mask displaying as "Mixed..."

9. Now your system should display the Background GUI Texture as the background of the main camera. Since, this GUI Texture is the background for the present camera, you can change it dynamically from the script to display any other video texture or Render Texture from other camera. Render Texture is  used to render the camera view to a texture which can be displayed somewhere else.

10. Create a new Render Texture by Assets->Create->Render Texture. Give a proper name to this render texture and edit the properties according to your needs.

11. Now setup the scene and a camera whose output you want to display as the background in the Main Camera.

12. Go to the 'Target Texture'  option of this new camera and assign the render texture you created to it.

13. Now make a script which assigns this render texture as GUI Texture to the Background Image you created earlier. 

10 December 2011

Weblinks for downloading 3D models for Games

While making a game or working with any game engine, you'll need 3D models for your project. I have listed some of the websites which I came across while searching for 3D models across the web. If you find anything new or interesting to be shared, please list them in your comments. Though some of them are not free, I found them pretty useful.
1. http://e2-productions.com/repository/modules/PDdownloads/
2. http://www.katorlegaz.com/3d_models/index.php
3. http://www.sharecg.com/b/6/Textures?PSID=c72202065a0071c54d10bc27e4798f32
4. http://opengameart.org/
5. http://www.dexsoft-games.com/
6. http://www.frogames.net/
7. http://archive3d.net/
8. http://www.turbosquid.com/
9. http://www.3dlinks.com/
10. http://www.mega-tex.nl/
11. http://3d-resources.com/

26 November 2011

OpenCL in Windows


OpenCL support is provided by the Graphics Driver you are using. Most Nvidia drivers these days come with OpenCL support and they even provide their SDKs for OpenCL. For Nvidia, you'll have to follow the following to get the OpenCL working  -

1. Go to Nvidia OpenCL site(http://developer.nvidia.com/opencl) and check for their latest drivers with OpenCL support and also other tools you want to install.

2. Download the latest GPU Computing SDK from the Nvidia site and install them.

3. This is the link for code samples related to OpenCL - http://developer.download.nvidia.com/compute/opencl/sdk/website/samples.html. Though these samples also come along with GPU Computing SDK. You may see an icon on your desktop named NVIDIA GPU Computing SDK Browser. You can open this browser and go to OpenCL tab to see the examples working. The source and project files for these examples are presesnt in C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\ folder. The required library files and header may be found along with the samples or in the C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\shared\ folder.


If you're not sure if you Graphics card supports OpenCL or whether it is enabled, you can download a software called GPU Caps Viewer from here. This shows you all the features and information of your graphics card with a feature to enable or disable the OpenCL as well as CUDA support. It also contains some binaries so that you may test them. It looks something like this -




If your graphics card doesn't support OpenCL, then you have the option of installing Intel's OpenCL SDKs which uses CPU for the task. The installation steps for Inter OpenCL SDK are -
1. Install the pre-requisites for the SDK ie.
   i) Microsoft Windows Installer 3.1 or more
  ii) Microsoft Visual C++ 2008 run-time libraries or more
 iii) Java SE Runtime Environment 6 Update 27 or more
 The installer prompts you if anything is missing. You must have the administrative priviledge while installing the SDK.

2. Download the appropriate setup for your machine from Intel's site.

3. Install the setup. Mostly the SDK is installed in C:\Program Files (x86)\Intel\OpenCL SDK\ on a 64 bit system. The sample which come along with the SDK are installed in this folder - C:\Users\Public\Documents\Intel\OpenCL SDK\1.5\samples\

Now you are ready to start programming using OpenCL. Some website links are given below which might be of help.
1. The OpenCL official page on the Khronos* website. All information about latest versions of OpenCL  - http://www.khronos.org/opencl/
2. Information on the Khronos* conformance test process - http://www.khronos.org/adopters/
3. Intel OpenCL SDK Product page - http://software.intel.com/en-us/articles/intel-opencl-sdk/
4. Intel OpenCL SDK Download page  - http://software.intel.com/en-us/articles/download-intel-opencl-sdk/
5. Intel OpenCL SDK support forum - http://software.intel.com/en-us/forums/intel-opencl-sdk/
6. NVIDIA OpenCL developer zone - http://developer.nvidia.com/opencl
7. NVIDIA OpenCL developer forum - http://forums.nvidia.com/index.php?showforum=134

13 October 2011

Installing PCL on Ubuntu 11.04


Add the PCL to the repository
sudo add-apt-repository ppa:v-launchpad-jochen-sprickerhof-de/pcl
Update repository
sudo apt-get update
Install repository
sudo apt-get install libpcl-all
It would be better you add ROS to your repository before installing PCL. This add some of the optional dependencies of PCL which are there in ROS. Moreover OpenNI is also installed automatically from ROS repo which relieves you from the burden ofconnecting kinect by installing all the dependencies on by one.
ROS Diamondback repository - 
$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu natty main" > /etc/apt/sources.list.d/ros-latest.list' 

$ wget http://packages.ros.org/ros.key -O - | sudo apt-key add -

$ sudo apt-get update

10 October 2011

Installing OGRE on Ubuntu 11.04

Download following files before installation -
1. Ogre SDK
2. Object Oriented Input System(OIS) Source
3. Perl Compatible Regular Expression (PCRE)
4. Install nvdia-cg-toolkit from synaptic or download from here.
5. Type this command to install other dependencies -
$ sudo apt-get install build-essential autoconf libtool libdevil-dev libfreeimage-dev libfreetype6-dev libglew1.5-dev libxaw7-dev libxrandr-dev libxt-dev libxxf86vm-dev libzzip-dev

Step 1:  Building OIS
   Extract OIS to any folder and type following commands from terminal to build.
$ ./bootstrap
$ ./configure
$ make
$ sudo make install

Step 2: Building Nvidia CG toolkit if you have downloaded the source.
 Extract into a folder and type the following commands -
$ ./configure
$ make -j4
This 4 can be any number which specifies the number of threads you want to use for the make process.
$ sudo make install
$ sudo ldconfig

Step 3: Installing PCRE
Extract the files and type the following command from the terminal -
$ ./configure --enable-utf8
$ make -j4
$ sudo make install

Make link to the shared object in /usr/lib folder by typing following command.
$ sudo ln -s /lib/x86_64-linux-gnu/libpcre.so.3 /usr/lib/libpcre.so.0
Now we are ready to install Ogre.

Step 4: Installing OGRE SDK
Extract the ogre files and type the following commands from the terminal.
$ cmake-gui .
This will open the cmake gui tool. Click on the configure button. Now all the required libraries will be configured and shown. Tick the build samples and build doc check boxes. Also check if all the required libraries are present. Now click on generate button. After generating you may close this gui.
Type following commands in terminal after exiting the gui.
$ make -j4
$ sudo make install

Step 5: Installing CEGUI
Extract the files in some folder and type the following lines from the terminal.
$ ./configure
$ make -j4
$ sudo make install

Now open .bashrc file and the following line at the end of it.
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH



Reference links -
1. http://ubuntuforums.org/showthread.php?t=1148570
2. http://www.ogre3d.org/tikiwiki/Building+Ogre+With+CMake

6 October 2011

Important links required to make own linux distibution

1. https://help.ubuntu.com/community/LiveCDCustomization - Ubuntu Live CD Customization site
2. https://help.ubuntu.com/community/UbuntuBootupHowto - Ubuntu Boot Up Changing Site
3. http://ubuntuclub.com/files/04-Techniques.txt - Some customization techniques
4. http://ubuntuforums.org/showthread.php?t=1073838 - Remastersys steps to customize own distribution
5. http://www.ubuntugeek.com/creating-custom-ubuntu-live-cd-with-remastersys.html - Using Remastersys
6. https://help.ubuntu.com/community/Grub2 - Grub2 customization instructions
7. http://www.remastersys.com/info.html - Remastersys website for information
8. https://help.ubuntu.com/community/Kernel/Compile - Compiling kernel for greater customization
9. http://theindexer.wordpress.com/2011/04/03/to-do-list-after-installing-ubuntu-11-04-aka-natty-narwhal/ - Packages and repositories for newly installed systems
10. http://blog.sarathonline.com/2009/03/how-to-make-local-offline-repository-in.html - Making a local repository
11. http://members.iinet.net/~herman546/p20/GRUB2%20Splashimages.html - Changing grub splash screen
12. http://ubuntuguide.net/an-effective-way-changing-ubuntu-11-04-login-screen-appearance - Changing login window appearance
13. http://www.unixmen.com/linux-distributions/4/265-great-themes-for-ubuntu-904-jaunty-jackalope - Some theme installations for ubuntu
14. http://ubuntuguide.net/an-easy-way-to-addchange-grub2-background-image-in-ubuntu-11-04 - Changing grub background splash image.
15. http://www.youtube.com/watch?v=_6j05f9SccY - Improving boot time of ubuntu.
16. http://brej.org/blog/?p=158 - Creating plymouth splash screen

4 October 2011

Installing latest version of remastersys on Ubuntu 11.10

 Remastersys is a tool that can be used to do 2 things with an existing Debian,  Ubuntu or derivative installation.
  1. It can make a full system backup including personal data to a live cd or dvd that you can use anywhere and install.
  2. It can make a distributable copy you can share with friends.  This will not have any of your personal user data in it.

I haven't found any specific method to install remastersys properly. Everytime, some works and some don't. So I try different methods in this order and everytime atleast one of them works. Sounds funny but works for me.

Method 1
1. Go to this link  http://www.remastersys.com/ubuntu/remastersys.gpg.key and save this key on your disk.
2. In synaptic, go to Settings/Repositories; select "Authentication" tab and "Import Key File" just downloaded.
3. Still in synaptic, go to "Other Software" tab and click "Add", then enter the apt line and replace oneiric with either lucid, maverick, or natty to match your Ubuntu version:
    deb http://www.remastersys.com/ubuntu oneiric main
4. Leave the repositories tab and "Reload".
5. Search for "remastersys" and select for install.  Edit/Apply Marked Changes.

This might give error some times.

Method 2
1. Type the following key in the terminal to add the key of the repository to the synaptic.
    sudo wget -O - http://www.remastersys.com/ubuntu/remastersys.gpg.key | apt-key add -
2. Add the following line that corresponds to your version of Ubuntu to your /etc/apt/sources.list

#Remastersys Lucid
deb http://www.remastersys.com/ubuntu lucid main

#Remastersys Maverick

deb http://www.remastersys.com/ubuntu maverick main

#Remastersys Natty

deb http://www.remastersys.com/ubuntu natty main

#Remastersys Oneiric

deb http://www.remastersys.com/ubuntu oneiric main

3. Type the following line in the terminal
    sudo apt-get update
4. Now open the synaptic package manager and search for remastersys and install it.

If the above two methods give error. Remove the packages from your sources.list file.

Method 3
1. Go to this link http://www.remastersys.com/repository/ and download the appropriate version of remastersys. For ubuntu, it will be in karmic folder or similar other ubuntu version.
2. Double click on it so that it may open in software center directly. Now click on install.


Reference:
1. http://www.remastersys.com/

2 October 2011

Setting up Ogre Project in Visual Studio 2010

Prerequisites - 

  • Visual Studio 2010 must be installed.
  • Ogre SDK 1.7 or greater must be installed. Use this link for installation details.
Steps to setup project - 


1. Set Environment variable - 
   Run setx OGRE_HOME path_to_ogre_sdk in a command console (cmd.exe).
   Alternatively create a batch file to set the variable. 
   Filename: OgreHome.bat
   Contents: setx OGRE_HOME %CD%
                  pause
   Location: Ogre Extracted folder ( Eg:-C:\OgreSDK_vc10_v1-7-3)

2. Create a new Visual Studio Project
   Make sure the windows application is selected and empty project is checked.
  

I kept the name as OgreProject.

2. Now download the sample ogre files to be included in the project - TutorialsFramework.zip.
   After downloading this zip file, extract the file into the project folder.
   Add those files to the project by selecting Add->Existing Item...

3. Change the project configuration.
   
Switch to All Configurations:

Under General Properties, set the Character Set to Multi-Byte Character Set


Under Debuggin Configuration Properties, set the following values:
Command : $(OGRE_HOME)\Bin\$(Configuration)\$(ProjectName).exe
Working Directory: $(OGRE_HOME)\Bin\$(Configuration)
   
  Now Goto Configuration Properties->C/C++->General->Additional Include Directories add following:
  $(OGRE_HOME)\include
$(OGRE_HOME)\include\OIS
$(OGRE_HOME)\include\OGRE 
$(OGRE_HOME)\Samples\Common\include
$(OGRE_HOME)\boost_1_44

In Configuration->Linker->General->Additional Library Directories add following - $(OGRE_HOME)\lib\$(Configuration)
$(OGRE_HOME)\boost_1_44\lib

In Configuration Properties->Build Events->Post Build Event->Command Line, add:
copy "$(OutDir)\$(TargetFileName)" "$(OGRE_HOME)\Bin\$(Configuration)"


Now make some Configuration Specific Settings. Switch Configuration to Active(Debug) : 

Add Input libaries for debug : 
OgreMain_d.lib
OIS_d.lib

Configuration Properties -> Linker -> Input ->Additional Dependencies -> Release
Switch configuration from Active(debug) to Active(release).
Add input libraries for release: 
OgreMain.lib
OIS.lib

4. Now Build your project and see the output. All executables generated are sent to the Ogre SDK's->Bin Folder as all the Ogre .dll files are there. So you may execute from there as well.

30 September 2011

Common Ubuntu Problems and their Solutions

-> Error: “E: Could not get lock /var/lib/apt/lists/lock – open (11:   Resource temporarily unavailable)”
        Solution: Change to root user and type the following commands -
             $ su
             # killall -9 apt-get aptitude
             # rm -f /var/lib/apt/lists/lock


         If you further get the same error, then type -
               # rm -f /var/lib/dpkg/lock


Restart Ubuntu GNOME session without Rebooting 

1. Press Ctrl+Alt+T to open the terminal.
2. Type the following command - $sudo /etc/init.d/gdm restart  

 Restore panels in Ubuntu to their default settings
1. Press Ctrl+Alt+T to open the terminal.
2. Type the following commands one by one in terminal
$ gconftool-2 --shutdown
$ gconftool --recursive-unset /apps/panel
$ rm -rf ~/.gconf/apps/panel
$ pkill gnome-panel


Auto Login for a specific user
1. Go to Users And Group settings and disable ask for password when login for that particular user.
2. The open terminal and go to  /etc/lightdm/lightdm.conf
3. Add the line  - 
        autologin-user=<username>
4. Save and exit.


Change Ip settings for Ubuntu server
1. sudo vi /etc/network/interfaces
2. For auto eth0 DHCP, add -
   auto eth0
   iface eth0 inet dhcp
3. For auto eth0 static IP, add -
    auto eth0
    iface eth0 inet static
        address 192.168.1.100
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.1
4. Now add the DNS settings by editing resolv.conf file - 
    sudo vi /etc/resolv.conf

Installing Desktop environment on Ubuntu server
1. Update the repository -
     $ sudo apt-get update
2. If you want to install ubuntu desktop, type - 
     $ sudo apt-get install ubuntu-desktop
3. If you want to install desktop environment without addons like mail client or open office, type - 
     $ sudo aptitude install --without-recommends ubuntu-desktop
4. If you want to install some light weight desktop, type - 
     $ sudo apt-get install xubuntu-desktop
5. If you want to install the kde environment, type -
     $ sudo apt-get install kubuntu-desktop

Installing add-apt-repository
1. When you try to add repository on Ubuntu server, most often you get the error -
    sudo : add-apt-repository : command not found
2. The solution is to install python-software-properties
   sudo apt-get install python-software-properties 




29 September 2011

Resetting Compiz to Remove "no taskbar problem" in Ubuntu 11.04 Unity

1. If you don't have compiz configuration manager, then you can install it by going to the terminal  and typing -
   $ sudo apt-get install compizconfig-settings-manager
If you have problem opening the terminal, press Ctrl+Alt+F2 or you can directly run commands in terminal by pressing Alt+F2.


2. Now if you want to change some specific settings in compiz, you can start gconf editor by -
  $ gconf-editor
  This should bring you the Gnome Configuration editor as shown below. From the left side choose:"apps" -> "compiz-1". Now under "compiz-1", go to "plugins". You'll see a lot of setting there which can be changed as required.
After making the changes, reset the unity using the terminal -
   $ unity --reset


3. So, if you successfully messed up Compiz then you can actually reset all those value to the default ones by issuing the below commands in your Terminal.
   $ gconftool-2 --recursive-unset /apps/compiz-1
   $ unity --reset  

27 September 2011

Installing OpenGL on Ubuntu

OpenGL is installed by the graphics driver provider, so you don't need to worry about installing OpenGL. The only thing you require is the GL libraries to work on OpenGL coding.

This can be done by installing glut as follows -

 sudo apt-get install freeglut3 freeglut3-dev

This will install the required libraries in /usr/lib/libglut.a and includes in the /usr/include/GL folder.

To test the library just write any openGL code and compile is using the linker "-lglut" as -

$ g++ helloworld.cpp -lglut



Installing Virtual Box 4.x on Ubuntu 11.04

Install virtualbox 4.x on ubuntu 11.04


1. You need to edit /etc/apt/sources.list by typing
$ sudo gedit /etc/apt/sources.list

2. Add the following line
$ deb http://download.virtualbox.org/virtualbox/debian natty contrib

3. Save and exit the file.
    Now type the following command in terminal -

$ wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -

4. Update source list -
$ sudo apt-get update

5. Now install virtual box by typing - 
$ sudo apt-get install virtualbox-4.0


Note: Ubuntu/Debian users might want to install the dkms package to ensure that the VirtualBox host kernel modules (vboxdrv, vboxnetflt and vboxnetadp) are properly updated if the linux kernel version changes during the next apt-get upgrade. For Debian it is available in Lenny backports and in the normal repository for Squeeze and later. The dkms package can be installed through the Synaptic Package manager or through the following command:

$ sudo apt-get install dkms


24 September 2011

Installing OpenCV 2.3 on Ubuntu 11.04

Building and installing OpenCV 2.3 on Ubuntu 11.04 -
1. Install the OpenCV dependencies by typing following commands.

sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev
To cover all the dependencies install -
sudo apt-get install build-essential
sudo apt-get install cmake
sudo apt-get install pkg-config
sudo apt-get install libpng12-0 libpng12-dev libpng++-dev libpng3
sudo apt-get install libpnglite-dev libpngwriter0-dev libpngwriter0c2
sudo apt-get install zlib1g-dbg zlib1g zlib1g-dev
sudo apt-get install libjasper-dev libjasper-runtime libjasper1
sudo apt-get install pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools
sudo apt-get install libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-progs
sudo apt-get install ffmpeg libavcodec-dev libavcodec52 libavformat52 libavformat-dev
sudo apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0  libgstreamer0.10-dev
sudo apt-get install libxine1-ffmpeg  libxine-dev libxine1-bin
sudo apt-get install libunicap2 libunicap2-dev
sudo apt-get install libdc1394-22-dev libdc1394-22 libdc1394-utils
sudo apt-get install swig
sudo apt-get install libv4l-0 libv4l-dev
sudo apt-get install python-numpy

Further optional dependencies could be checked and installed from the configure option during building. For more info go to OpenCV site.

2. Download the OpenCV 2.3 source from here or type following command -
   wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3.1/OpenCV-2.3.1a.tar.bz2/

3. Extract the OpenCV tar file (preferably in your home directory)
    tar -xvf OpenCV-2.3.1a.tar.bz2

4. Now create the build directory for opencv
    $ cd OpenCV-2.3.1
    $ mkdir opencv.build
    $ cd opencv.build

5. Configure, make and install the code -
    $ cmake ..
    $ make
    $ sudo make install

6. Open the .bashrc file from your home folder
    $ gedit .bashrc
     and add the following at the end of the file -

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/<username>/OpenCV-2.3.1/opencv.build/lib
    export PKG_CONFIG_PATH=/home/<username>/OpenCV-2.3.1/lib/opencv.build/pkgconfig
    alias gcv="g++ `pkg-config --cflags opencv` `pkg-config --libs opencv`"

7. Now test building the samples -
    $ cd /home/<username>/OpenCV-2.3.1/samples/c
    $ chmod a+x build_all.sh
    $ ./build_all.sh
   If the samples are successfully compiled, then your opencv is ready to use.

8. Since we added an alias in the bashrc file named "gcv", you can compile any opencv code just by using this alias as -
    $ gcv hellocv.cpp

6 September 2011

Using dynamixel motors in ROS in Ubuntu 10.10


The Dynamixel AX-12 Servo from Robotis is one of the advanced actuator on the market, in this price range. It is widely used in hobby robotics. The Dynamixl AX-12 robot servo has the ability to track its speed, temperature, shaft position, voltage, and load. These parameters are coded on 10 bits each. Also, the algoirthm used to maintain shaft position on the AX-12 actuator can be adjuste individually for each servo, allowing you to control the speed and strength of the motor's response. All of the sensor management and position control is handled by the servo's build-in microcontroller (ATMega 8). The Dynamixel AX-12 servos are different from regular hobby servos. They connect to a serial bus, and each has an ID number.

The above is the picture shows how a Dynamixel AX-12 motor looks like. The figure below shows the pin configuration and has to be kept in mind while connecting it to power source or to other motors.
I am using 3 Dynamixel AX-12 serially connected as daisy chain and is interfaced with the computer using USB2Dyanamixel. This device also has its SDK in C so that the motor movements and values could be easily accessed from ROS nodes. The figure below is of the USB2Dynamixel dongle device.
I am working on Ubuntu 10.10 with 2.6.35-28-generic kernel version. Its recommended by Dynamixel SDK providers to use kernel greater than 2.6.21 as the code regarding FT232RL is already added to the kernel code so you don't have to install this. 

Just download the Dynamixel SDK for linux from here.

The SDK for linux folder composes of the following folder after making it -
/include  :this contains header files to use Dynamixel SDK
/src         :this folder contains the Dynamixel SDK source files
/lib          :this contains the compiled library files
/example :there are examples to control Dynamixel motors

I copied the dynamixel.h header file into standard header folder i.e. /usr/include and libdxl.a library into /usr/lib so that it may work as any linux shared library. After doing all this, the system is ready to interact with the motors using the C code. The motors must be connected to the computer using USB2Dynamixel connected to any of the USB port.

Before going to the coding, its better to go through the AX-12 manual and also through the Dynamixel APIs in C. The address values and pin configurations should be seen as it will be required while programming to know the addresses. This can be accessed from here

Here is a sample program which I used for rotating three motors connected serially.

#include <stdio.h>
#include <termio.h>
#include <unistd.h>
#include <dynamixel.h>
#include <termios.h>

int getch(void)
{
  int ch;
  struct termios oldt;
  struct termios newt;
  tcgetattr(STDIN_FILENO, &oldt); /*store old settings */
  newt = oldt; /* copy old settings to new settings */
  newt.c_lflag &= ~(ICANON | ECHO); /* make one change to old settings in new settings */
  tcsetattr(STDIN_FILENO, TCSANOW, &newt); /*apply the new settings immediatly */
  ch = getchar(); /* standard getchar call */
  tcsetattr(STDIN_FILENO, TCSANOW, &oldt); /*reapply the old settings */
  return ch; /*return received char */
}

// Control table address
#define P_GOAL_POSITION_L 30
#define P_GOAL_POSITION_H 31
#define P_PRESENT_POSITION_L 36
#define P_PRESENT_POSITION_H 37
#define P_MOVING 46

/** Motor IDs of all three motors motors */
#define MOTOR1      18
#define MOTOR2      17
#define MOTOR3      15

// Id of the currently connected dynamixel
#define DEFAULT_BAUDNUM 1 // 1Mbps
#define DEFAULT_ID 15

void PrintCommStatus(int CommStatus);
void PrintErrorCode(void);

int main()
{
        int baudnum = 1;
        /*
         * One digit of motor represents 0.3515625 degrees.
         * One degree represents 2.8444444 values of motor turn
         */
        int GoalPos[2] = {512, 512};
        /**
         * Middle Motor limits - [ -92.109, 101.25  ]
         */
        int GoalPosMotor2[2] = { 250, 800 };
        /**
         * Base Motor limits - [-180, 180 ];
         */
        int GoalPosMotor1[2] = { 0, 1024 };
        /**
         * Top Motor limits - [ 77.344, 125.859 ];
         */
        int GoalPosMotor3[2] = { 292, 870 };
        //int GoalPos[2] = {0, 4095}; // for Ex series
        int index = 0;
        int deviceIndex = 0;
        int Moving, PresentPos;
        int CommStatus;

        printf( "\n\nRead/Write example for Linux\n\n" );
        ///////// Open USB2Dynamixel ////////////
        if( dxl_initialize(deviceIndex, baudnum) == 0 )
        {
                printf( "Failed to open USB2Dynamixel!\n" );
                printf( "Press Enter key to terminate...\n" );
                getchar();
                return 0;
        }
        else
                printf( "Succeed to open USB2Dynamixel!\n" );
        int turnValue = 512;
        dxl_write_word( 18, 32, 100 );
        dxl_write_word( 17, 32, 100 );
        dxl_write_word( 15, 32, 100 );
        dxl_write_word( BROADCAST_ID, P_GOAL_POSITION_L, turnValue );

        while(1)
        {
                printf( "Press Enter key to continue!(press ESC and Enter to quit)\n" );
                char c = getch();
                if(c == 0x1b)
                     break;
                if(c == 'a')
                    turnValue-=1;
                if(c == 'd')
                    turnValue+=1;

                 printf("Turn value - %d\n", turnValue);
                // Write goal position

                dxl_write_word( 18, P_GOAL_POSITION_L, 900 );
                dxl_write_word( 17, P_GOAL_POSITION_L, 400 );
                dxl_write_word( 15, P_GOAL_POSITION_L, 700 );
                do
                {
                        // Read present position
                        PresentPos = dxl_read_word( DEFAULT_ID, P_PRESENT_POSITION_L );
                        CommStatus = dxl_get_result();

                        if( CommStatus == COMM_RXSUCCESS )
                        {
                                printf( "%d   %d\n",GoalPos[index], PresentPos );
                                PrintErrorCode();
                        }
                        else
                        {
                                PrintCommStatus(CommStatus);
                                break;
                        }

                        // Check moving done
                        Moving = dxl_read_byte( DEFAULT_ID, P_MOVING );
                        CommStatus = dxl_get_result();
                        if( CommStatus == COMM_RXSUCCESS )
                        {
                                if( Moving == 0 )
                                {
                                        // Change goal position
                                        if( index == 0 )
                                                index = 1;
                                        else
                                                index = 0;
                                }

                                PrintErrorCode();
                        }
                        else
                        {
                                PrintCommStatus(CommStatus);
                                break;
                        }
                }while(Moving == 1);
        }

        // Close device
        dxl_terminate();
        printf( "Press Enter key to terminate...\n" );
        getchar();
        return 0;
}

/** Printing communication result */
void PrintCommStatus(int CommStatus)
{
        switch(CommStatus)
        {
        case COMM_TXFAIL:
                printf("COMM_TXFAIL: Failed transmit instruction packet!\n");
                break;

        case COMM_TXERROR:
                printf("COMM_TXERROR: Incorrect instruction packet!\n");
                break;

        case COMM_RXFAIL:
                printf("COMM_RXFAIL: Failed get status packet from device!\n");
                break;

        case COMM_RXWAITING:
                printf("COMM_RXWAITING: Now recieving status packet!\n");
                break;

        case COMM_RXTIMEOUT:
                printf("COMM_RXTIMEOUT: There is no status packet!\n");
                break;

        case COMM_RXCORRUPT:
                printf("COMM_RXCORRUPT: Incorrect status packet!\n");
                break;

        default:
                printf("This is unknown error code!\n");
                break;
        }
}

/** Print error bit of status packet */
void PrintErrorCode()
{
        if(dxl_get_rxpacket_error(ERRBIT_VOLTAGE) == 1)
                printf("Input voltage error!\n");

        if(dxl_get_rxpacket_error(ERRBIT_ANGLE) == 1)
                printf("Angle limit error!\n");

        if(dxl_get_rxpacket_error(ERRBIT_OVERHEAT) == 1)
                printf("Overheat error!\n");

        if(dxl_get_rxpacket_error(ERRBIT_RANGE) == 1)
                printf("Out of range error!\n");

        if(dxl_get_rxpacket_error(ERRBIT_CHECKSUM) == 1)
                printf("Checksum error!\n");

        if(dxl_get_rxpacket_error(ERRBIT_OVERLOAD) == 1)
                printf("Overload error!\n");

        if(dxl_get_rxpacket_error(ERRBIT_INSTRUCTION) == 1)
                printf("Instruction code error!\n");
}


This program can be compiled using the following line - 
$ g++ main.cpp -o output -ldxl -lm

For integrating it with ros, we just need to add the library in the CMakeLists.txt as -
target_link_libraries(<executable name> -ldxl -lm)


References - 

Using Qt Libraries in ROS


Modify the CMakeLists.txt file to include the qt library while compilation. Add the following lines at the end of the default generated CMakeLists.txt file -


find_package(Qt4)
include(${QT_USE_FILE})
# This is necessary as all ui files etc will get dumped in the bottom of the
# binary directory.
include_directories(${CMAKE_CURRENT_BINARY_DIR})

##############################################################################
# Sections
##############################################################################

file(GLOB QT_FORMS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ui/*.ui)
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} resources/*.qrc)
file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/local/*.hpp)

QT4_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES})
QT4_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})
QT4_WRAP_CPP(QT_MOC_HPP ${QT_MOC})

##############################################################################
# Sources
##############################################################################

file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp)

##############################################################################
# Binaries
##############################################################################

rosbuild_add_executable(qgoo ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP})
target_link_libraries(qgoo ${QT_LIBRARIES})



2 September 2011

Single Installer for OpenNI, NITE and Sensor Kinect on Windows

While searching for proper installation methods to setup Kinect using OpenNI and NITE on my Windows 7 64-bit system, I came across a very interesting site named ZigFu. I faced a lot of trouble integrating the working NITE and OpenNI sdk with the Unity for 3D game development.

The Zigfu OpenNI installer lets you set up your entire development environment in one click. It bundles together OpenNI, NITE and SensorKinect and configures them automatically. They also provide a Unity package which can be directly imported into Unity with basic functionalities.

The required links -
1. Download Installer
2. Download Unity Package
3. Zigfu Website