Tuesday, December 20, 2011

ShanghAI lecture assignment 5

The final assignment of the lot. A number of very interesting questions were posted. We tried our best in coming up with the answers and here they are

assignment - questions and answers

ShangAI Ex 5 Solutions
Thanks and have fun :)
Abishek

ShanghAI lecture assignment 4

The next in this series of experiments involved understanding

1. Principle of cheap design
2. Emergent Behavior
3. Braitenberg Design

A famous experiment performed at Zurich was study of emergent behavior using a set of robots called the swiss cleaning robots.

The scenario is a number of blocks (garbage) are dispersed in a closed arena. Robots are needed to form heaps of the blocks thereby "cleaning the arena"

If the aim of your robot is to clean the room, conventional design requires a vision system in the robots to identify the location of the blocks, pushing them when encountered and avoiding the other robots.

But using the principle of cheap design, robots fitted with Braitenberg obstacle avoidance scheme are used to achieve this. How? The solutions are posted.

ASSIGNMENT

ShanghAI Exercise4

SOLUTION

Exercise 4 - Study Group 160

ShanghAI lecture assignment 3

This was a very exciting assignment. An evolutionary algorithm was used to evolve a robot dog using webots so that it is able to run for the longest time without tripping. Three scenarios were considered

1. Evolution of the brain alone
2. Evolution of the morphology alone
3. Co-Evolution of the brain and the morphology

All three scenarios were studied and a number of questions regarding the benefits of each case was answered. Find the solutions to assignment 3 here.

Assignment 3

ShanghAI Exercise Sheet 3 Minidog

Solution

Exercise 3 - Study Group 160

Thanks,
Abishek

ShanghAI lecture assignment 2

Hi,

The first assignment of this lecture series was to on general intelligence. The second assignment was more interesting and was based on passive dynamic walkers

Passive Dynamic Walkers are mechanical devices that can walk down a slope without any actuation. They are usually inspired by the human legs and, despite a complete lack of motors and sensors, display a very natural-looking walking motion. I am posting the solutions to this assignment here. I once again thank my team members Miss Stephanie Wartenburg, Miss Denise Reiser and Miss Xiong qu for working with me on all assignments.

ShanghAI ExerciseSheetPDW

SOLUTION

AI Exercise 2 - Study Group 160

ShanghAI lectures

I wanted to learn about artificial intelligence. What is a better way than to join a lecture series conducted by an expert in this field from one of the leading universities in the world?

Welcome to ShanghAI lectures.

ShangAI Lectures are a series of online lectures on Natural and Artificial Intelligence. A global classroom of students from different parts of the world get together, online, to know about the cutting edge research that is going on in the field of artificial intelligence.

http://shanghailectures.org/

The class is 3 hours in length through video conferencing. The classes are conducted by professor Rolf Pfiefer from the AI lab in Zurich. It starts off with the professor discussing a topic in front of the class. This is an interactive session where questions will be directed to different global classrooms on the topics being discussed. This is followed by guest lectures from eminent speakers on the field of robotics and artificial intelligence.

The lectures are held over a span of three months with a number of assignments where students are put together in a group and work together on assignments. The assignments are designed to provide a beginner with insight on the different methods adopted in the circles of artificial intelligence. The students get to learn and use Webots simulator which is a powerful simulator for simulating robots in a "real life" setting where they are subjected to forces programmed. (ex gravity).

Lecture Topics
A wide variety of topics are discussed on intelligence, thinking and artificial intelligence. An introduction is given on what is intelligence and artificial intelligence. The landscape is then described using the myriad of developmental robotic projects being carried out. Important concepts such as frame of reference and synthetic methodology are explained with very good examples by professor Rolf.

The properties on intelligent systems and the principles involved in designing them are explained beautifully in detail. The difference in real and virtual worlds and hence the need of an embodied approach was explained in a wonderful way. The different principles of designing agents were detailed with a number of examples for each principle driving home the importance of each principle.

The concept of how locomotion is essential to cognition, two seemingly unrelated activities, was elegantly described by professor Rolf. The assignments provided a deep insight on how "design is out and evolution is in". Evolutionary algorithms were used to describe how the parameters of a robotic dog can be varied to optimize it for a particular fitness. The fitness was the longest distance traversed without falling in case of the robot dog. The ways in which artificial evolution and neural networks are used in the the modern world was mind boggling.

The lectures took a dive into the science fiction path when they described how collective intelligent behavior can be used to have swarm of robots. Modular robots can be used to modify their morphology to achieve different functions. These discussions were very interesting and have made me more curious into this evolving field of artificial intelligence.

Group 160
I was assigned to a group which is proudly called group 160. We worked together on the assignment projects and it was a wonderful experience. There was a rich sharing of information and ideas as we worked on the assignments. It was amazing working with such hard working and extremely talented individuals. The group was also assigned a highly motivating mentor who graded our assignments and provided us with feedback, helped us when we got stuck and motivated us throughout the course. The dynamics of the group was almost perfect even when we had not known/seen each other before. I still have not seen any of my group mates still :) . I had a wonderful time working in group160 with very knowledgable people in my team.

Acknowledgement
I want to thank my team members Miss. Stephanie Wartenburg, Miss. Denise Rieser and Miss. Xiong qu for their active participation in the assignments, keeping me motivated and also providing me with a great amount of knowledge in this otherwise obscure field :). I also want to thank our supervisor Mr. Naveen Kuppuswamy for his motivation and valuable feedback.

Installing ROS on mac

The errors encountered when installing ROS in a MAC is documented here.

ROS installation in MAC

Installation of ROS in MAC
http://www.ros.org/wiki/electric/Installation/OSX

Error 1
When installing ROS in MAC, there comes a point where a number of tools are required to be installed. The installer automatically generates the scripts required to install the tools. It asks for your password. But the terminal sort of crashed and did not accept even if my password was correct.

The solution to this is we need to manually install the tools before installing ROS.

Dependencies in MAC -
sudo port install py26-pil
sudo port install py26-numpy
sudo port install google-test
sudo port install log4cxx
sudo port install boost
sudo port install py26-paramiko

run the ROS installer command from http://www.ros.org/wiki/electric/Installation/OSX

