Monday, January 25, 2010

NextSapiens Robotics Local Contest (Basic Embedded System)

Our team (with the name DU Terminator) just participated the International Robot Contest (Bangladesh Regional). The purpose was to build a line follower robot which will reach the destination following line of colors within shortest time. The problem statement is here.

I’m doing a bit report here based on our team’s work. First of all you need a development kit which will guide through programming to work with sensors and move forward using motors.

Development Kit

We got a basic development kit from NextSapiens which includes
ü  ATMega16 Micro controller.
ü  L293D IC, LCD Screen, Sensors
ü  Relays, Switches, LEDs
ü  Power Supply
ü  And other electronic/electrical components

Collect a development kit according to your requirement and ask for manual to the manufacturer.

As I couldn’t find an online/ebook manual for the development board we have used, I’m just describing the coding has to be done for this development board. Anyway, you can get it from spellbound or nenomart. As the mcu is Atmega16 we can use AVR softwares such as BASCOM AVR.

Coding

A sample code for line follower robot with three sensors is given below.

$regfile = "m16def.dat"
$crystal = 4000000

Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7,
E = Portb.3 , Rs = Portb.2

Config Adc = Single , Prescaler = Auto , Reference = Avcc
Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Down,
Compare B Pwm = Clear Down

Start Adc
Cls
Start Timer1

Dim Lw As Integer
Dim Lb As Integer
Dim Lm As Integer

Dim Cw As Integer
Dim Cb As Integer
Dim Cm As Integer

Dim Rw As Integer
Dim Rb As Integer
Dim Rm As Integer

Dim L As Integer
Dim R As Integer
Dim C As Integer

Lcd "Place on White"
Waitms 1000
Lw = Getadc(0)
Cw = Getadc(1)
Rw = Getadc(2)
Cls

Lcd "Place on Black"
Waitms 1000
Lb = Getadc(0)
Cb = Getadc(1)
Rb = Getadc(2)
Cls

Lcd "Mean"
Lm = Lw + Lb
Lm = Lm / 2

Cm = Cw + Cb
Cm = Cm / 2

Rm = Rw + Rb
Rm = Rm / 2

Do
Cls

L = Getadc(0)
C = Getadc(1)
R = Getadc(2)

Lcd L ; "-" ; C ; "-" ; R

If L < Lm And C > Cm And R < Rm Then
Lcd "FWD"
Pwm1b = 100
Portd.3 = 0
Pwm1a = 100
Portd.6 = 0
Cls

Elseif L < Lm And C < Cm And R > Rm Then
Lcd "Right"
Pwm1b = 120
Portd.3 = 0
Pwm1a = 30
Portd.6 = 0
Cls

Elseif L > Lm And C < Cm And R < Rm Then
Lcd "Left"
Pwm1b = 30
Portd.3 = 0
Pwm1a = 120
Portd.6 = 0
Cls

Elseif L < Lm And C > Cm And R > Rm Then
Lcd "90 Right"
Pwm1b = 120
Portd.3 = 0
Pwm1a = 0
Portd.6 = 0
Cls

Elseif L > Lm And C > Cm And R < Rm Then
Lcd "90 Left"
Pwm1b = 0
Portd.3 = 0
Pwm1a = 120
Portd.6 = 0
Cls


End If

Loop
End

Coding Description

ü    $regfile = "m16def.dat" includes the header file for atmega16 mcu.

ü    $crystal = 4000000 provides 4MHz clock

ü    Config routine configures devices.

ü    Getadc as initialized reads the sensor value.

ü    Waitms library routine performs the delay specified in milliseconds.

ü    Cls clears the LCD screen.

ü    Lcd routine prints provided text on LCD Screen.

There are certain factors that should be considered or as critical cases for line follower robots such as:

ü    Following acute angles correctly

ü    Distance between sensors according to track width

ü    Distance between motors for fast turning

ü    Weight of battery (better if it can be covered the voltage source with single cell of battery)

ü    Equality of readings of all sensors and similarity of speed of motors

Tricks

For first round one doesn’t need great speed to win over. Hence you can slow a bit down if you wish. Critical cases like Y-shapes, T-shapes or acute angles should be handled properly depending on the track specification.

Line Follower Robot and the Contest

A video stream of our line follower robot is embedded below.


Robot as moves following the black line track

On the contest our team acquired 4th position and the other team DU RoboIcon acquired 2nd position. A photo on the venue with Judge is attached here.


International Robotics Intelligent Systems Competition 2010 (1st robotics competition in Bangladesh) at Agargaon [DU Teams, 4 Participants of DU Terminator on Left Side and 4 Participants of DU RoboIcons on Right Side]

Related Links:

        http://www.nextsapiens.com/
        http://www.nextsapiens.com/site/edu/bes.htm
        http://www.nenowiki.com/

Monday, January 18, 2010

Windows command prompt pwd command doesn't work

There is no pwd executable file in windows. But there is a way. Create a batch script with following texts.

@echo %CD%

Save it as pwd.cmd. Now type pwd command at command prompt.

st> pwd
g:\Sourcecodes\Scripts

Also you can type cd without any arguments which works the same way as pwd in Linux.

Instant Messengers / Clients


Yahoo Messenger


Yahoo Messenger 10 Multi-lingual [click image to zoom]

Yahoo Messenger 10 brought several new features and enhancements. It has improved appearance, video calling feature, twitter like status updates etc.

Download latest stable release [10.0.0.1102]
       http://download.yahoo.com/ycs/msg/dl/msgr10/us/ymsgr1000_1102_us.exe

