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

1 September 2011

Installing Kinect Windows 7 64-bit (using OpenNI and NITE)

The OpenNI organization is an industry-led, not-for-profit organization formed to certify and promote the compatibility and interoperability of Natural Interaction (NI) devices, applications and middleware. PrimeSense, the company behind Kinect, released OpenNI framework and NITE middleware. This means that we can now have access to features such as real-time skeleton tracking, gesture recognition, wave detection and much more!

The latest binaries and source codes can be downloaded from the OpenNI download website  -
1. Sources
2. Binaries
3. Avin Sensor Binaries (This can be downloaded form the git repository of avin2 project)

Download the following binaries and sources from the OpenNI site if you are using Windows 7 64-bit or download corresponding binaries for 32bit systems -
1. PrimeSense Sensor Module (stable / unstable) - (Filename : avin2-SensorKinect-<version>)
2. OpenNI binaries (stable / unstable) - (Filename: openni-win32-<version>)
3. OpenNI Compliant Middleware Binaries(NITE)  - (Filename: NITE-Win64-<version>)

Installation instructions -
Step 1: Disable User Access Control : http://windows.microsoft.com/en-US/windows-vista/Turn-User-Account-Control-on-or-off
Step 2: Uninstall everything, OpenNI, NITE, any Kinect Sensor Driver, Kinect Virtual Camera or any other driver related to Kinect.
Step 3: Install the downloaded OpenNI binary.
Step 4: Extract avin zip into a folder. Now go to avin extracted folder -> platform->win32->driver. Install the driver according to your system(32/64 bit). Now go the the avin extracted folder->Bin and install Sensor Kinect 32.
Step 5: Install downloaded NITE binary.Step 6: Hold "Win" key and press "R" button. Then type "Sysdm.cpl" and press enter.
Step 7: Go to advanced tab and click on "Environment Variables". From system variables select "Path" and         click "Edit". Then go to the end of the string at variable value field and add a ";" character and then your  "Kinect Sensor Driver" installation address plus "/Bin".
  And your Kinect Sensor Driver installation directory was, e.g. -
 "C:\Program Files (x86)\Prime Sense\Sensor"
 Click Ok and then Ok again. And again Ok.

Restart your PC.

After restarting your PC connect the kinect to any of the USB ports and wait for automatic installation to be complete. Three devices will be detected namely - Motor, Camera and Audio device.
Your installation is complete. Now try checking your installation by running NITE samples.

After this you have to write the licence information in the data xmls installed with the above setups. You can download the xmls from here and replace the default xml files in the Data folder of the the OpenNI and NITE package which are installed in Program Files folder by default.

Now your tools are ready to integrate with anything.

Other reference sites -
1. http://www.kinectdevs.com/forums/kinect-virtual-camera-kinect-webcam-f17/kinect-drivers-and-64bit-windows-t13.html
2. http://www.studentguru.gr/blogs/vangos/archive/2011/01/20/how-to-successfully-install-kinect-windows-openni-nite.aspx
3. http://code.google.com/p/vr-simon/wiki/InstallingKinect
4. http://www.kinecthacks.nl/kinect-tutorial-3-setting-up-openni-and-nite-on-windows-for-kinect/
5. http://www.codingbeta.com/?p=10

24 August 2011

Installing Kinect on Windows 7 64-bit (Microsoft Kinect SDK)

System Requirements
* Windows 7 (x86 or x64)
* Dual Core or Faster
* 2 GB Ram
* Windows 7 compatible graphics card that supports Directx 9.0
* Kinect Sensor
* Microsoft Visual Studio 2010 Express or Other Visual Studio 2010 edition
* .Net Framework 4.0
*  For C++ Skeletal Viewer samples: Microsoft DirectX® SDK - June 2010 or later version
    Runtime for Microsoft DirectX® 9 
For Speech sample (x86 only):
     Microsoft Speech Platform Runtime, version 10.2 (x86 edition)
     Microsoft Speech Platform - Software Development Kit, version 10.2 (x86 edition)
     Kinect for Windows Runtime Language Pack, version 0.9
     (acoustic model from Microsoft Speech Platform for the Kinect for Windows SDK Beta)



Installation
To install this beta SDK:
  1. Make sure the Kinect device is not plugged in to the USB port on your computer.
     
  2. Remove any other drivers for the Kinect device, including earlier versions of the Microsoft Kinect drivers.
     
  3. Close Visual Studio.
    Note: You must close Visual Studio before installing the SDK and then restart it after installation to pick up the MSRKINECTSDK environment variables that the SDK requires.
     
  4. From the download location for the beta SDK package, double-click the link for your system: 32-bit or 64-bit.
To load the Microsoft Kinect drivers:
  1. Make sure the Kinect device is plugged into an external power source.
     
  2. After installing the beta SDK, plug your Kinect device into the PC's USB port.
     
  3. All the drivers, including audio, will load seamlessly.
If the driver is installed correctly:
  1. You should see a blinking green LED on the Kinect sensor.
     
  2. The Kinect sensor should appear in Device Manager as the following nodes under “Microsoft Kinect”:
    • Microsoft Kinect Audio Array Control
    • Microsoft Kinect Camera
    • Microsoft Kinect Device
  3. The Kinect sensor's microphone array should appear under Sound, Video and Game Controllers in Device Manager as : Kinect USB Audio     

Useful Pages 

29 June 2011

Installing PyDev plugin for Eclipse IDE


PyDev is a Python IDE for Eclipse, which may be used in PythonJython and IronPython development.
It comes with many goodies such as:
  • Django integration
  • Code completion
  • Code completion with auto import
  • Syntax highlighting
  • Code analysis
  • Go to definition
  • Refactoring
  • Mark occurrences
  • Debugger
  • Remote debugger
  • Tokens browser
  • Interactive console
  • Unittest integration
  • Code coverage
  • and many others