Error 2:
rosinstall command not found.
roslocate command not found


Solution:
export PATH=$PATH:/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin


RXGRAPH
rosmake rxtools
Running rxgraph gives the following error 
Error - ImportError: No module named gobject

Solution
The problem here is the symbolic link to python.
make sure the link to python in /usr/bin points to /opt/local/bin/python2.6
sudo mv /usr/bin/python /usr/bin/python_old
sudo ln -fsv /opt/local/bin/python2.6 /usr/bin/python

rosdep install rxtools
rosdep install rxgraph

Make sure all the following dependencies are met
sudo port install graphviz
sudo port install py26-cairo py26-gobject py26-gtk py26-wxpython
sudo port install py26-gtk

rosdep satisfy [package_name]

http://www.php-architect.com/blog/2009/02/25/installing-python-pygtk-on-mac-osx/
http://answers.ros.org/question/1364/rxgraph-no-module-named-gobject-os-x

ROS - Robot Operating Systems

You can find my notes in installation of ROS in a mac and the tutorials that are available on their website
here.

ROS - meta operating system for your robot. It provides hardware abstraction, low level device control, implementation of commonly used functionality, message passing between processes and package management.

Ot provides tools and libraries for obtaining, building, writing and running code across multiple computers. 

Communication in ROS - several different sytles of communication
1. synchronous RPC style communication over services
2. asynchronous streaming of data over topics
3. storage of data on a peremeter server.

ROS is not realtime framework though it is possible to integrate

ROS file system level -
1. Packages - are used to organize software. packages contain runtime processes (nodes), ROS dependent library, datasets config files
2. Manifests - contain metadata about packages
3. stack - aggregation of packages to perform a function. ex navigation stack
4. Stack Manifest - metadata about stacks.
5. Message types : data structures for messages sent in ROS.
6. Service types - request and response data structures for services.

ROS Computation Graph Level -
Computation Graph - a peer to peer network of ROS processes that are processing data together. The concepts of computation graph are

1. nodes - processes that perform computation. It is an executable file within an ROS package. It uses a ROS client library to communicate with other nodes. Nodes can publish or subscribe to a topic. It can also provide or use a service

2. master - ROS master provides name registration and lookup to the rest of the computation graph. The master enables the nodes to find each other, exchange messages or invoke services

3. parameter server - allows data to be stored by key in a central location. Part of master.

4. messages - similar to c structs. used to communicate between the nodes

5. services - Request/Reply - 2 data structures, one for request the other for reply. A node offers a service under a name. A client uses the service by sending a request to the node and waiting for a response. This is presented to the programmer as a remote procedure call.

6. topics - messages routed via the publish/subscribe semantics. A node publishes a message under a topic. A node interested in certain kind of data will subscribe to that topic. There may be multiple concurrent publishers and subscribers in a topic.  publishers and subscribers do not know each other. this is done to decouple the production and consumption of information.

7. bags - format for saving and playing back ROS message data. used to store data like sensor data that can be difficult to collect.

MEthodology
1. ROS master stores topics, services and registration information of all nodes
2. nodes communicate with the master to provide registration information
3. nodes make connections with other nodes using information present in the ROS master
4. Master callbacks nodes when registration information changes.

nodes connect to other nodes directly.  The commonly used protocol is TCPROS. The master acts like a DNS server. TCPROS uses TCP/IP sockets

Command line remapping of names - A compiled program can be recompiled at runtime to operate in a different computation graph topology. This is done using the names. 

Names
Graph Resource Names - provide encapsulation in ROS. Each resource in defined within a namespace which may share other resources. Resources can create resources within their namespace and they can access resources within or above their namespace. connections can be made between resources in different namespaces but this is achieved by integrating the code above both namespaces.

valid names
1. first character should be alpha character or tilde  or forward slash /
2. subsequent characters can be alphanumeric underscore forward slashes

Resolving
4 types of graph resource names in ROS
1. base    - base
2. relative    - relative/name
3. global     - /global/name
4. private     -˜private/name


Client libraries
Collection of code that is used for programming. lets us create ROS nodes, publish and subscribe to topics, write and call services and use the parameter server.
C++ and Python support
rospy, roscpp


Installation of ROS in MAC
http://www.ros.org/wiki/electric/Installation/OSX

Error 1
When installing ROS in MAC, there comes a point where a number of tools are required to be installed. The installer automatically generates the scripts required to install the tools. It asks for your password. But the terminal sort of crashed and did not accept even if my password was correct.

The solution to this is we need to manually install the tools before installing ROS.

Dependencies in MAC -
sudo port install py26-pil
sudo port install py26-numpy
sudo port install google-test
sudo port install log4cxx
sudo port install boost
sudo port install py26-paramiko

run the ROS installer command from http://www.ros.org/wiki/electric/Installation/OSX

Error 2:
rosinstall command not found.
roslocate command not found

Solution:
export PATH=$PATH:/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin


Tutorials
Assume ROS is installed in ros_sw folder
The file system is found inside the ros_sw. It is composed of
1. packages - contains libraries, tools etc. lowest level of ROS software organization
2. package manifests - description of a package, defines dependencies between packages
3. stack - collection of packages to form a higher level library
4. stack manifests - information on stack

File system tools.
rospack suite -
To get information about packages and stacks
rospack find [package name]
rosstack find [stack name]

rosbash suite -
1. change directory to a package or stack  - roscd [locationname[/subdir]]
2. list - rosld [locationname[/subdir]]


Tutorial - Creating a ROS package
roscreate-pkg - create package
rospack - list package dependencies

1. roscreate-pkg [package_name] [depend1][depend2][depend3]

2. rospack
rospack profile - to make changes to the path so that new directories are found
rospack find [package]

roscreate-pkg = ros+create-pkg : generates all the files needed to create a ROS package
rospack = ros+pack(age) : provides information related to ROS packages
rosstack = ros+stack : provides information related to ROS stacks

If rospack fails, that implies that your workspace is not listed in the ROS_PACKAGE_PATH. Open .bashrc and add this at the end. (after sourcing setup.bash line)
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/Location/to/workspace