It’s a direct link from yahoo’s server. One more thing, do you know that you can keep back up of your yahoo messege/ chat archives? The folder where messages are archived is C:\Program Files\Yahoo!\Messenger\Profiles\YourPCUserName


Messenger 10 with improved appearance [click image to zoom]


Yahoo Messenger 10 Y! Insider with improved appearance [click image to zoom]

Google Talk


Google Talk [click image to zoom]


Download Latest stable release [1.0.0.105]
       http://dl.google.com/googletalk/googletalk-setup.exe [Permanent Link]

This page will be updated with every new release of these softwares.

Happy IMs with updated softwares.

Tips: There is a pattern on the direct download links. If you can recognize that you can generate the link for every new release.

Learning some commands makes Linux life easier

Redirecting inputs and outputs
It's about these two operator '<' and '>'. For example,

$ ls -l > fileList.txt

The output of this command is not printed on the screen, it is written to a file named fileList.txt.

cat command

Purpose of this command is equivalent to "type" command. You can view contents of a text file using cat command. Example given below,

$ cat fileList.txt 
total 36 
drwxrwxrwx   4 ar       root         512 Dec  1 16:45 HarvardPackages 
-rwxrwxrwx   1 ar       root        1098 Dec  1 16:49 IS_OS161_v1.3.1.sh~ 
-rwxrwxrwx   1 ar       root        1140 Dec  1 16:49 IS_OS161_v1.3.2.sh 
drwxrwxrwx   2 ar       root         512 Dec  1 16:44 Package 1.4 
-rwxrwxrwx   1 ar       root         244 Dec  1 16:49 Scripting.txt 
-rwxrwxrwx   1 ar       root         189 Dec  1 16:49 Scripting.txt~ 
drwxrwxrwx  12 ar       root         512 Dec  1 16:47 cs161-binutils-1.4 
drwxrwxrwx   6 ar       root         512 Dec  1 16:48 cs161-gcc-1.4-2 
drwxrwxrwx  14 ar       root         512 Dec  1 16:44 cs161-gdb-1.4-2 
-rw-r--r--   1 ar       other          0 Dec 26 20:03 fileList.txt 
-rwxrwxrwx   1 ar       root         148 Dec  1 16:44 input.sh 
-rwxrwxrwx   1 ar       root         294 Dec  1 16:49 install.sh~ 
-rwxrwxrwx   1 ar       root         695 Dec  1 16:49 install_os161.sh 
-rwxrwxrwx   1 ar       root         668 Dec  1 16:49 install_os161.sh~ 
drwxrwxrwx  10 ar       root         512 Dec  1 16:49 os161-1.11 
drwxrwxrwx  16 ar       root        1024 Dec  1 16:49 sys161-1.12-2 
-rwxrwxrwx   1 ar       root          24 Dec  1 16:49 test2.txt~ 

grep
Very useful command. It is used to filter the outputs (pipes supported). If you don't understand the purpose in theory don't worry you will be able to understand from examples. If you give the command ls -a it will show like this,

$ ls -a 
total 44 
drwxrwxrwx   9 ar       root         512 Dec 26 20:03 . 
drwxrwxrwx   6 ar       root         512 Dec  1 16:43 .. 
drwxrwxrwx   4 ar       root         512 Dec  1 16:45 HarvardPackages 
-rwxrwxrwx   1 ar       root        1098 Dec  1 16:49 IS_OS161_v1.3.1.sh~ 
-rwxrwxrwx   1 ar       root        1140 Dec  1 16:49 IS_OS161_v1.3.2.sh 
drwxrwxrwx   2 ar       root         512 Dec  1 16:44 Package 1.4 
-rwxrwxrwx   1 ar       root         244 Dec  1 16:49 Scripting.txt 
...........................................................................
...........................................................................
drwxrwxrwx  10 ar       root         512 Dec  1 16:49 os161-1.11 
drwxrwxrwx  16 ar       root        1024 Dec  1 16:49 sys161-1.12-2 
-rwxrwxrwx   1 ar       root          24 Dec  1 16:49 test2.txt~

If the output was huge and wanted details about only the file whose name
contains Package. Then give the command like this:


$ ls -l | grep Package 
drwxrwxrwx   4 ar       root         512 Dec  1 16:45 HarvardPackages 
drwxrwxrwx   2 ar       root         512 Dec  1 16:44 Package 1.4

'|' This sign is called pipe which linked the output of first command to the second as input. You can search for files containing certain text string.

$ grep -r "textString" /path

Use -H switch to show line numbers. grep has many useful options learn them from manual ("$ man grep")

find

In case you know the name of a file but you don't know where it is then to find it's location use this command,

find /directoryname -name file.ext

which
If you apply a command but don't know from where it'll be executed or where the executable file resides? To view that location use this syntax,

which commandName
Example,

$ which gcc 
/usr/sfw/bin/gcc

It is the output for Solaris 10. Hence, your output can be different.

tar

An archive is a file containing compressed files and directories.
  • creating an archive using tar command

    $ tar -cvf test.tar local.login local.profile .bashrc 
    a local.login 1K 
    a local.profile 1K 
    a .bashrc 1K

    Why did we use v switch? Let's see the difference.

    $ tar -cf test.tar local.login local.profile .bashrc

    It means if v is included then tar displays information on every file it adds.

    To add a file in an existing archive use -r option(-f means next argument is
    the archive file name).

    $ tar -rf test.tar local.cshrc

  • Extracting archive,
    If file extension contains tar.gz then syntax is,
         tar xzvf fileName.tar.gz

    If extension is tar.bz2
         tar xjvf fileName.tar.bz2

    if extension is only .tar then
         tar xvf fileName.tar.bz2

