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