BUILDING A PACKAGE
1. rosdep install [package] _ install system dependencies required by ROS packages
2. rosmake [package] - to build a package we created
3. rosmake [package1] [package2] [package3]

NODES
Client Libraries
1. rospy - python client library
2. roscpp - C++ client libraries

3. roscore - first thing you should run when using ROS
4. rosnode  list - shows a list of all running  nodes
5. rosnode info [node] - shows more information about a node
6. rosrun [package_name] [node_name] - Run a particular node from a package 

RXGRAPH
rosmake rxtools
Running rxgraph gives the following error 
Error - ImportError: No module named gobject

Solution
The problem here is the symbolic link to python.
make sure the link to python in /usr/bin points to /opt/local/bin/python2.6
sudo mv /usr/bin/python /usr/bin/python_old
sudo ln -fsv /opt/local/bin/python2.6 /usr/bin/python

rosdep install rxtools
rosdep install rxgraph

Make sure all the following dependencies are met
sudo port install graphviz
sudo port install py26-cairo py26-gobject py26-gtk py26-wxpython
sudo port install py26-gtk

rosdep satisfy [package_name]

http://www.php-architect.com/blog/2009/02/25/installing-python-pygtk-on-mac-osx/
http://answers.ros.org/question/1364/rxgraph-no-module-named-gobject-os-x

Wednesday, November 9, 2011

Running a JAVA applet program

This is to test if JAVA is installed properly. A Java applet program which is compiled without using and IDE. The procedure is as follows

Applet Hello world
Running it from the console without any IDE

A. Creating a class extending the applet class
1. open your favourite editor and type in the following code
public class HWApplet extends java.applet.Applet
{
    public void paint(java.awt.Graphics g)
    {
        g.drawString("greetings",50,50);
    }
}
2. Save the file as HWApplet.java

B. Creating a HTML file to run the applet

1. Open your editor and type in the following code
<APPLET code="HWApplet.class" width=350 height=200></APPLET>
2. Save it as HW.html in the same directory as the HWApplet.java file

C. Compile the Java program
1. you can compile the Java program by going into the folder containing the file and using Javac
javac HWApplet.java

D. Running the Applet

1. Open your browser and make sure you have JRE installed and enabled. look here on details how to enable JAVA in your browser
http://www.java.com/en/download/help/enable_browser.xml
2. Open the previously created HW.html file in the browser. it should display a "greetings" message

Running a JAVA applet in firefox
1. make sure you have installed the Java Runtime Environment
sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts
2. In firefox -> tools -> Add-ons -> Plugins make sure the Java plugin is enabled

Installation of Netbeans IDE in Linux


Installation of NETBEANS IDE in linux
1. Download netbeans from http://netbeans.org/downloads/ (choose the version depending on your system)
2. After download is complete, cd to the download location you will find a netbeans-ver.sh script
3. open terminal, cd to the location of the .sh file and type
chmod u+x netbeans-ver.sh
(changes the execute permissions)
4. Then type "./netbeans-ver.sh" to execute the shell script
5. The installer pops up and you can specify the destination for installtion. (say ~/netbeans-ver)
6. Agree to terms and conditions and complete the installation
7. After installation is done open ~/.bashrc file in your favourite editor (.bashrc is a hidden file)
8. Add the follwing lines to the end of the file
 export PATH=$PATH:/location-to-netbeans/lib
(for example in this case where the location is ~/netbeans-ver type export PATH=$PATH:~/netbeans-ver/lib)
9. close the terminal and open it again and type "netbeans" to open the IDE.
10. It takes a few seconds to open the IDE. Have fun :)

Abishek

Installation of Sun JAVA 6 in Ubuntu 11.04

Hello,

There are a number of websites that explain how to install Java 6 on your Ubuntu machine. Here I have recorded the installation of JAVA in a brand new Ubuntu 11.04 machine.

You need to install JDK and JRE to get Java up and running in your system.

Installing JAVA 6 in ubuntu 11.04 Natty

1. Installing JRE - Java Runtime Environment
sudo add-apt-repository ppa:ferramroberto/java
sudo apt-get update
sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts

2. Installing JDK
sudo apt-get install sun-java6-jdk

Testing if installation is fine
1. open terminal
2. type "javac -version"
it displays the version of java compiler if installation is fine

http://www.ubuntugeek.com/install-jre-in-ubuntu-11-04-natty-using-ppa.html

Setting up the SDK for NAO in MAC

SDK
The source developer kit allows you to write your own Cpp or python script to be executed by the NAO. This post explains how to set up the SDK in Mac.


Download and Installation of NAO SDK
1.     Download SDK from http://users.aldebaran-robotics.com/ -> software -> downloads
2.     Download cmake from http://www.cmake.org/cmake/resources/software.html and install
3.     Extract the SDK to a location (say: /path to/sdk/)
4.     export DYLD_LIBRARY_PATH= /path to/sdk/lib
5.     export DYLD_FRAMEWORK_PATH = /path to/sdk/lib
6.     export PYTHONPATH = /path to/sdk/lib
7.     go to /path to/sdk/modules/src/examples/helloworld/
8.     mkdir build
9.     cd build
10.  cmake –DCMAKE_TOOLCHAIN_FILE=/path to/sdk/toolchain-pc.cmake ..
11.  make
No errors must occur

-Cmake and the toolchain works properly in MAC no problems

LINKS
http://users.aldebaran-robotics.com/docs/site_en/reddoc/sdk/using_cmake.html

Abishek

Working with Choreographe - Hands on tutorial


Working with choreographe

 Preliminary steps
1. Open Choreographe
2. Open NAOSIM
3. Connect choreographe to local NAO as explained in previous posts,

Then,
1.     In the box library, choose templates – animation box. Drag and drop it on the flow diagram area
2.     Double click on the animation box, timeline pops out
3.     The time line has a number of frames. Frames are similar to the movie frames, which are played one after the other to show movement on screen.
4.     Key frames are frames that indicate a particular important position that we are interested in. other frames in the intermediate show the transition between key frames.
5.     Click on a frame at any index other than index 1 (say index 5). A blue line shows that frame is the key frame.
6.     You can specify a particular position for a limb by clicking on the limb from the 3D NAO.
7.     The motion window is displayed. Change the position of the limb according to your requirement.
8.     Click again on the timeline at an index greater than the previously chosen index (say index 20).
9.     Click on the limb and change its position again as mentioned in steps 6 and 7.
10.  Now click on the  “Play” icon in the motion timeline to see the animation in the NAO 3D window.
11.  You can delete a key frame by right clicking on the key frame and clicking delete.
12.  It is similar to adobe flash frame animation.