echo
This is the easiest command. You know about this. An example is,

$ echo "This line will be printed." 
This line will be printed.

zip and unzip
You can create zip files using zip command. Use following syntax.

$ zip ArchiveFileName.zip /path/dir_OR_file

To unzip a zip file (extract an zip archive) use following syntax

$ unzip ArchiveFileName.zip

To work with rar archives follow this post.

Assembling and Linking Assembly Language Codes with TASM and MASM

On the days of Assembly Programming I enjoyed it very much. It was not about which assembler I used, whether it was turbo assembler or microsoft assembler. It was about the clever scripts I always wrote to perform compilation of my codes and linking at ease.

TASM
So if you were using Turbo Assember what would be the command to assemble the code. It is:

D:\tasm\bin> tasm filename.asm

And how to link?

D:\tasm\bin> tlink filename

Notice the tlink command uses only filename. No extension should be provided. Otherwise it will halt on error.

You’ll find my batch script more interesting.

@echo Saint Atique Windows Batch Script
@if exist %1.obj del %1.obj
@if exist %1.exe del %1.exe
@tasm %1
@if not exist %1.obj goto End
@echo Compiled filename: %1.asm (Assembly Sourcecode)
@tlink %1
@echo.
@echo Linked filename: %1.obj (Object file)
@echo.
@if not exist %1.exe goto End
@echo %1.exe (Executable file running under %os% DOS)
@echo =========================================================
@echo.
@%1
@echo.

:End
@echo Process Ended

As I saved it as tcpl.cmd the command to assemble and link a program file was:

D:\tasm\bin> tcpl filename.asm

MASM
I wrote the following script to assemble and link with masm as you know assemble command is masm and linking command is link.

@title Saint Atique masm platform
@echo Saint Atique Script
@echo MASM assemble syntax: mpl SourceFileName (output file is out.exe)
@echo Creating object file.
@echo.
@rem case sensitive /ml switch
@if exist out.exe del out.exe
@if exist out.obj del out.obj
@masm /ml %1 out
@if not exist out.obj goto obj_fail
@echo Linking output obj file
@link /batch out;
@echo.
@if not exist out.exe goto build_fail
@echo Running executable file: out.exe
@echo ==============================================
@out
@echo.
@echo Process succeeded.
@goto end
:obj_fail
@echo.
@echo Error generating obj binary codes
@goto end
:build_fail
@Echo Error building executable file..

:end
@echo Process Ended.
@title Saint Atique Terminal

And for compiling masm win32 programs I wrote this script, saved a lot of hard works and avoiding boorish repetition.


@title Saint Atique masm win32 platform
@echo Saint Atique Script
@echo MASM assemble syntax: wpl SourceFileName
@echo Creating object file.
@echo.
@if exist %1.exe del %1.exe
@if exist %1.obj del %1.obj
@ml /c /coff /Cp %1.asm
@if not exist %1.obj goto obj_fail
@if exist %1.rc @echo Linking %1.rc & @rc %1.rc
@echo Linking object file and res file
@link /SUBSYSTEM:WINDOWS /LIBPATH:e:\masm32\lib %1.obj %1.RES
@echo.
@if not exist %1.exe goto build_fail
@echo Running executable file: %1.exe
@echo ==============================================
@%1.exe
@echo.
@echo Process succeeded.
@goto end
:obj_fail
@echo.
@echo Error generating obj binary codes
@goto end
:build_fail
@echo.
@Echo Errors in source. Correction required..

:end
@echo Process Ended.
@title Saint Atique Terminal

Happy assembling.

Saturday, January 16, 2010

Installing and Configuring Apache, PHP, MySQL on Fedora Core

  • Install Apache (httpd), PHP, MySQL (server and client)

    # yum -y install httpd php mysql mysql-server php-mysql 

  • Configure the new services to start automatically

    # /sbin/chkconfig httpd on 
    # /sbin/chkconfig --add mysqld
    [not required with FC4 and above] 
    # /sbin/chkconfig mysqld on 
    # /sbin/service httpd start 
    # /sbin/service mysqld start

    If everything went okay attempting to open this url:
         http://localhost
    or http://127.0.0.1 will forward to a page like one displayed in image below. Otherwise it will give an error.


    Click image to enlarge

  • By default the document directory is /var/www/html. You can change it modifying /etc/httpd/conf/httpd.conf Modify the lines and set like this:

    DocumentRoot "/home/AR/web"

    And another line

    <Directory "/home/AR/web">


    Changing directory like this may not allow apache to read files or execute scripts. Hence this error message "Forbidded, you don't have permission to access / on this server" can be produced. To get rid of this change the directory attributes to executable.


    # chmod a+x /home 
    # chmod a+x /home/AR 
    # chmod a+x /home/AR/web

    which means that you are giving permission of execution to apache for the entire directory chain. This actually solves the problem. If still the problem persists then apply this command too.

    # chown -R apache:apache /home/AR/web

    Change "/home/AR/web" with your www directory.

  • Add mysqld as startup service

    # /sbin/chkconfig mysqld on 
    # /sbin/service mysqld start

  • Change the mysqladmin password for security reason.

    # mysqladmin -u root password new-password

Notice # means root user prevelige.

How to Install Kaspersky Antivirus/ Internet Security on Linux

Fedora Core Instructions

Command "yum install kaspersky" won't work.

First you have to download your required product/software from
        kes10linux

After that you have to install the downloaded package (rpm for Fedora Core/RHEL/CentOS etc and .deb for debian systems like Ubuntu)

