Thursday 26 March 2020

Ising Model simulation Code

MATLAB code for the Ising model simulation is given in this post. Try Yourself.

You can access ready-made simulation of this in your phone with the following Android app https://play.google.com/store/apps/details?id=com.gaurtavm.randomprocesssimulation


MATLAB CODE:

a=200;  %height
b=200;  %width
T=1;    %Temprature
steps=10000000;
img=2*(randi(2,a,b)-1)-1;  % Random 2D array containing +1 and -1
for i=1:steps
    x=randi(a,1);
    y=randi(b,1);
    tmp=(img(mod(x-1-1,a)+1,y)+img(mod(x+1-1,a)+1,y)+img(x,mod(y+1-1,b)+1)+img(x,mod(y-1-1,b)+1));
    E=-img(x,y)*tmp;   %Energy
    r=rand;
    if E>0
        img(x,y)=-img(x,y);
    elseif E<=0 && r<exp(E)/T
        img(x,y)=-img(x,y);
    end
   
    if mod(i,10000)==0   %update image after 10000 steps
        imshow(((img+1.0)/2))
        fprintf("%d\n",i)
    end
end


OUTPUT:


Monday 16 March 2020

My Android Apps on google play store

In this post, ill tell you about android apps I published and their use

Photo Noise Editor:  With help of this app you can add various kinds of noise to your photos. It is different from other apps in a way that you can pause the noise addition process at any time and save your photos. A small demo of app is given in the GIF image below.
App Link:  https://play.google.com/store/apps/details?id=com.gaurtavm.photonoiseadder




Virtual Line follower: This app lets you create a line follower inside your phone. This Line follower can have as many sensors as you want in a straight-line fashion.
The main purpose of this app is to make complex line followers easily. For example, it is a very hard task to make a PID line follower and tune Kp, Ki and Kd values but this application makes it easy. You can try those things in this app that are out of your budget for a practical line follower.
You can draw a path of your choice for the bot. That is a very time consuming and expensive task in practical line follower.
Blog page: https://crackeconcept.blogspot.com/2020/03/virtual-line-followerline-foll.html
 
The app is available on google play store. Link for the app is: https://play.google.com/store/apps/details?id=com.gaurtavm.virtuallinefollower








Probability Simulations: This app contains a number of coded simulations that are mostly related to probability theory. The animation helps to understand the process well. There are adjustable parameters for each simulation you can play with the values.  My motivation to make this app is to let the user visualize these processes easily through these simulations.
Currently Available simulations in the app are
- Discrete-time Markov Chain (DTMC)
- Ising Model 2D
- Random Walk 1D
- Random Walk 2D
- Diffusion-limited aggregation (DLA)
Link: https://play.google.com/store/apps/details?id=com.gaurtavm.randomprocesssimulation

Flexible Whiteboard: This app lets you draw on a small area on screen and view drawing on full screen. It is very useful for tablets where screen size is big. You don't have to take your hands everywhere to draw, just draw on a small area which is also adjustable.
Features:
- Zoom-In and Zoon-Out
- Instant sharing of drawing
- Adjustable drawing area
- ARGB brush control
- Brush width control
App Link: https://play.google.com/store/apps/details?id=com.gaurtavm.flexiblewhiteboard


Sunday 15 March 2020

Virtual PID Line Follower

When you are making a PID line follower there are a lot of problems. How many sensors to use? What should be coefficients? What should be the distance between sensors for your problem? One cannot afford to buy so many sensors and changing distance between sensors is a very time-consuming process.
For best performance, you have to tune Kp, Ki, and Kd. Tuning these parameters of a PID line follower is a very hard task. You have to keep changing value and burn the code again and again to the microcontroller. With the help of this app, you can learn easily how to tune these values.


PID Algorithm:

Initialize I=0,error=0,last_error=0
1. Read all sensors output s0,s1,s3...,sn which can be either 0 or 1. 


2. Calculate current Position using.
 if (s0+s1+s2+...+sn>0) then current_position=(s0*b0+s1*b1+s2*b2+..+sn*bn)/(s0+s1+s2+...+sn)

else current_position=s0*b0+ s1*b1+ s2*b2+...+ sn*bn
Where b0, b1, b2,..., bn are sensor coefficients. These sensor cofficients are decided by us. For example, for 5 sensors cofficients can be 
b0=10, b1=20,b2=30,b3=40,b4=50 ,For these cofficients our set point shoud be 30 which is the middle sensor cofficient value.

3. Find error using,  
error = set_position- current_position
set_position contains the value where the error should be zero.

4. Set I=I+error

5. pid_error = kp*error + ki*I + kd*(error-last_error)

6. Remember current error in last_error variable. last_error = error
7. Set motor speeds:  
if (pid_error<0) then left_motor=max_speed, right_motor=max_speed+pid_error

else left_motor=max_speed-pid_error, right_motor=max_speed

8. Limit output speed. if(left_motor>max_speed) then left_motor= max_speed
if(left_motor< -max_speed) then left_motor= -max_speed 
if(right_motor> max_speed) then right_motor= max_speed 
if(right_motor< -max_speed) then right_motor= -max_speed

Saturday 14 March 2020

Virtual Line Follower

This post is about the Virtual line follower android app. This app lets you learn about line follower without any complex circuit. In this app, you can adjust parameters like the number of sensors, the distance between sensors which is a very time consuming and costly task to do with a practical line follower. You can write your own logic and run the robot.
If you don't have an android device then you can download any Android emulator available and run this app.

Let us look at the geometry of the robot.
Following parameters of line follower bot are adjustable
1. The number of sensors. You can use as many sensors you want in a straight array fashion.
2. Distance between sensors (x): Distance between sensors can be chosen in terms of pixel length. The distance between consecutive sensors is the same for all sensors.
3. Distance between motors (L) can also be changed.
4. The distance of the sensor array from the motor axis can be changed.
5. Sensors are arranged from left to right as shown in the figure below.
Line Follower Geometry


The sensor state is written from the leftmost sensor to the rightmost sensor. For example for two sensors S0, S1 possible states are 00, 01, 10, 11.
Motor output can be from -1 to +1. Where -1 is for maximum reverse speed and +1 for maximum forward speed.

Examples to try inside the app:

1) Two sensors:

for "00" state go forward by left motor=1 and right motor=1 
for "01" state go right by left motor=1 and right motor=0 
for "10" state go left by left motor=0 and right motor=1  
for "11" state go forward by left motor=1 and right motor=1 

Inside App, the following should be input
Sensor state:
00
01
10
11

Left Motor:
1
1
0
1

Right Motor:
1
0
1
1

2) Three sensors:

for "001" and "011" states go right by left motor=1 and right motor=0 
for "110" and "100" state go left by left motor=0 and right motor=1  
for "010" state go forward by left motor=1 and right motor=1 
Otherwise, go forward in simple robot. 

Inside App, the following should be input
Sensor state:
001
011
100
110
010

Left Motor:
1
1
0
0
1

Right Motor:
0
0
1
1
1

For PID go here https://crackeconcept.blogspot.com/2020/03/virtual-pid-line-follower.html


the app is out! Try now.