Abishek

Virtual Simulation using NAOSIM



NAOSIM  
NAOSIM is used to simulate the NAO in a virtual environment. Make sure NAOSIM, CHOREOGRAPHE, NAOQI are installed.

Setting up NAOSIM and CHOREOGRAPHE
1.     Launch CHOREOGRAPHE
2.     Launch NAOSIM
3.     In NAOSIM click on the start button (the play button) to start the virtual NAO
4.     In CHOREOGRAPHE, click connect and select the local NAO which has the name of the computer

Handling objects in NAOSIM
1.     Open the NAOSIM window
2.     Click on view – objects
3.     Select an object and click on the location where you want the object to be placed.
4.     You can rotate, move and resize the object using the icons that are present on the NAOSIM toolbar
5.     To delete an either select the object and press delete key (Fn+backspace in Mac) or go to view – explorer and select the object and press the delete key (Fn+bakcspace in Mac).

Testing behavior in NAOSIM
1.     Create a behavior in CHOREOGRAPHE  (example endless walk inside motion in the box library)
2.     Start the simulation
3.     You can see NAO performing the behavior in the NAOSIM window
4.     To stop the simulation, click on the stop button in the CHOREOGRAPHE window and not the NAOSIM.
5.     If you click on the stop button in the NAOSIM window, the connection with CHOREOGRAPHE gets terminated and you need to connect again.
6.     You can see what NAO is seeing using view – camera

Errors
Errors: Some times NAOSIM shows an blank window as shown in fig.

Solution
This is due to zooming in too close or a bug in NAOSIM, you can work around it by
1.     Click view – explorer
2.     Click on an item in the list
3.     Press F key
4.     The window focus is on the item selected which fixed the issue

Using Choreographe to program the NAO


Using CHOREOGRAPHE
·      After CHOREOGRAPHE is installed, open it from the applications folder
·      Connect to the NAO robot, (after checking out whether it is connected to the network using its IP address as described in previous post), using the connect icon
·      Enable the “Use fixed IP/Hostname” check box and type in the IP address of the NAO robot (press the center button of NAO and he will tell you his IP address)
·      After a connection is established, you will see the NAO in the NAO 3D window of CHOREOGRAPHE simulating the original NAO
·      You can program commands on the program window and have NAO execute them using the play button.
Documentation for CHOREOGRAPHE - http://users.aldebaran-robotics.com/docs/site_en/greendoc/choregraphe/choregraphe.html

Abishek

Setting up NAO for the first time

You need a wireless router to connect to the NAO for the first time and to set up a wireless connection in NAO. The steps are as follows.


CONNECTING TO THE NAO
 Installation of three software from the CD
1. CHOREOGRAPHE
2. NAOQI
3. NAOSIM

Mandatory Step (Before a wireless connection is set up):
·      You need to connect NAO to a wired connection in order to set up a wireless connection.
·      Connect the NAO robot to a port on the router and your laptop on another port.
·      Turn the robot on.
·      Press the center button. If the robot is connected, it will say an IP address.
·      Open the web browser and type the IP address
·      A login page will be displayed. Use “nao” for both the username and password.
·      Alternatively you can use “bonjour” app that comes with safari (MAC) to connect to nao (open safari -> bookmarks -> show all book marks and click on “bonjour” in the left pane)
·      Once wired connection is setup, you can click on the network tab to setup a wireless connection.
·      The next time NAO automatically connects to the known wireless connection.

Beginning NAO

Hey,

I got a new NAO to play with. I am recording the steps I followed in order to set it up and get it running. The following series is from a beginners perspective on working with the NAO robot. Hope someone out there finds it useful.

I am using a MAC for NAO though the softwares are available for Windows, Mac and Linux. For linux, the cross compilers etc have been tested with Ubuntu 10.10 (Meerkat). The cross compilers do not work with 11.04. So if you are using Linux use Ubuntu 10.10 for the "less" time consuming approach.

Have fun,
Abishek

Monday, July 4, 2011

playing wmv files in ubuntu

How to play windows media player formats (wmv etc) on ubuntu -  In the synaptic package manager, search for ubuntu-restricted and install the restricted codecs.

Thursday, June 16, 2011

Generating 16k ROM using Xilinx IP COREGEN and simulating it in modelsim


The instruction ROM is an IP Core. so before interfacing with the open8, it has to be generated. The method of generating and simulating a ROM Xilinx IP Core is described here.

FIND ALL THE FILES HERE
1. app.coe (the initialization file)
2. rom_16k_core.vhd
3. rom_16k_core.vho
4. rom_16k_core.xco
5. top_level.vhd
6. do_memgen.do

Creation of the ROM
Xilinx 10.1
1. open ISE
2. create a new project
3. tools -> core generator(12.1) (or right click on the device and add a new file 10.1)
4. In the IP catalog -> Memory and storage elements -> RAM and ROM
5. double click on block memory generator, A new window opens
6. In the new window select single port ROM click next, Write first mode
7. Select
Read Width = 8 and Read Depth = 16384 for 16K ROM -> next
8. The output ports are unregistered, load initialization COE if required -> next
9. No need to use the Reset pin -> next
10. Generate. (takes a little time then shows successfully generated)


This generated ROM has to be connected to the Open8 and functions as the program memory. The ROM provides a VHDL file. needs to be connected to the open8

Simulation using Modelsim
1. The ip core is generated in the ipcore_dir directory inside the current project
2. The most important files are the .vhd, .xco,.vho, .mif
3. Simulate the .vhd file as any other vhdl file. copy the .xco file into the simulation directory and the .vho contains information on how to instantiate the ip core

The simulation directory contains .vhd,.vho,.xco,.mif