For rpm packages try this command to install Kaspersky Software

# rpm -Uvh packagename.rpm

Also you can try this command

# yum localinstall packagename.rpm

For debian packages try this command to install Kaspersky Software.


$ sudo dpkg -i package.deb

You can choose to install the network agent version if you want to enable installation from Network.

Refreences

https://usa.kaspersky.com/small-to-medium-business-security/endpoint-linux
Kaspersky Endpoint Security 10 for Linux - Administrator's Guide - Application version 10


$ sudo dpkg -i package.deb

Monday, January 11, 2010

Learning SQL through MySQL software


Installing WAMP Server and Starting MySQL Console
To learn SQL you don’t necessarily need an Oracle SQL Server(oracle/sql is really big in size). We can achieve our goals still with MySQL. Install wamp server to get MySQL along with Apache and PHP. Latest release till today is 2.0i
          http://www.wampserver.com/en/download.php

W stands for Windows and amp stands for Apache, MySQL and PHP.

Now start wamp server clicking Start Menu -> Programs -> WampServer -> Start WampServer.

You’ll see there is a icon on the right side of the taskbar. Click (not right button click) it. In the Menu under submenu of MySQL click MySQL console.

It will ask for a password. By default there is no password set. Simply press enter.

Working with Databases
First step is to list the databases. You will use the following query to list databases.

show databases

Every query ends with a semicolon. Hence here is how the console responds to the query.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mydb               |
| mysql              |
+--------------------+
3 rows in set (0.01 sec)

Create your own database. The command to create database is

create database databasename

Here is the console response for a sample command.

mysql> create database bankdb;
Query OK, 1 row affected (0.01 sec)
Now you have to select a database to work with. In our case it’s bankdb;

mysql> use bankdb;
Database changed

Working with Tables
To list tables inside the database you have to use “show tables” query.
mysql> show tables;
Empty set (0.00 sec)

Note Oracle SQL query “select * from tab” doesn’t work here.

mysql> select * from tab;
ERROR 1146 (42S02): Table 'bankdb.tab' doesn't exist

As there are no tables on the database we’ll create some.

During creating tables we need to remember that data type number and varchar2 does not exist in mysql. To know more about mysql data types follow here.

To compare with oracle data types check link this too.

Hence we replace varchar2 with varchar and number with float.

And we create tables with following commands.

create table branch
        (branch_name varchar(15),
        branch_city varchar(12) not null,
        assets float(10,2) not null,
        constraint b_pk primary key(branch_name),
        constraint b_chk check(assets>=0));

create table customer
        (customer_name varchar(20),
        customer_street varchar(15),
        customer_city varchar(15)not null,
        constraint c_pk primary key(customer_name));


create table account
        (account_no char(5),
        branch_name varchar(15),
        balance float(10,2) not null,
        constraint a_pk primary key(account_no),
        constraint a_fk foreign key (branch_name) references branch(branch_name),
        constraint a_chk1 check (balance>=0),
        constraint a_chk2 check (account_no like 'A-%'));


create table loan
        (loan_no char(5),
        branch_name varchar(15),
        amount float(10,2) not null,
        constraint l_pk primary key(loan_no),
        constraint l_fk foreign key (branch_name) references branch(branch_name),
        constraint l_chk1 check (amount >= 0),
        constraint l_chk2 check (loan_no like 'L-%'));


create table depositor
        (customer_name varchar(15),
        account_no char(5),
        constraint de_pk primary key (customer_name, account_no),
        constraint de_fk1 foreign key (customer_name) references customer(
        customer_name), constraint de_fk2 foreign key (account_no) references
        account(account_no));


create table borrower
        (customer_name varchar(15),
        loan_no char(5),
        constraint bo_pk primary key (customer_name, loan_no),
        constraint bo_fk1 foreign key (customer_name) references customer (
        customer_name), constraint bo_fk2 foreign key (loan_no) references 
        loan (loan_no));
Show current list of tables.
mysql> show tables;
+------------------+
| Tables_in_bankdb |
+------------------+
| account          |
| borrower         |
| branch           |
| customer         |
| depositor        |
| loan             |
+------------------+
6 rows in set (0.00 sec)
You use desc command to view descriptions of a table.
mysql> desc account;
+-------------+-------------+------+-----+---------+-------+
| Field       | Type        | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| account_no  | char(5)     | NO   | PRI |         |       |
| branch_name | varchar(15) | YES  | MUL | NULL    |       |
| balance     | float(10,2) | NO   |     | NULL    |       |
+-------------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

Now it’s time to insert data into the tables.
insert into branch
values('Brighton','Brooklyn',7100000);

insert into branch
values('Downtown', 'Brooklyn',9000000);

insert into branch
values('Mianus', 'Horseneck',400000);

insert into branch
values('North Town', 'Rye',3700000);

insert into branch
values('Perryridge', 'Horseneck',1700000);

insert into branch
values('Pownal', 'Bennington',300000);

insert into branch
values('Redwood', 'Palo Alto',2100000);

insert into branch
values('Round Hill', 'Horseneck',8000000);


insert into customer
values('Adams','Spring','Pittsfield');

insert into customer
values('Brooks','Senator','Brooklyn');

insert into customer
values('Curry','North','Rye');

insert into customer
values('Glenn','Sand Hill','Woodside');

insert into customer
values('Green','Walnut','Stamford');

insert into customer
values('Hayes','Main','Harrison');

insert into customer
values('Jhonson','Alma','Palo Alto');

insert into customer
values('Jones','Main','Harrison');

insert into customer
values('Lindsay','Park','Pittsfield');