To install the plugin into already installed Eclipse IDE -
1. Start the Eclipse IDE, you will see a welcome screen like this -


2. Go to Help -> Install new Software
    This will look like this -


3. Type the following url resource into the text box so that it will download the required plugins from there and install something like this. It will look something like this after typing everything -


4. Click "Next" and "OK" to continue installing PyDev.
5. Select "I accept the terms of the license agreement", then click "Finish". The installer will begin to download the plug-in.
6. A following window will appear after download is complete. Check the box and click on OK.




7. When the installation is complete, you will be asked if you want to restart Eclipse. Select "Yes". You may see a Subclipse Usage  dialog, just uncheck the box and continue.

26 June 2011

Installing PVM on Ubuntu 10.10 64 bit


PVM is a software system that allows you to combine a number of computers which are connected over a network into a Parallel Virtual Machine. This machine can consist of computers with different architectures, running different flavors of the Unix/Linux operating systems, and can still be treated as if it were a single parallel machine.

The simpler way to install PVM is
1. Go to the synaptic package manager and install pvm, libpvm3, xpvm.
2. Or type in terminal $sudo apt-get install pvm

Check if the PVM libraries in /usr/lib/pvm3  or in /usr/local/lib/pvm3 and include files in /usr/include directory.

Configuring PVM to work on different machines -
1. Find out which computers are available. You can use any computer on which you have an account,    and on which PVM is installed.

2. Edit or create the file .rhosts in your home directory. This file must have an entry for every computer you want to use. The entry is in the form of the name of the computer and your login name on that machine:
 ucs.orst.edu  kowallih
dogby.physics.edu hans

If your login name is the same on all machines, then you can leave the field with the login name blank, but it doesn’t hurt to put it in.

3. Set the environment variables in the .bashrc file.
export PVM_ROOT="/usr/lib/pvm3"
export PVM_ARCH=`$PVM_ROOT/lib/pvmgetarch`
export XPVM_ROOT=/usr/bin/xpvm
export PVM_RSH=`which ssh`

4. Create directories for your executables:
    $mkdir $HOME/pvm3/bin/PVM ARCH
where PVM ARCH is the PVM code for the architecture. Although this step is not necessary for PVM to work, it will make your life much easier if you are going to use PVM on computers with different architectures. You can find the code for each computer’s via the PVM function pvmgetarch.

The PVM console
The PVM console is the interface between the parallel virtual machine and the user. You use it to start and stop processes, to display information about the state of the virtual machine, and most importantly, to start and stop PVM on local and remote machines.

Step 1: Starting PVM Log into one of the computers you want to include in
PVM and enter:
pvm>

Step 2: Adding hosts This is done from the PVM prompt:
pvm> add <hostname>
where hostname is the name of the computer you want to add. This will start PVM
on the specified hosts and, if successful, will produce a message such as:
1 successful
HOST DTID
banana 140000
You can continue to add additional hosts as desired.

Step 3: Checking your configuration You display the configuration of your
parallel virtual machine from the PVM prompt:
pvm> conf
This will give you information about the hosts configured, their PVM identification
number and their architecture.

Step 4: Deleting hosts Sometimes it is necessary to remove hosts from the virtual
machine to test or debug a program:
pvm> delete <hostname>

Step 5: Leaving the console If you are done with setting up your virtual machine,
and if you don’t need any of the other functions of the console, you close the
console but keep PVM running:
pvm> quit

Step 6: Stopping PVM To stop PVM after your parallel program has finished,
enter the PVM console, and then from the PVM prompt:
> pvm From Unix shell
pvm> halt From PVM prompt
This stops PVM on all the machines and kills all programs running under PVM.
This is the best and easiest way to stop PVM.

A simple hello.c code to check the library.

#include <stdio.h>
#include <pvm3.h>

int main()
{
  int mytid;

  mytid = pvm_mytid();
  printf("My TID is %d\n", mytid);
  pvm_exit();
  return 0;
}

Compiling the code - 
$gcc hello.c -o hello -lpvm3
A simple master program master.c

#include <stdio.h>
#include <stdlib.h>
#include <pvm3.h>

int main()
{
  int myTID;
  int x = 12;
  int children[10];
  int res;

  myTID = pvm_mytid();
  printf("Master: TID is %d\n", myTID);

  res = pvm_spawn("slave", NULL, PvmTaskDefault, "", 1, children);
  if (res<1) {
    printf("Master: pvm_spawn error\n");
    pvm_exit();
    exit(1);
  }

  pvm_initsend(PvmDataDefault);
  pvm_pkint(&x, 1, 1);

  pvm_send(children[0], 1);

  pvm_recv(-1, -1);
  pvm_upkint(&x, 1, 1);

  printf("Master has received x=%d\n", x);

  pvm_exit();

  return 0;
}

A simple client program slave.c

#include <stdio.h>
#include <pvm3.h>

int main()
{
  int myTID, masterTID;
  int x = 12;

  myTID = pvm_mytid();
  printf("Slave: TID is %d\n", myTID);

  pvm_recv(-1, -1);
  pvm_upkint(&x, 1, 1);
  printf("Slave has received x=%d\n", x);

  sleep(3);
  x = x + 5;

  pvm_initsend(PvmDataDefault);
  pvm_pkint(&x, 1, 1);

  pvm_send(pvm_parent(), 1);

  pvm_exit();

  return 0;
}

Compiling the above code - 
$gcc -o master master.c -lpvm3
$gcc -o slave slave.c -lpvm3
Now copy the slave binary to the standard pvm folder so that master may know where to get the binary to spawn it.