4. For simulation it is essential that you compile the xilinx libraries namely unisim, simprim and xilinxcorelib.(mainly xilinxcorelib because it contains the definition for the ipcore).
5. Write a top level that instantiates the memory as a component and write a test bench to test the memory created

ERROR: Error: Could not find xilinxcorelib.blk_mem_gen_v7_2.
Make sure you have compiled the xilinx libraries unisim, simprim and xilinxcorelib in modelsim.

BUG in open8 - solved - It is not a bug but a misunderstanding, THANK YOU Mr. SETH HENRY

Hi,

There was a misunderstanding regarding to the bug I had encountered while using open 8 core. The bug is that there was a displacement of 1 cycle in the processor code while fetching the return address executing the "RTI" instruction. It is described in detail here.

This is not actually a bug because the processor was pipelined in such a way that the data was to be read from the memory in a span of 2 cycles while my assumption about the memory model was that data was fetched in 1 cycle. This pipelining was done in order to increase the frequency of operation.


So the memory model is described as follows - 16 k single ported ROM in the write first mode. width = 8 and depth = 16k (16384). The pipeline operation is described here as a stand alone project. (not connected to the open8)


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity rom_16k is
port(
  Clock                 : in  std_logic;
  --
  Bus_Address           : in  std_logic_vector(15 downto 0);
  Rd_Enable             : in  std_logic;
  Rd_Data               : out std_logic_vector(7 downto 0)
);
end entity;

architecture behave of rom_16k is

  constant User_Addr    : std_logic_vector(15 downto 14) := "00";
  alias Comp_Addr       is Bus_Address(15 downto 14);
  signal Comp_Addr_q    : std_logic_vector(15 downto 14);

  alias ROM_Addr        is Bus_Address(13 downto 0);

  signal Rd_Enable_q    : std_logic;
  signal Rd_Data_i      : std_logic_vector(7 downto 0);

  component rom_16k_core
port (
clka: IN std_logic;
addra: IN std_logic_VECTOR(13 downto 0);
douta: OUT std_logic_VECTOR(7 downto 0));
  end component;

begin

  RAM_proc: process( Clock )
  begin
    if( rising_edge(Clock) )then
      Comp_Addr_q       <= Comp_Addr;
      Rd_Enable_q       <= Rd_Enable;
      Rd_Data           <= (others => '0');
      if( User_Addr = Comp_Addr_q )then
        if( Rd_Enable_q = '1' )then
          Rd_Data       <= Rd_Data_i;
        end if;
      end if;
    end if;
  end process;

  U_ROM_CORE : rom_16k_core
  port map(
    addra             => ROM_Addr,
    clka              => Clock,
    douta             => Rd_Data_i
  );


It had described in my earlier post the supposed bug






"It is to be seen in the waveform that when rd_data line has the return address (151 in our case) the cache_ctrl is idle. "


This will work fine if the memory model is a 2 stage pipeline before the data is read from the memory. as shown in this figure

It is seen that in this memory model, the address is present before the first clock cycle while the data is read only in the second clock cycle.

How to generate the memory in xilinx and simulate it? it is another story in itself and is described here.

Hence there was no bug in the open8 core. This was elegantly explained to me by Mr. Seth Henry who is the author of the processor. He shared with me the memory model in his mail and helped correct my concept. I truly consider it an honor getting a detailed reply from him. Thank you Mr. Seth Henry. Long live open source.

Wednesday, May 18, 2011

OpenSPARCT1 - Synthesizing only the Instruction Fetch Unit in ISE

In order to study the Instruction Fetch Unit, I thought the RTL schematic view of ISE would be a useful tool. So i collected all the necessary files to synthesize the Instruction Fetch Unit alone of the OpenSPARCT1 core. Here I document the steps


The files that are required for IFU are present in OpenSPARCT1/design/sys/iop/sparc/rtl/Flist.ifu

Xilinx 10.1 is to be used.
Steps
1. Open xilinx10.1
2. create a new project IFU_Sparc
3. Open OpenSPARCT1/design/sys/iop/sparc/rtl/Flist.ifu
4. Add all the files that are specified in the file to the new project
5. Add all the files that are present in design/sys/iop/sparc/ifu/rtl
5. Add all the header files present in /opensparc/design/sys/iop/include
6. Added all the files inside design/sys/common/rtl to the project (simplicity sake)
7. Add all files inside design/sys/srams/ to the project (simplicity sake)
8. Add files OpenSPARCT1/lib/u1.behV and OpenSPARCT1/lib/m1.behV. Rename the files to u1behV.v and m1behV.v so that they are identified as verilog files. make sure they are added to the project

The next step is to set the compile time macros: To do this:
(make sure "sparc_ifu.v" is the top module)
1. Look for the ISE sub-window on the left labeled "Processes"
2. Find the "Synthesize-XST" entry in that window
3. Right click on that entry and select "Properties"
4. In the popup window "Process Properties - Synthesis Options,
select "synthesis options in the left window
5. Set the property display level to "Advanced"
6. In the right list scroll down to find the property
"Verilog Macros"
7. Type the value FPGA_SYN FPGA_SYN_1THREAD FPGA_SYN_NO_SPU FPGA_SYN_8TLB in that box.
8. now DESELCT "process->properties->xilinx specification options->add i/o buffers"
9. Synthesize
10. View RTL schematic.

Error: bw_r_irf_register not found
Find the file bw_r_irf_register in the sources window of ISE
set it as the top module and synthesize
set sparc_ifu.v as the top module and resynthesize

Tuesday, May 17, 2011

LFS - Binutils


INSTALLING BINUTILS package
Shifted to www.linuxfromscratch.org - Linux From Scratch - version 6.8 (the book was outdated so shifting to the website by the same other) - It starts with installation of binutils and not BASH. no problem though.

The main modifications I made is shifted the sources from /usr/src to a dedicated folder at $LFS/sources
The location where the tools are to be installed is $LFS/tools. A symbolic link is created for the same in the host systems

INSTALLATION OF BINUTILS
check for $LFS, $LFS_TGT else
export LFS=/mnt/lfs
export LFS_TGT=$(uname -m)-lfs-linux-gnu