insert into customer
values('Smith','North','Rye');

insert into customer
values('Turner','Putnam','Stamford');

insert into customer
values('Williams','Nassau','Princeton');


insert into account
values('A-101','Downtown',500);

insert into account
values('A-102','Perryridge',400);

insert into account
values('A-201','Brighton',900);

insert into account
values('A-215','Mianus',700);

insert into account
values('A-217','Brighton',750);

insert into account
values('A-222','Redwood',700);

insert into account
values('A-305','Round Hill',350);


insert into loan
values('L-11', 'Round Hill',900);

insert into loan
values('L-14', 'Downtown',1500);

insert into loan
values('L-15', 'Perryridge',1500);

insert into loan
values('L-16', 'Perryridge',1300);

insert into loan
values('L-17', 'Downtown',1000);

insert into loan
values('L-23', 'Redwood',2000);

insert into loan
values('L-93','Mianus',500);


insert into depositor
values('Hayes', 'A-102');

insert into depositor
values('Jhonson', 'A-101');

insert into depositor
values('Jhonson', 'A-201');

insert into depositor
values('Jones', 'A-217');

insert into depositor
values('Lindsay', 'A-222');

insert into depositor
values('Smith', 'A-215');

insert into depositor
values('Turner', 'A-305');


insert into borrower
values('Adams', 'L-16');

insert into borrower
values('Curry', 'L-93');

insert into borrower
values('Hayes', 'L-15');

insert into borrower
values('Jackson', 'L-14');

insert into borrower
values('Jones', 'L-17');

insert into borrower
values('Smith', 'L-11');

insert into borrower
values('Smith', 'L-23');

insert into borrower
values('Williams', 'L-17');

Now you can perform queries on existing tables and data for practicing. I’ll add some nice queries soon.

Sunday, January 10, 2010

How to Create Makefile from Imakefile

Here we'll describe how to create Makefile using Imakefile.

Create the Imakefile for example with following contents
TARGET = program.out
OBJS = main.o
SRCS = main.cpp

CC = g++
CCOPTIONS = -g

MESAINCDIR = /usr/include
MESALIBDIR = /usr/lib

GLLIB = -L$(MESALIBDIR) -lglut -lGLU -lGL
XLIB = -L/usr/lib -lXmu -lXi -lXext -lX11 -lm -lpthread
INCLUDES = -I$(MESAINCDIR)

LOCAL_LIBRARIES = $(GLLIB) $(XLIB)

ComplexProgramTarget($(TARGET))

Use xmkmf command to create makefile from Imakefile.
$ xmkmf

xmkmf script actually uses imake command to create Imakefile. Hence following command would also work.

$ imake -DUseInstalled -I/usr/share/X11/config

xmkmf command does not necessarily require a parameter. It looks for a file named Imakefile inside current dirctory to create makefile.

If imake package is not installed bash will tell you that Command not found. For Fedora Core Systems login as root and type the following command.

# yum -y install imake

For Ubuntu the command will be something like this.

$ sudo apt-get install imake

Now imake or xmkmf command will work.

Now let's test it compiling and running a program. Create your source file main.cpp for example with following contents.

/* Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above notice and this permission notice shall be included in all copies
 * or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/* File for "Basic Shapes" lesson of the OpenGL tutorial on
 * www.videotutorialsrock.com
 */



#include <iostream>
#include <stdlib.h> //Needed for "exit" function

//Include OpenGL header files, so that we can use OpenGL
#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

using namespace std;

//Called when a key is pressed
void handleKeypress(unsigned char key, //The key that was pressed
     int x, int y) {    //The current mouse coordinates
 switch (key) {
  case 27: //Escape key
   exit(0); //Exit the program
 }
}

//Initializes 3D rendering
void initRendering() {
 //Makes 3D drawing work when something is in front of something else
 glEnable(GL_DEPTH_TEST);
}

//Called when the window is resized
void handleResize(int w, int h) {
 //Tell OpenGL how to convert from coordinates to pixel values
 glViewport(0, 0, w, h);
 
 glMatrixMode(GL_PROJECTION); //Switch to setting the camera perspective
 
 //Set the camera perspective
 glLoadIdentity(); //Reset the camera
 gluPerspective(45.0,                  //The camera angle
       (double)w / (double)h, //The width-to-height ratio
       1.0,                   //The near z clipping coordinate
       200.0);                //The far z clipping coordinate
}

//Draws the 3D scene
void drawScene() {
 //Clear information from last draw
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
 glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
 glLoadIdentity(); //Reset the drawing perspective
 
 glBegin(GL_QUADS); //Begin quadrilateral coordinates
 
 //Trapezoid
 glVertex3f(-0.7f, -1.5f, -5.0f);
 glVertex3f(0.7f, -1.5f, -5.0f);
 glVertex3f(0.4f, -0.5f, -5.0f);
 glVertex3f(-0.4f, -0.5f, -5.0f);
 
 glEnd(); //End quadrilateral coordinates
 
 glBegin(GL_TRIANGLES); //Begin triangle coordinates
 
 //Pentagon
 glVertex3f(0.5f, 0.5f, -5.0f);
 glVertex3f(1.5f, 0.5f, -5.0f);
 glVertex3f(0.5f, 1.0f, -5.0f);
 
 glVertex3f(0.5f, 1.0f, -5.0f);
 glVertex3f(1.5f, 0.5f, -5.0f);
 glVertex3f(1.5f, 1.0f, -5.0f);
 
 glVertex3f(0.5f, 1.0f, -5.0f);
 glVertex3f(1.5f, 1.0f, -5.0f);
 glVertex3f(1.0f, 1.5f, -5.0f);
 
 //Triangle
 glVertex3f(-0.5f, 0.5f, -5.0f);
 glVertex3f(-1.0f, 1.5f, -5.0f);
 glVertex3f(-1.5f, 0.5f, -5.0f);
 
 glEnd(); //End triangle coordinates
 
 glutSwapBuffers(); //Send the 3D scene to the screen
}

