Monday, November 23, 2015

How to Disable ipv6 in UBUNTU


In order to disable the ipv6 in Ubuntu for many reasons like installing hadoop


  • open the terminal and write following command
  •  sudo gedit /etc/sysctl.conf
  • once the editor is opened copy the following lines

# disable ipv6


    net.ipv6.conf.all.disable_ipv6 = 1


      net.ipv6.conf.default.disable_ipv6 = 1

        net.ipv6.conf.lo.disable_ipv6 = 1

        Once that is copied , either you can restart sysctl or restart in somecase when the instructions does not make any change


        How to change computer name in ubunutu

        While installing Hadoop for multi-cluster , i needed to re-name machines, so that each virtual machine can be called differently so for this i did following steps
        • Open the terminal in UBUNTU
        • sudo gedit /etc/hostname
        • you will be prompted for password, enter that
          • Editor will be opened where you can insert the name you like 
          • Save it
        • and now Restart the system to apply the changes
        • You can watch the steps in videos

        Wednesday, November 18, 2015

        Tutorial 2: Step by Step Database Connection and Operations

        Tutorial 2: Step by Step Database Connection and Operations

        // Step 1: Add the SQL Library

        import java.sql.*;

        // Step2 : Add Jar file

        ·         right click library -> Properties -> Add Jar / Folder -> MySql connector.jar


        //Step 3: JDBC driver name and database URL

           static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; 
           static final String DB_URL = "jdbc:mysql://localhost/studenttest";

        // Step 4:  Database credentials

           static final String USER = "root";
           static final String PASS = "";

        // Step 5: Define Connection and Query Variables

                Connection conn = null;
                 Statement stmt = null;
                 ResultSet rs = null;

        // Step 6: Try - Catch Block

                
                 try{
                    
                 }catch(Exception ex){

        //Step 7Handle errors for SQL and other exception


              ex.printStackTrace();
                 }

          // STEP 8: Register JDBC driver

              Class.forName("com.mysql.jdbc.Driver");

         //STEP 9: Open a connection

              System.out.println("Connecting to database...");
              // connection statement
              conn = DriverManager.getConnection(DB_URL,USER,PASS);


         //STEP 10 : Creating a SQL Statement

              System.out.println("Creating SQL Statement...");
              stmt = conn.createStatement();
              String sql;
              sql = "SELECT id, name, age FROM staff";


        // Step 11: Exectuting the SQL Query

              rs = stmt.executeQuery(sql);

         //STEP 12: Get the Data From RS

              while(rs.next()){ // while rs has the data

        //Step 13: Retrieve the data column by column

                 int id  = rs.getInt("id");
                 int age = rs.getInt("age");
                 String name = rs.getString("name");
               

        //Step 14: Display the Results stored

                 System.out.print("ID: " + id);
                 System.out.print(", Name: " + name);
                 System.out.println(", Age: " + age);
                
                

        //STEP 15: Closing up all the connection and result set to clear the environment

                        rs.close(); // result set
                        stmt.close(); // sql query
                        conn.close(); // connection

        //Step 16: Error checks

        ·         //variable name worng
        ·         //putting closing statement inside checks

        Step 17: Run the file


        Step 18: java and SQL date time options


        Step19: Insert Example

        create a new java class InsertExample

        // Step 20: Add the Sql Library

        import java.sql.*;

        public class InsertExample {

        //Step 21: JDBC driver name and database URL

           static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; 
           static final String DB_URL = "jdbc:mysql://localhost/studenttest";
          
        // Step 22:  Database credentials
           static final String USER = "root";
           static final String PASS = "";
            public static void main(String[] args) {
               
            }

         

        // Step 23: Define Connection and Query Variables

                Connection conn = null;
                 Statement stmt = null;
                 ResultSet rs = null;
                

        // Step 24: Try - Catch Block

                
                 try{

        //STEP 25: Register JDBC driver

              Class.forName("com.mysql.jdbc.Driver");
             

         //STEP 26: Open a connection

              System.out.println("Connecting to database...");

         //Step 27:  connection statement

              conn = DriverManager.getConnection(DB_URL,USER,PASS);
                    

        //STEP 28 : Creating a SQL Statement

              System.out.println("Creating SQL Statement...");
              System.out.println("Inserting records into the table...");
              stmt = conn.createStatement();
             

        // Step 29: Creating Insert Statement

              String sql = "INSERT INTO studentinfo " +
                           "VALUES (3, 'Amjad', 18, 'Jeddah')";
              stmt.executeUpdate(sql);
              sql = "INSERT INTO studentinfo " +
                           "VALUES (4, 'Nawaf', 25, 'Yanbu')";
              stmt.executeUpdate(sql);
             

              //just the print out

              System.out.println("Inserted records into the table...");
          

          //STEP 31: Closing up all the connection

                            stmt.close(); // sql query
                        conn.close(); // connection 
                                        }catch(Exception ex){

        //Step 30: Handle errors for


                        ex.printStackTrace();
                 }   
             
                     
                 }catch(Exception ex){



        Now create program for update, delete, whereas , like and sorting

        Tutorial 1 : Creating a JDBC connection with Swing

        Tutorial 1: Step by Step Database Connection with SWING

        Step 1: Create a class name MySQLConnector

        Step 2: Add the dependencies

        import java.sql.*; // for SQL
        import javax.swing.*; // for Design

        Step 3: // Object for database connection

            Connection conn = null;

        Step 4:// Create a class for Connect

            public Connection ConnectDatabase(){
           
                try{
          
                   }catch(Exception ex){
                    JOptionPane.showMessageDialog(null,ex);
                }
        }

        Step 5:    Inside try catch block

                         STEP 2: Register JDBC driver
                        This will load the MySQL driver, each DB has its own driver
                    System.out.println("Register JDBC driver");
                    Class.forName("com.mysql.jdbc.Driver");

        Step 6-An optional go to the main class and define the variables to be used

           // JDBC driver name and database URL

           static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; 
           static final String DB_URL = "jdbc:mysql://localhost/EMP";
           

           // Database credentials

           static final String USER = "root";
           static final String PASS = "";

        //STEP7: Open a connection

              System.out.println("Connecting to database...");
             // conn = DriverManager.getConnection(DB_URL,USER,PASS);
              conn = DriverManager.getConnection("jdbc:mysql://localhost/studenttest","root","");
              return conn;
                }

        //Step 8 Catch block

        catch(Exception ex){
                    JOptionPane.showMessageDialog(null,ex);
                    return null;
                }

        Step9: Create a Table Staff for login

        ·         Staff_ID
        ·         NAME
        ·         AGE
        ·         USERNAME
        ·         PASSWORD

        Step 10: Create a New JFRAME Form

        ·         name it Login_form
        ·         Add two labels username and password
        ·         Add a text field
        ·         Add a Password Field
        ·         Add a button

        Change the variables name

        ·         username : txt_username
        ·         password : txt_password
        ·         button : btn_login

        Step11: Put in Panel


        Select all the label, field and button
        ·         right click and enclose in panel
        ·         Go to properties of panel and select title border

        //Step: 12 import the following librarys for Login Form

        import java.awt.*;
        import java.awt.event.WindowEvent;
        import java.sql.*;
        import javax.swing.*;

        //Step 13: Declare the connection and connector variables for Login Form

            Connection conn = null;
            PreparedStatement pst = null;
            ResultSet rs = null;

         //Step 14 A Closing Event with a Function is created to close the form

            public void close(){
                WindowEvent winClosingEvent = new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
                Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);
            }


        Step 15: Create a form open event

        // event for window opened
            // to do it right click on outside panel then event,-> windowEvent -> windowopened
            private void formWindowOpened(java.awt.event.WindowEvent evt) {                                 
                // TODO add your handling code here:
            }

        Step 16: // Step 16: event for window opened

        ·         // to do it right click on outside panel then event,-> windowEvent -> windowopened
            private void formWindowOpened(java.awt.event.WindowEvent evt) {                                 
                // for the connection the MYSQL
                conn = MySQLConnector.ConnectDatabase();
            }         

        Step 17:

        ·         GO to design
        ·         Then on button
        ·         Right Click -> Events -> Mouse -> buttonCLikced

         //when the login button is pressed
            private void btn_loginMouseClicked(java.awt.event.MouseEvent evt) {                                      
                // TODO add your handling code here:
            }

         //Step 18: Write SQL Statements

                String sql= "select * from staff where username=? and password=?";
               

         //Step 19: Try Catch Blocks

                try{
                   
                }catch(Exception esql){
                   
                }
        //////////
        catch(Exception esql){

                    //step20: print exception

                    JOptionPane.showMessageDialog(null, esql);
                }

          // Step 21: Create the Statement object

        //The createStatement() method of Connection interface is used to create statement.
         // The object of statement is responsible to execute queries with the database.
                    pst =conn.prepareStatement(sql);

         //Step 22: Get the Variable names from entered data

                    pst.setString(1,txt_username.getText());
                    pst.setString(2,txt_password.getText());


         //Step 23:  // Result set get the result of the SQL query

             //Execute the query : The executeQuery() method of Statement interface
              //is used to execute queries to the database.
               //This method returns the object of ResultSet that can be used to get all the records of a table.
              
                    rs = pst.executeQuery();

        //Step 24:  Verification of results Retrieved

                    if(rs.next()){ // there is some record received only in case of valid username and password
                        JOptionPane.showMessageDialog(null,"You Have ENTERED Correct Information");
                        close();
                    }

        //Step 25: else{ // step 25: else portion if the username is not valid

                        JOptionPane.showMessageDialog(null,"You Have ENTERED In-Correct Information");
                    }

        //Step 26: //default close information to dispose

        ·         Go to design -> main screen -> Properties
        ·         DeafultCloseOperation from Close to Dispose to see the screen staying there

        // Step 27 : Add the sql library


        ·         Go to library on left pane
        ·         Select add library
        ·         then add my-sql jar

        //Step 28: Create a new JFrameFrom for showing Staff info


        ·         rightclick -> New -> JFrameForm and name it as staffinfo

        // Step 29 Add this to code to show the staff pane

                        Staff_Info s_info = new Staff_Info();
                        s_info.setVisible(true);

        //Step 30: See Main Function


        //Step 31: Right Click Run the file


        ·         enter correct and incorrect information check the command line

        //Step 32: go to staffinfo jframe and add the table from the design pane

        ·         //then rename by
        ·         right click on table-> change variable name
        ·         then enter the name   tbl_staffinfo

        //Step 33: Table connector driver rs2xml.jar

        www.filesdownload.info/file/69Se66yD/rs2xml.html

        //Step 34: Add it to project

        go to library -> then properties -> add jar/folder and select rs2xml.jar

        //step 35: Go to Staff_info.java


        // Step 36: Add the Header files

        import java.sql.*;
        import javax.swing.*;
        import net.proteanit.sql.DbUtils;

         //Step 37:  Define the Connection Statements

            Connection conn = null;
            ResultSet rs = null;
            PreparedStatement pst = null;

         // Step 38: the connection statement

                conn = MySQLConnector.ConnectDatabase();

        //Step 39: create a population method

           
            private void Update_table(){
                try{
               
                }catch(Exception ex){
                    JOptionPane.showMessageDialog(null, ex);
                }
            }

           //step 40:  select queries

                    String sql = "select * from staff";
                    pst= conn.prepareStatement(sql);
                    rs= pst.executeQuery();

            //Step 41: now use the variable name for the table given when the Jtable was dragged

                    tbl_staffinfo.setModel(DbUtils.resultSetToTableModel(rs));

        //Step 42: Call the Populate_table()method

                Populate_table();

             

        Sunday, May 24, 2015

        How to reload UDEV rules without restarting the PC



        While new udev rules are created, in order to make them working we have to restart the udev rules.

        following command will do it.

        Open the terminal and write following command

        sudo udevadm control --reload-rules

        Sunday, March 29, 2015

        Creating a robotic arm model using MoveIT


        In this video tutorial, I explained multiple details for creating robotic arm using moveIT, and viewing it in rviz. This tutorial is divided into following steps. In order to cover all the details follow the steps explained in video.

        1. Installing moveit.

        2. Creating a static robotic arm model,

        3. Running the moveit Setup assistant,

        4. Loading the urdf model,

        5. Generating the collision matrix,

        6. Creating Virtual joints,

        7. Adding the right arm planning group,

        8. Adding the gripper joints,

        9. Defining robot poses

        10. Generating the Configuration files.



        References
        1. wiki ROS.
        2. Wiki MoveIT,
        3, ROS by example v2 book

        Creating and Playing the ROSBAG file

        This tutorial is a video tutorial that describes how to create a rosbag file, how to replay the ros bag file and how to run the hokuyo node. so video is divided into following steps.

        1. Allowing hokuyo node to connect with.
        2. Deploying roscore
        3. Running Hokuyo node
        4. Checking for topic scan
        5. Looking in RVIZ for data view
        6. creating a bag file for recording scan topic
        7. Stopping every thing except roscore.
        8. playing bag file.
        9. Viewing the data in rviz again and comparing it will recorded data.


        Tuesday, March 3, 2015

        Creating Publisher and Subscriber for TurtleSim in ROS


        This tutorial explains the creation of publisher and subscriber. It also explains how to get the message details and call backs for each subscriber. In second portion it creates a publisher for turtlesim.

        In order to create the publisher and subscriber for turtlesim provided by ROS follow the following steps.

        1. run roscore on the terminal, For this open the terminal and write "roscore".



        2. Open new terminal using "Ctrl+Shift+N" or using mouse and run the turtlesim using following command
        "  rosrun turtlesim turtlesim_node "



        3. See the list of topic , for this open new terminal and write
        " rostopic list "




        4. There are three topics for the turtlesim naming

        • /turtle1/cmd_vel
        • /turtle1/color_sensor
        • /turtle1/pose


        5. Now lets see which topic need subscriber and which one need publisher, for this run the following command

        " rostopic info /turtle1/color_sensor" 




        and this shows it needs a subscriber as it is a published topic having type " turtlesim/Color "

        now run the command
        " rostopic info /turtle1/pose "



        and this shows it needs a subscriber as it is a published topic having type " turtlesim/Pose "

        now run the command for third topic
         "rostopic info /turtle1/cmd_vel "



        and this shows it needs a publisher as it is a subscriber on the topic " geometry_msgs/Twist "

        6. Once we know about the subscribers and publisher , we can continue our programming. First we will create subscriber, so in order to create , create an empty file named " subscriber_tsim.cpp ". and copy the following code.

        #include "ros/ros.h"
        #include "turtlesim/Color.h"
        #include "turtlesim/Pose.h"

        // Topic messages callback
        void color_callback(const turtlesim::Color::ConstPtr& col)
        {
        ROS_INFO("red: %d, green: %d, blue: %d", col->r, col->g, col->b);
        }

        //pose_callback
        void pose_callback(const turtlesim::Pose& msgIn){

        ROS_INFO_STREAM(std::setprecision(2) << std::fixed
        << "position=(" << msgIn.x << "," << msgIn.y << ")"
        << "direction=" << msgIn.theta); 
          
        }

        int main(int argc, char **argv)
        {
            // Initiate a new ROS node named "subTsim"
        ros::init(argc, argv, "subTsim");
        //create a node handle: it is reference assigned to a new node
        ros::NodeHandle node;

            // Subscribe to a given topic, in this case "chatter".
        //color_callback: is the name of the callback function that will be executed each time a message is received.
            ros::Subscriber subscriber_color = node.subscribe("/turtle1/color_sensor", 1000, color_callback);

            
            ros::Subscriber subscriber_pose=node.subscribe("turtle1/pose", 1000, pose_callback);
            // Enter a loop, pumping callbacks
            ros::spin();

            return 0;
        }


        7. Now, we have to change the makings on CMakeLists.txt . add the following lines

        add_executable(subtsim src/subscriber_tsim.cpp)
        target_link_libraries (subtsim ${catkin_LIBRARIES})
        add_dependencies(subtsim beginner_tutorials_generate_message_cpp)


        8. Now, open the terminal and compile the code. for this type following

        cd catkin_ws
        catkin_make

        if the compilation is successful then we can proceed.

        9. now run the node we created , for this run the following code.
        " rosrun beginner_tutorials subtsim




        10. Now, we will create the publisher, for this create a file named "publisher_tsim.cpp " and copy the following code

        #include "ros/ros.h"
        #include "geometry_msgs/Twist.h"
        #include "geometry_msgs/Pose.h"
        #include <sstream>


        int main(int argc, char **argv)
        {
        // Initiate new ROS node named "talker"
        ros::init(argc, argv, "pubTsim");
        ros::NodeHandle n;

        ros::Publisher velocity_publisher = n.advertise<geometry_msgs::Twist>("/turtle1/cmd_vel", 1000);
        ros::Rate loop_rate(1); //1 message per second

           int count = 0;
           /* initialize random seed: */
             srand (time(NULL));
           while (ros::ok()) // Keep spinning loop until user presses Ctrl+C
           {

          geometry_msgs::Twist vel_msg;
          //set a random linear velocity in the x-axis
          vel_msg.linear.x =(double)(rand() % 10 +1)/4.0;
          vel_msg.linear.y =0;
          vel_msg.linear.z =0;
          //set a random angular velocity in the y-axis
          vel_msg.angular.x = 0;
          vel_msg.angular.y = 0;
          vel_msg.angular.z =(double)(rand() % 10 - 5)/2.0;

          //print the content of the message in the terminal
           ROS_INFO("[Random Walk] linear.x = %.2f, angular.z=%.2f\n", vel_msg.linear.x, vel_msg.angular.z);

          //publish the message
          velocity_publisher.publish(vel_msg);
               ros::spinOnce(); // Need to call this function often to allow ROS to process incoming messages

              loop_rate.sleep(); // Sleep for the rest of the cycle, to enforce the loop rate
               count++;
           }
           return 0;
        }

        save the file.

        11. Now go to CMakeLists.txt and add the following lines
        add_executable(pubtsim src/publisher_tsim.cpp)
        target_link_libraries (pubtsim ${catkin_LIBRARIES})
        add_dependencies(pubtsim beginner_tutorials_generate_message_cpp)



        12.  Now, open the terminal and compile the code. for this write 
        cd catkin_ws
        catkin_make

        13. Now, launch the node, this will make the turtlesim run as random walk. you can also view the values from subscriber node.





        14. For more details you can watch the video tutorial at

        Saturday, February 21, 2015

        VMWARE EXSI Server installation - P1


        VMWARE EXSI Server installation


         

        In order to create the VMWare EXSi server 5.5 server we need to do the following steps

        Part 1: Collecting the Tools required


        1.       Creating account at https://my.vmware.com.

        2.       Downloading the following list of software’s from VMWARE Website

        a.       VMware-tools-linux-9.4.10-2068191

        b.      VMware-viclient-all-5.5.0-1993072.exe

        c.       VMware-VMvisor-Installer-5.5.0.update02-2068190.x86_64.iso

        d.      VMware-vCenter-Server-Appliance-5.5.0.20000-2063318_OVF10.ova

        3.       Downloading supporting client tools

        a.       Putty

        b.      WinSCP

        c.       RUFUS

        4.       Supportive Hardware required

        a.       USB stick Minimum 4GB

        b.      A Server Machine

        c.       A High Internet Speed LAN connection

        Part 2:


        5.       Run Rufus application and click No for updates

        6.       Select the MBR partiions and find the VMWARE EXSI  ISO file
         
         
        7.       After the USB the ready install VMWare EXSI at Server and set the network for this follow the following steps
        a.       Creating RAID for your server.
        b.      Enabling Virtualization from settings.
        c.       Running the installer.
        d.      Accepting the License
        e.      Setting the password for server
         

        f.       Restart the server and
        g. Managing the IP configuration that making the static IP of server


        We can access the server from any other system over the network, we may get the following error but we can pass through it