1. download the Binutils-2.21.tar.gz into the $LFS/sources
2. tar xvzf binutils-2.21.tar.gz - extracts into a folder called binutils-2.21
3. mkdir $LFS/sources/binutils-build
4. cd $LFS/binutils-build
5. ../binutils-2.21/confiure --targer=$LFS_TGT --prefix=/tools --disable-nls --disable-werror
6. make
7. make install

LFS_TGT contains the description of the system. The config.guess inside binutils-2.21 contains information on the description of the machine assumed.
--prefix=/tools - tells the configure script to install in the /tools directory
--disable-werror - prevents build from stopping if there are warnings in host compiler

Cannot run the test scripts now because the testsuite framword (Tcl, Expect and DejaGNU is not available yet).

Abishek Ramdas
NYU Poly

LFS - BASH - compilation and installation


DOWNLOADING  REQUIRED PACKAGES
1. Downloading bash - (bash-4.2)
http://ftp.gnu.org/gnu/bash/ - download the latest tar.gz file. I downloaded bash-4.2.tar.gz
It is put inside the folder $LFS/usr/src

* as root (sudo -i) cd into the folder $LFS/usr/src/bash-4.2
* ./configure --enable-static-link --prefix=$LFS/usr --disable-nls --without-bash-malloc
* make

+ERROR: /usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/libc.a(malloc.o): In function `malloc':
(.text+0x4ad0): multiple definition of `malloc'
./lib/malloc/libmalloc.a(malloc.o):/mnt/lfs/usr/src/bash-4.2/lib/malloc/malloc.c:1254: first defined here
+SOLUTION:
./configure --enable-static-link --prefix=$LFS/usr --disable-nls --without-bash-malloc (INCLUDE "--without-bash-malloc") in the configure option.
+REFERENCE:
http://www.linuxforums.org/forum/programming-scripting/129616-multiple-definitions-compliling-error.html
+make succeded

* make prefix=$LFS/usr install
* mv $LFS/usr/bin/bash $LFS/usr/bin/bashbug $LFS/bin
* cd $LFS/bin
* ln -s bash sh


Testing if bash is installed properly
*cd $LFS/bin
*./sh
It should open a new shell which contains information on the version installed. Bash is hence installed successfully.

Abishek Ramdas
NYU Poly

LFS - Creating a partition


These steps are quite straight forward no errors were encountered. Follow the procedure described in
http://www.linuxfromscratch.org/lfs/view/stable/chapter02/chapter02.html

CREATING A PARTITION

I used Gparted tool to create the partition. The tool is quite straight forward to use. You can download it from the package manager. here is the tutorial - http://www.dedoimedo.com/computers/gparted.html

Created a partition using the steps described here
http://www.linuxfromscratch.org/lfs/view/stable/chapter02/creatingpartition.html

Created a partition - 50 GB /dev/sda1 (primary partition)
                        3 GB /dev/sda4 (primary partition for swap)
(note : in my system I have linux (Ubuntu 9.10 karmic koala) installed in logical partition sda5 and swap is in logical parition sda6. primary partition sda2 is extended to create logical partitions.)

MOUTING THE NEW PARTITION

mkdir /mnt/lfs
mount /dev/sda1 /mnt/lfs
export $LFS = /mnt/lfs


CREATING DIRECTORIES
FILE HEIRARCHY STANDARDS : http://www.pathname.com/fhs/
going to root mode in ubuntu - sudo -i
inside /mnt/lfs
create dirctories bin boot dev dev/pts etc home lib mnt proc root sbin tmp var

Create two more folders /usr and /usr/local
inside /usr create bin etc include lib sbin share src tmp var
inside share create following folders dict, doc, info, locale, man, nls, misc, terminfo, zoneinfo
inside share/man, create folders man1 man2 man3 man4 man5 man6 man7 man8
inside the /usr folder create symbolic links to the share/man, share/doc and share/info

inside /usr/local
inside share create following folders dict, doc, info, locale, man, nls, misc, terminfo, zoneinfo
inside share/man, create folders man1 man2 man3 man4 man5 man6 man7 man8
inside the /usr folder create symbolic links to the share/man, share/doc and share/info
(basically repeat the same steps).

Abishek Ramdas
NYU Poly

Building Linux From Scratch

hi,
For long I wanted to build a custom linux system from scratch. Since now I am in my summer hols, I finally find time to do it. I am doing it for a hobby and documenting the procedure I followed, errors that I got and how I have solved them if I have solved them. Hope this documentation serves useful to the people.



IMPORTANT - describes the variables that are used,

1. sudo -i is used to go into the superuser mode in ubuntu
2. $LFS = /mnt/lfs - the partition where linux is being built from scratch is mounted into this location
3. all the packages that are to be installed are to be present in $LFS/usr/src
4. $LFS_TGT=$(uname -m)-lfs-linux-gnu


INDEX
1. Creating a partition
2. Mounting the partition
3. Creating Directories based on the File Hierarchy Standards (FHS)
4. Installing Bash
5. Installing Bin utils

Tuesday, May 3, 2011

READ ME for SOBOL QUASI RANDOM NUMBER GENERATOR

********************************************************************
Quasi Random Number Generator
Abishek Ramdas
********************************************************************
Single threaded implementation
File name - quasi_rand_gen_modification.c

How to run -
at the command prompt

$gcc quasi_rand_gen_modification.c (return)
$./a.out (return)

Output:
Requests:  Number of patterns to be generated and Dimensions
File - QRNG_Patterns_sngl_thrd.txt in the same folder which contains the C file.

********************************************************************
Multiple threaded implementation
File name - quasi_rand_gen_pthreads.c

How to run -
at the command prompt

$gcc -pthread quasi_rand_gen_modification.c (return)
$./a.out (return)

Output:
Requests:  Number of patterns to be generated, Dimensions and Number of cores
File - QRNG_Patterns_pthreads.txt in the same folder which contains the C
file.

********************************************************************
Testing Driver

In the linux system there is a binary called diff

Usage : diff filename1 filename2 (return)

Result : gives the differnce between the two files. gives no output if the two files are the same.

syntax
$diff QRNG_Patterns_sngl_thrd.txt QRNG_Patterns_pthreads.txt