int main(int argc, char** argv) {
 //Initialize GLUT
 glutInit(&argc, argv);
 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
 glutInitWindowSize(400, 400); //Set the window size
 
 //Create the window
 glutCreateWindow("Basic Shapes - videotutorialsrock.com");
 initRendering(); //Initialize rendering
 
 //Set handler functions for drawing, keypresses, and window resizes
 glutDisplayFunc(drawScene);
 glutKeyboardFunc(handleKeypress);
 glutReshapeFunc(handleResize);
 
 glutMainLoop(); //Start the main loop.  glutMainLoop doesn't return.
 return 0; //This line is never reached
}

Now apply make command to compile and build the program. And then as in our Imakefile output file name was program.out type ./program.out to display output.

$ make
c++ -m32 -O2 -fno-strength-reduce -fno-strict-aliasing   -I/usr/include \
-I/usr/include -Dlinux -D__i386__ -D_POSIX_C_SOURCE=199309L -D_POSIX_SOURCE\ 
-D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_LARGEFILE_SOURCE \
-D_FILE_OFFSET_BITS=64 -c -o main.o main.cpp
rm -f program.out
g++ -o program.out -O2 -fno-strength-reduce -fno-strict-aliasing -g -L/usr/lib\ 
main.o -L/usr/lib -lglut -lGLU -lGL -L/usr/lib -lXmu -lXi -lXext -lX11 -lm -lpthread
make: *** No rule to make target `program.out.man', needed by `program.out._man'.
Stop.

It is not a must that you have to use an Imakefile to compile sources. You can use simple makefiles.

For example a file named makefile with following contents will serve the same purpose.

CC = g++
CFLAGS = -Wall
PROG = basicshapes

SRCS = main.cpp

ifeq ($(shell uname),Darwin)
 LIBS = -framework OpenGL -framework GLUT
else
 LIBS = -lGL -lGLU -lglut
endif

all: $(PROG)

$(PROG): $(SRCS)
 $(CC) $(CFLAGS) -o $(PROG) $(SRCS) $(LIBS)

clean:
 rm -f $(PROG)

An easy tutorial on makefile here.
       http://mrbook.org/tutorials/make

How to Load All New Yahoo Mail on Google Chrome Linux

Users of All New Yahoo Mail may be redirected to the following page when using Google Chrome on Linux.

[Click image to zoom]

The page says "Sorry, the all-new Yahoo! Mail does not support your browser.
You can either download a compatible browser or proceed to Yahoo! Mail Classic."

And there are two options; one to download browsers other to "To proceed to Yahoo! Mail Classic"

How weird is that!! This is happening with Google Chrome 4.0.249.43 which is a very much capable browser for the technologies that New Yahoo Mail uses!

So what's the workaround? As Yahoo Mail is dumb we have to bypass their browser and platform check!

Enter the following URL on address bar and enter
       http://us.mg2.mail.yahoo.com/dc/launch?sysreq=ignore

Asians, use this url. It will help faster loading.
       http://aa.mg2.mail.yahoo.com/dc/launch?sysreq=ignore

Monday, January 4, 2010

OpenGL on Windows & Common Instructions

Download glut for Windows here here.

Common instructions for setting up opengl with Visual Studio
Many different sites have posts about this. However, I'm going to give you hints. In Pro versions SDKs are installed by default. If you are using Visual Studio Express you need to install Windows Platform SDK.

Now extract the glut archive you just downloaded from this page. Copy glut.h and paste where GL.h and GLU.h resides.


[Click image to enlarge]

The directory is PlatformSDKInstallDIR\Windows\VERSION\Include\gl
Copy dll file to System 32 folder
Copy lib file to to PlatformSDKInstallDIR\Windows\VERSION\Lib

For Visual Studio 2008 Pro files go like this.
      glut.h -> C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\gl
      glut32.dll-> C:\Windows\System32
      glut32.lib -> C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib

Testing OpenGL Code
  • Create new win32 -> win32 project.
  • Click Solution Explorer. Right click Source Files. Click Add - > New Item. Specify a name. Select .cpp as template.
  • Download this code file. Extract and copy the contents of the cpp file and paste on the empty cpp file of the IDE
  • Select Project properties additional dependency: opengl32.lib glut32.lib glu32.lib


    [Click image to enlarge]

  • To build press Alt + Shft + B. If build is successful press Ctrl + F5 to run the program.


    [Click image to enlarge]
If your opengl code does not have a WinMAIN function, instead you have a main function then the type of project to be created should be General -> Empty Project to avoid linker errors. Output of the program will start with a console. In both cases you need to remember about selecting additional dependency: opengl32.lib glut32.lib glu32.lib in project properties.

Example of such code here.

Related Links:

Sunday, January 3, 2010

How to hide drive icons on gnome desktop Linux

First we need to install gconf-editor. You can check if it exists in your system (Applications Menu->System Tools->Configuration Editor).

On Fedore Core login as root and apply commands

# su
Password: # yum -y install gconf-editor


On Ubuntu

# sudo aptitude install -P gconf-editor

Now using start menu go to Applications->System Tools->Configuration Editor or simply type 'gconf-editor' on terminal.

Go to apps -> nautilus -> desktop


[Click image to enlarge]

Untick the check box besides "volumes_visible" Immediately the change will take effect and you will see the mounted partitions gone from desktop.



[Click image to enlarge]

How to Install Adobe Flash Player on Google Chrome Linux [Deprecated]

This post is for older version of google chrome. Nowadays google chrome is bundled with flash player. So flash player is no more required to be installed separately. For older versions of chrome which doesn't have flash pleas follow instructions below. First determine if flash player is already installed. Apply following command.

# sudo locate libflashplayer.so
/usr/lib/flash-plugin/libflashplayer.so
/usr/lib/mozilla/plugins/libflashplayer.so
If there is no output it means flash player is not installed. In that case you have to install it.

To install flash player, open a terminal. Press Alt + F2. Type gnome-terminal. Hit Enter.

Command for Ubuntu

# sudo aptitude install flashplugin-installer

For Fedora core, login as root. For example, type su and provide root password and apply following commands.

# rpm -Uvh http://linuxdownload.adobe.com/adobe-release/adobe-release-i386-1.0-1.\
noarch.rpm
warning: adobe-release-i386-1.0-1.noarch.rpm: Header V3 DSA signature: NOKEY, key ID
f6777c67
Preparing...                ########################################### [100%]
   1:adobe-release-i386     ########################################### [100%]

# yum install flash-plugin
Loaded plugins: presto, refresh-packagekit
adobe-linux-i386                                         |  951 B     00:00     
adobe-linux-i386/primary                                 |  12 kB     00:00     
adobe-linux-i386                                                          17/17
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package flash-plugin.i386 0:10.0.42.34-release set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package          Arch     Version                   Repository            Size
================================================================================
Installing:
 flash-plugin     i386     10.0.42.34-release        adobe-linux-i386     3.9 M

Transaction Summary
================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 3.9 M
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 3.9 M
flash-plugin-10.0.42.34-release.i386.rpm                 | 3.9 MB     03:05     
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID f6777c67
adobe-linux-i386/gpgkey                                  | 3.4 kB     00:00 ... 
Importing GPG key 0xF6777C67 "Adobe Systems Incorporated (Linux RPM Signing Key)
<secure@adobe.com>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-adobe-linux
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB has been altered since the last yum transaction.
  Installing     : flash-plugin-10.0.42.34-release.i386                     1/1 

Installed:
  flash-plugin.i386 0:10.0.42.34-release                                        

Complete!

Press y if asked for confirmation.

Restart your browser. Whether it is Google Chrome or Mozilla Firefox no manual configuration is required. Tested on Google Chrome 4.0.249.43 beta.

[Click image to enlarge]

If you still get trouble with Google Chrome make symbolic link after creating plugins directory.

# sudo mkdir /opt/google/chrome/plugins
# sudo ln -s /usr/lib/flashplugin-installer/libflashplayer.so \
/opt/google/chrome/plugins/libflashplayer.so

How to Setup OpenGL (installing glut) on Linux and Compile Programs


Fedora Core Instructions

I am assuming that you have the primary idea about what OpenGL is and what it does. Hence, without wasting any more time let's see how to set it up or install on Linux Operating System.

First check for files gl.h and glut.h

# cd /usr/include/GL
# ls
glext.h      glu.h         glx.h         glxmd.h      internal
gl.h         glu_mangle.h  glxint.h      glxproto.h
gl_mangle.h  glxext.h      glx_mangle.h  glxtokens.h

We have gl.h but no glut.h Hence we have to install development packages. If you don't have gl.h then you have to install mesa graphics libraries or nvidia libraries if you are using nvidia graphics card.

As freeglut devel package provides glut.h we are going to install it.

# yum -y install freeglut-devel
Loaded plugins: presto, refresh-packagekit
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package freeglut-devel.i686 0:2.6.0-1.fc12 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                Arch         Version              Repository       Size
================================================================================
Installing:
 freeglut-devel         i686         2.6.0-1.fc12         updates         112 k

Transaction Summary
================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 112 k
Downloading Packages:
Setting up and reading Presto delta metadata
updates/prestodelta                                      | 322 kB     00:30     
Processing delta metadata
Package(s) data still to download: 112 k
freeglut-devel-2.6.0-1.fc12.i686.rpm                     | 112 kB     00:11     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : freeglut-devel-2.6.0-1.fc12.i686                         1/1 

Installed:
  freeglut-devel.i686 0:2.6.0-1.fc12                                            

Complete!
# ls
freeglut_ext.h  glext.h      glu.h         glxext.h  glx_mangle.h  glxtokens.h
freeglut.h      gl.h         glu_mangle.h  glx.h     glxmd.h       internal
freeglut_std.h  gl_mangle.h  glut.h        glxint.h  glxproto.h

Installation of OpenGL in a Machine without Internet Connection

Download freeglut-devel according to your distribution using a PC that has internet connection.
      freeglut-devel for Fedora Core 8
      freeglut-devel for Fedora Core 9
      freeglut-devel for Fedora Core 10
      freeglut-devel for Fedora Core 11
      freeglut-devel for Fedora Core 12

You can take the file to your PC using a memory device like USB Stick (pen drive)etc. Copy the file in the machine in which you want to install. Login as root(you can type su and provide root password after hitting enter). cd to the directory where you copied the file. Use this syntax to install them (rpm).

# rpm -Uvh filename.rpm

For Fedora Core 12 it will be like this

# rpm -Uvh freeglut-devel-2.6.0-1.fc12.i686.rpm

Now you'll find glut.h inside /usr/include/GL and that's all about installation.