*********************************************************************
Additional information
1. Make sure the number the same number of patterns are generated for single threaded and multi threaded version.
2. Make sure the dimensions provided are also the same.
3. A sleep signal is provided for 2 seconds before the output is printed on the screen in the multi threaded part. so if it looks like it hanged please wait.
********************************************************************

Sobol Quasi Random Number Generator single thread version

#include<stdio.h>
#include<stdlib.h>
#include<error.h>
#include<errno.h>
#include"nrutil.h"

#define MAXBIT 30
#define MAXDIM 6
#define DEBUG 1

void sobseq(int *, float []);

int main(int argc, char *argv[])
{
  int n,i;
  float x[100];
  for(i=0;i<100;i++)
    x[i]=0;
  n=-1;
  sobseq(&n,x);
  //  for(i=0;i<100;i++)
  //  printf("%f",x[i]);
  n=4;
  sobseq(&n,x);
  for(i=0;i<100;i++)
    printf("%f\n",x[i]);
 n=5;
  sobseq(&n,x);
  for(i=0;i<100;i++)
    printf("%f\n",x[i]);
  return 0;
}

void sobseq(int *n,float x[])
{
  int j,k,l;
  unsigned long i,im,ipp;
  static float fac;
  static unsigned long in,ix[MAXDIM+1],*iu[MAXBIT+1];
  static unsigned long mdeg[MAXDIM+1]={0,1,2,3,3,4,4};
  static unsigned long ip[MAXDIM+1]={0,0,1,1,2,1,4};
  static unsigned long iv[MAXDIM*MAXBIT+1]={0,1,1,1,1,1,1,3,1,3,3,1,1,5,7,7,3,3,5,15,11,5,15,13,9};
  printf("n = %d\n",*n);
  if(*n<0)
    {
      for(k=1;k<=MAXDIM;k++) ix[k]=0;
      in=0;
      if (iv[1] != 1) return;
      fac=1.0/(1L << MAXBIT);
      if(DEBUG)
    {
      printf("debug:\n");
      printf("n: %d\n",*n);
      printf("fac: %1.30f\n",fac);
      printf("1L: %ld\n",1L);
      printf("end debug\n");
    }
      for (j=1,k=0;j<=MAXBIT;j++,k+=MAXDIM)
    {
      //iu is array of arrays. contains the address of each element of array iv
      //initialization iu so that addresses of iv are loaded in to iu
      iu[j] = &iv[k];
      if(DEBUG)
        {
          printf("j= %d,k = %d:\t%ld\n",j,k,*iu[j]);
        }
    }
      for (k=1;k<=MAXDIM;k++)
    {
      for (j=1;j<=mdeg[k];j++)
        {
          if(DEBUG)
        {
          printf("mdeg = %ld\n",mdeg[k]);
          printf("iu[%d][%d] = %ld\n",j,k,iu[j][k]);
          printf("(maxbit-%d) = %d\n",j,(MAXBIT-j));
        }
          //initialize vi values
          iu[j][k] <<= (MAXBIT-j);
          if(DEBUG)
        {
          printf("iu[%d][%d] = %ld\n",j,k,iu[j][k]);
          printf("(maxbit-%d) = %d\n",j,(MAXBIT-j));
        }
          printf("\n");
        }
      for(j=mdeg[k]+1;j<=MAXBIT;j++)
        {
          ipp=ip[k];
          i=iu[j-mdeg[k]][k];
          i ^= (i >> mdeg[k]);
          for (l=mdeg[k]-1;l>=1;l--)
        {
          if (ipp & 1) i ^= iu[j-l][k];
          ipp >>= 1;
        }
          iu[j][k]=i;
          printf("iu[%d][%d]: %f\n",j,k,iu[j][k]*fac);
        }
    }
    }
  else
    {
      printf("inside else\n ");
      im=in++;
      for(j=1;j<=MAXBIT;j++)
    {
      if (!(im & 1)) break;
      im >>= 1;
    }
      if (j > MAXBIT) error(1,errno,"MAXBIT too small in sobseq");
      im=(j-1)*MAXDIM;
      printf("IMIN %d\n",IMIN(*n,MAXDIM));
      for(k=1;k<=IMIN(*n,MAXDIM);k++)
    {
      ix[k] ^= iv[im+k];
      x[k]=ix[k]*fac;
      if(DEBUG)
        {
          printf("x[%d] : %f\n",k,x[k]);
          printf("fac : %1.30f\n",fac);
          printf("iv[%ld] : %ld\n",im+k,iv[im+k]);
        }
    }
    }
}

Parallelized Sobol Quasi Random Number Generator using Pthreads

/*
********************************************************************
Quasi Random Number Generator - serial version
Abishek Ramdas
********************************************************************
Inputs :
1. Number of patterns (limit 64000) can be varied by varying the LIM paramter
2. Number of dimensions

Outputs:
All patterns are stored in file QRNG_Patterns_sngl_thrd.txt
the patterns are printed along the x axis and the dimensions are along y axis
********************************************************************
*/


#include<stdio.h>
#include<stdlib.h>
#include<error.h>
#include<errno.h>
#include"nrutil.h"


#define LIM 64000 //limitng the number of patterns generated to max of 64000
#define MAXBIT 30
#define MAXDIM 6
#define DEBUG_INIT 0
#define DEBUG_SEED 0
#define DEBUG_SOBOL 0
#define DEBUG_SOBOL_E 0

float random_numbers[MAXDIM][LIM];//dynamic declaration of 2D array is not possible