# cd /usr/include/GL
# ls
glext.h      glu.h         glx.h         glxmd.h      internal
gl.h         glu_mangle.h  glxint.h      glxproto.h
gl_mangle.h  glxext.h      glx_mangle.h  glxtokens.h

Now we have glut.h along with other files. If everything is okay and hardware acceleration is enabled then glxinfo command will show "direct rendering: Yes"

# glxinfo
name of display: :0.0
display: :0  screen: 0
direct rendering: Yes
server glx vendor string: SGI
server glx version string: 1.4
server glx extensions:
  GLX_ARB_multisample, GLX_EXT_import_context, GLX_EXT_texture_from_pixmap,
......................................................................

Ubuntu Instructions
For ubuntu I would recommend you to follow this Video tutorial. This is a good one.
       http://www.videotutorialsrock.com/opengl_tutorial/get_opengl_setup_linux/video.php

Writing Opengl Programs and Compiling on Linux

Create a new directory.

$ mkdir og

Change directory.

$ cd og
Use a text-editor to create a make file inside the directory with following contents. For example, you can use command like this, (Or you can download files from the bottom of the post)

$ gedit Makefile&

Contents

CC = g++
CFLAGS = -Wall
PROG = basicshapes

SRCS = main.cpp

ifeq ($(shell uname),Darwin)
 LIBS = -framework OpenGL -framework GLUT
else
 LIBS = -lGL -lGLU -lglut
endif

all: $(PROG)

$(PROG): $(SRCS)
 $(CC) $(CFLAGS) -o $(PROG) $(SRCS) $(LIBS)

clean:
 rm -f $(PROG)

In the same way create a file named "main.cpp" with following contents

/* Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above notice and this permission notice shall be included in all copies
 * or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/* File for "Basic Shapes" lesson of the OpenGL tutorial on
 * www.videotutorialsrock.com
 */

#include <iostream>
#include <stdlib.h> //Needed for "exit" function

//Include OpenGL header files, so that we can use OpenGL
#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <glut/glut.h>
#else
#include <GL/glut.h>
#endif

using namespace std;

//Called when a key is pressed
void handleKeypress(unsigned char key, //The key that was pressed
                              int x, int y) {    //The current mouse coordinates
      switch (key) {
            case 27: //Escape key
            exit(0); //Exit the program
      }
}

//Initializes 3D rendering
void initRendering() {
      //Makes 3D drawing work when something is in front of something else
      glEnable(GL_DEPTH_TEST);
}

//Called when the window is resized
void handleResize(int w, int h) {
      //Tell OpenGL how to convert from coordinates to pixel values
      glViewport(0, 0, w, h);
     
      glMatrixMode(GL_PROJECTION); //Switch to setting the camera perspective
     
      //Set the camera perspective
      glLoadIdentity();      //Reset the camera
      gluPerspective(45.0,                  //The camera angle
                  (double)w / (double)h, //The width-to-height ratio
                  1.0,             //The near z clipping coordinate
                  200.0);          //The far z clipping coordinate
}

//Draws the 3D scene
void drawScene() {
      //Clear information from last draw
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
      glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
      glLoadIdentity(); //Reset the drawing perspective
     
      glBegin(GL_QUADS); //Begin quadrilateral coordinates
     
      //Trapezoid
      glVertex3f(-0.7f, -1.5f, -5.0f);
      glVertex3f(0.7f, -1.5f, -5.0f);
      glVertex3f(0.4f, -0.5f, -5.0f);
      glVertex3f(-0.4f, -0.5f, -5.0f);

      
      glEnd(); //End quadrilateral coordinates
     
      glBegin(GL_TRIANGLES); //Begin triangle coordinates
     
      //Pentagon
      glVertex3f(0.5f, 0.5f, -5.0f);
      glVertex3f(1.5f, 0.5f, -5.0f);
      glVertex3f(0.5f, 1.0f, -5.0f);
     
      glVertex3f(0.5f, 1.0f, -5.0f);
      glVertex3f(1.5f, 0.5f, -5.0f);
      glVertex3f(1.5f, 1.0f, -5.0f);
     
      glVertex3f(0.5f, 1.0f, -5.0f);
      glVertex3f(1.5f, 1.0f, -5.0f);
      glVertex3f(1.0f, 1.5f, -5.0f);
     
      //Triangle
      glVertex3f(-0.5f, 0.5f, -5.0f);
      glVertex3f(-1.0f, 1.5f, -5.0f);
      glVertex3f(-1.5f, 0.5f, -5.0f);
     
      glEnd(); //End triangle coordinates
     
      glutSwapBuffers(); //Send the 3D scene to the screen
}

int main(int argc, char** argv) {
      //Initialize GLUT
      glutInit(&argc, argv);
      glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
      glutInitWindowSize(400, 400); //Set the window size
     
      //Create the window
      glutCreateWindow("Basic Shapes - videotutorialsrock.com");
      initRendering(); //Initialize rendering
     
      //Set handler functions for drawing, keypresses, and window resizes
      glutDisplayFunc(drawScene);
      glutKeyboardFunc(handleKeypress);
      glutReshapeFunc(handleResize);
     
      glutMainLoop(); //Start the main loop.  glutMainLoop doesn't return.
      return 0; //This line is never reached
}


Now compile (simple make command will do this) and run the program

# make
g++ -Wall -o basicshapes main.cpp -lGL -lGLU -lglut
$ ls
basicshapes  main.cpp  Makefile
$ ./basicshapes &

A new window will appear like this one


[Click to enlarge image]


Write in comments if you face any exception.

Download attached files.
          BasicShape.zip