int main(int argc, char *argv[])
{
  int loop,init=1;
  unsigned long in_G,in_temp,no_of_vectors;
  int dim;//number of values to be generated
  int *n = &dim;
  float x[6];
  char filename[]="QRNG_Patterns_sngl_thrd.txt";//file contains patterns for a single threaded execution
  FILE *fp;
  fp=fopen(filename,"w");

  //  no_of_vectors = 20;

  int j,k,l;
  unsigned long i,im,ipp;
  static float fac;
  //  static unsigned long in,ix[MAXDIM+1],*iu[MAXBIT+1];
  unsigned long in,ix[MAXDIM+1],*iu[MAXBIT+1];
  static unsigned long mdeg[MAXDIM+1]={0,1,2,3,3,4,4};
  static unsigned long ip[MAXDIM+1]={0,0,1,1,2,1,4};
  static unsigned long iv[MAXDIM*MAXBIT+1]={0,1,1,1,1,1,1,3,1,3,3,1,1,5,7,7,3,3,5,15,11,5,15,13,9};

  printf("Enter the number of vectors required:");
  scanf("%ld",&no_of_vectors);
  printf("Enter the dimensions:");
  scanf("%d",n);
  printf("single threaded version\n");
  if(init==1)
    {
      //      printf("initializing... \n");
      for(k=1;k<=MAXDIM;k++) ix[k]=0;
      in=0;
      if (iv[1] != 1) return;
      fac=1.0/(1L << MAXBIT);
      if(DEBUG_INIT)
    {
      printf("debug:\n");
      printf("n: %d\n",*n);
      printf("fac: %1.30f\n",fac);
      printf("1L: %ld\n",1L);
      printf("end debug\n");
    }
      for (j=1,k=0;j<=MAXBIT;j++,k+=MAXDIM)
    {
      //iu is array of arrays. contains the address of each element of array iv
      //initialization iu so that addresses of iv are loaded in to iu
      iu[j] = &iv[k];
      if(DEBUG_INIT)
        {
          printf("j= %d,k = %d:\t%ld\n",j,k,*iu[j]);
        }
    }
      for (k=1;k<=MAXDIM;k++)
    {
      for (j=1;j<=mdeg[k];j++)
        {
          if(DEBUG_INIT)
        {
          printf("mdeg = %ld\n",mdeg[k]);
          printf("iu[%d][%d] = %ld\n",j,k,iu[j][k]);
          printf("(maxbit-%d) = %d\n",j,(MAXBIT-j));
        }
          //initialize vi values
          iu[j][k] <<= (MAXBIT-j);
          if(DEBUG_INIT)
        {
          printf("iu[%d][%d] = %ld\n",j,k,iu[j][k]);
          printf("(maxbit-%d) = %d\n",j,(MAXBIT-j));
        }
        }
      for(j=mdeg[k]+1;j<=MAXBIT;j++)
        {
          ipp=ip[k];
          i=iu[j-mdeg[k]][k];
          i ^= (i >> mdeg[k]);
          for (l=mdeg[k]-1;l>=1;l--)
        {
          if (ipp & 1) i ^= iu[j-l][k];
          ipp >>= 1;
        }
          iu[j][k]=i;
        }
    }
    }
 
  //Generate SEED for a particular index of random number
  in = -1;//in - index of (n-1)random number
  im = in++;
  in_G=in;
  in_temp = in;
  in_temp >>= 1;
  in_G ^= in_temp;
  if(DEBUG_SEED)
    {
      printf("Random # index : %ld\n",in);
      printf("Random # index in Gray in_G : %ld\n",in_G);
      printf("Generating random numbers from index: %ld\n",in+1);
    }
  for(k=1;k<=IMIN(*n,MAXDIM);k++)
    {
      in_G=in;
      in_temp = in;
      in_temp >>= 1;
      in_G ^= in_temp;
      if(DEBUG_SEED)
    {
      printf("ix[%d] =",k);
    }

      for(loop=0;loop*MAXDIM<(MAXBIT*MAXDIM+1);loop++)
    {
      //if LSB in in_G =0 then dont xor else xor
      if((in_G&1))
        {
          ix[k]^=iv[k+(loop*MAXDIM)];
          in_G >>= 1;
           if(DEBUG_SEED)
        {
          printf("iv[%d+%d]^",k,loop*MAXDIM);
        }
        }
      else
        {
          in_G >>= 1;
        }
    }
      if(DEBUG_SEED)
    {
      printf("\nseed value for rand #%ld : ix[%d]=%ld",in,k,ix[k]);
      printf("\n");
    }
    }

  //SEED is generated
  //Generate the random numbers next

  for(i=0;i<no_of_vectors;i++)//i is the number of random numbers to be generated
    {
      im=in++;
      if(DEBUG_SOBOL_E)
    {
      printf("in=%ld\n",in);
      printf("im=%ld\n",im);
    }
      for(j=1;j<=MAXBIT;j++)
    {
      if (!(im & 1)) break; //identify the location of the right most 0 in im. it is indicated by j
      im >>= 1;
      if(DEBUG_SOBOL_E)
        {
          printf("im2=%ld\n",im);
        }
    }
      if (j > MAXBIT) error(1,errno,"MAXBIT too small in sobseq");
      im=(j-1)*MAXDIM;
      if(DEBUG_SOBOL_E)
    {
      printf("j : %d\n",j);
      printf("im3=%ld\n",im);
      printf("IMIN %d\n",IMIN(*n,MAXDIM));
    }
     
      for(k=1;k<=IMIN(*n,MAXDIM);k++)
    {
      if(DEBUG_SOBOL)
        printf("ix[%d] = %ld\n",k,ix[k]);

      ix[k] ^= iv[im+k];
      x[k]=ix[k]*fac;
      random_numbers[k-1][i]=x[k];
      if(DEBUG_SOBOL)
        {
          printf("ix[%d]^= iv[%ld] => %ld ^= %ld => %f\t",k,im+k,ix[k],iv[im+k],x[k]);
      //          printf("fac : %1.30f\n",fac);
      //          printf("iv[%ld] : %ld\n",im+k,iv[im+k]);
        }

      if(!DEBUG_SOBOL)
        {
          printf("%f  ",x[k]);
        }
    }
      printf("\n");
     
    }
    printf("\nFinal Result\n");
  for(k=0;k<IMIN(*n,MAXDIM);k++)
    {
      for(i=0;i<no_of_vectors;i++)
    {
      //  printf("%f  ",random_numbers[k][i]);
      fprintf(fp,"%f  ",random_numbers[k][i]);//%f2spaces
    }
      fprintf(fp,"\n");
      //      printf("\n");
    }
  fclose(fp);
  printf("Random Numbers are stored in ./%s\n",filename);
  return 0;
}