Monday, April 28, 2014

University of Maryland, College Park - Compilation of places to stay



For accommodation usually there are four major communities where most of Indians live (easy to find roommates).

a) Sevens Spring Apartments : Cheap, Spacious. But, 2 mile far away from campus. Shuttles every 40 min during weekdays. No service during weekends. On weekends you have to take METRO buses which runs every 40 min to 60 min and costs $1.60 (this is constant and standard rate for all Maryland and  DC busses).

b) Graduate Hills and Graduate gardens: Cheap (Subsidized for grad students), Not too much spacious. But, very difficult to get in first year. It has huge pre booking queue. They require $100 deposit to be in queue for pre-booking. (MOST of PhD prefer this). Considerably near to campus. Shuttle every 15-20 min. Late night shuttle till 3 am. On weekends, During day NO CAMPUS SHUTTLE. Option of METRO BUS (cost same $1.6) or 30 min walk to Dr. S. K. Gupta’s lab (Usually my lab mates walk).

c) Parkside or University Club: Moderate ($400 - $470 per person if you share with 3 other students), very near and convenient 7 min walk to Dr. S. K. Gupta’s lab.

d) Town house: This is not apartment bldg. Considerably cheap. ($350 - $500). This are huge house with 4 -5 bedrooms with common kitchen and living room etc. You can mostly get your own room. They are considerably near. Several location of these kind of houses. You have to find rite roommates to live with.

Courtesy :
1. Student's Council of India (SCI).
2. My very helpful senior, Mr. Brual Shah.



Thursday, April 24, 2014

Fundamentals of Digital Image and Video Processing - Week 3 Solutions


This week's assignment was quite challenging, considering the fact that I'm novice to Matlab programming! Anyways, after hours of hard programming, I nailed it! Full 3 points :)

Here is the question number 8 of week 3.
In this problem you will get hands-on experience with changing the resolution of an image, i.e., down-sampling and up-sampling. Follow the instructions below to finish this problem. (1) Download the original image from here. The original image is an 8-bit gray-scale image of width 479 and height 359 pixels. Convert the original image from type 'uint8' (8-bit integer) to 'double' (real number). (2) Recall from the lecture that in order to avoid aliasing (e.g., jagged edges) when down-sampling an image, you will need to first perform low-pass filtering of the original image. For this step, create a 3×3 low-pass filter with all coefficients equal to 1/9. Perform low-pass filtering with this filter using the MATLAB function "imfilter" with 'replicate' as the third argument. For more information about low-pass filtering using MATLAB, refer to the programming problem in the homework of Week 2. (3) Obtain the down-sampled image by removing every other row and column from the filtered image, that is, removing the 2, 4, all the way to the 358 row, and then removing the 2, 4, all the way to the 478 column. The resulting image should be of width 240 and height 180 pixles. This completes the procedure for image down-sampling. In the next steps, you will up-sample this low-resolution image to the original resolution via spatial domain processing. (4) Create an all-zero MATLAB array of width 479 and height 359. For every odd-valued i∈[1,359] and odd-valued j∈[1,479], set the value of the newly created array at (i,j) equal to the value of the low-resolution image at (i+12,j+12). After this step you have inserted zeros into the low-resolution image. (5) Convolve the result obtained from step (4) with a filter with coefficients [0.25,0.5,0.25;0.5,1,0.5;0.25,0.5,0.25] using the MATLAB function "imfilter". In this step you should only provide "imfilter" with two arguments instead of three, that was the case in step (1). The two arguments are the result from step (4) and the filter specified in this step. This step essentially performs bilinear interpolation to obtain the up-sampled image. (6) Compute the PSNR between the upsampled image obtained from step (5) and the original image. For more information about PSNR, refer to the programming problem in the homework of Week 2. Enter the PSNR you have obtained to two decimal points in the box below.


Here's my attempt at the code...
I=imread('D:\Image processing\digital-images-week3_quizzes-original_quiz.jpg'); % read the image
I2=im2double(I); % convert the uint8 image to double
B = [1/9, 1/9, 1/9; 1/9, 1/9, 1/9; 1/9, 1/9, 1/9]; % create the 3x3 array
C = imfilter(I2, B, 'replicate'); % apply the filter
C2=C; % just to make sure the original image is intact, I'm copying it into another dummy
C2(2:2:end,:)=[]; % clear the even rows
C2(:,2:2:end)=[]; % clear the even columns
IDownScale = C2; % just a legit name
NullMatrix=zeros(359,479); % create the NULL matrix
k=2; % a constant used below in checking even rows and columns
for i=1:359 % for loop for row
if rem(i,k) ~= 0 % filter out odd rows
for j=1:479 % for loop for columns
if rem(j,k) ~= 0 % filter out odd columns
NullMatrix(i,j) = IDownScale((i+1)/2,(j+1)/2); % copy downscaled image elements to appropriate places
end
end
end
end
ConvolveFilter=[0.25,0.5,0.25;0.5,1,0.5;0.25,0.5,0.25]; % create the convolution filter
Final = imfilter(NullMatrix, ConvolveFilter); % apply the filter
MSE = mean(mean((I2 - Final).^2,2)); % get the MSE
MaxI=1;% the maximum possible pixel value of the images.
PSNR1=10*log10((MaxI^2)/MSE); % get the PSNR
PSNR1

cheers,
Vijay.

Saturday, April 19, 2014

Running a stepper motor through ATMEGA16

When it comes to position control, and if we are talking about precision in the range of micro meter or nano meter, there is strictly no substitute to servo motors and linear motors. Here are videos of some of the projects we have done at Parker.


This is the link to what a linear motor means.

So, why don't we just start using servo motors for all applications? Its fast, precise and compact right? But, if I tell you the cost of a servo motor-drive package, you would probably be baffled! You can buy hundreds of stepper systems for the cost of just ONE servo system. So, does that mean servo motors are seldom used because of their prohibitively high costs? The answer is a big NO. "It is the application that demands which product to select and then comes the cost" - as my boss usually says!

Ok. Now that we understand the urge to go for a cheaper alternative, we end up with stepper motors and DC geared motors for most/all of educational and hobby projects. These products are easy to setup and economical. They can be run by a simple microprocessor like 8085.

Now we'll see how to interface and run a stepper motor from ATMEGA16 microcontroller. The same procedure applies to all controllers. Here is the link to download its datasheet.

ATMEGA16 is a 8-bit high performance microcontroller of Atmel's Mega AVR family with low power consumption. It is based on enhanced Reduced Instruction Set Computing (RISC) architecture, and supports 131 powerful instructions (most of which execute in one machine cycle). It can be clocked at a maximum frequency of 16MHz.

ATMEGA16 had 16 KB of programmable flash memory, 1 KB of static RAM and 512 B of EEPROM, with an endurance cycle of 10000 and 100000 for RAM and EEPROM respectively. It is a 40 pin IC with 32 digital I/O divided uniformly across 4 ports, namely, PORT A, PORT B, PORT C and PORT D. Mentioned below is a brief description of the individual pins.

Pin No.
Pin name
Description
Alternate Function
1
(XCK/T0) PB0
I/O PORTB, Pin 0
T0: Timer0 External Counter Input.
XCK : USART External Clock I/O
2
(T1) PB1
I/O PORTB, Pin 1
T1:Timer1 External Counter Input
3
(INT2/AIN0) PB2
I/O PORTB, Pin 2
AIN0: Analog Comparator Positive I/P
INT2: External Interrupt 2 Input
4
(OC0/AIN1) PB3
I/O PORTB, Pin 3
AIN1: Analog Comparator Negative I/P
OC0 : Timer0 Output Compare Match Output
5
(SS) PB4
I/O PORTB, Pin 4
In System Programmer (ISP)
Serial Peripheral Interface (SPI)
6
(MOSI) PB5
I/O PORTB, Pin 5
7
(MISO) PB6
I/O PORTB, Pin 6
8
(SCK) PB7
I/O PORTB, Pin 7
9
RESET
Reset Pin, Active Low Reset

10
Vcc
Vcc = +5V

11
GND
GROUND
12
XTAL2
Output to Inverting Oscillator Amplifier
13
XTAL1
Input to Inverting Oscillator Amplifier
14
(RXD) PD0
I/O PORTD, Pin 0
USART Serial Communication Interface
15
(TXD) PD1
I/O PORTD, Pin 1
16
(INT0) PD2
I/O PORTD, Pin 2
External Interrupt INT0
17
(INT1) PD3
I/O PORTD, Pin 3
External Interrupt INT1
18
(OC1B) PD4
I/O PORTD, Pin 4
PWM Channel Outputs
19
(OC1A) PD5
I/O PORTD, Pin 5
20
(ICP) PD6
I/O PORTD, Pin 6
Timer/Counter1 Input Capture Pin
21
PD7 (OC2)
I/O PORTD, Pin 7
Timer/Counter2 Output Compare Match Output
22
PC0 (SCL)
I/O PORTC, Pin 0
TWI Interface
23
PC1 (SDA)
I/O PORTC, Pin 1
24
PC2 (TCK)
I/O PORTC, Pin 2
JTAG Interface
25
PC3 (TMS)
I/O PORTC, Pin 3
26
PC4 (TDO)
I/O PORTC, Pin 4
27
PC5 (TDI)
I/O PORTC, Pin 5
28
PC6 (TOSC1)
I/O PORTC, Pin 6
Timer Oscillator Pin 1
29
PC7 (TOSC2)
I/O PORTC, Pin 7
Timer Oscillator Pin 2
30
AVcc
Voltage Supply = Vcc for ADC
31
GND
GROUND
32
AREF
Analog Reference Pin for ADC
33
PA7 (ADC7)
I/O PORTA, Pin 7
ADC Channel 7
34
PA6 (ADC6)
I/O PORTA, Pin 6
ADC Channel 6
35
PA5 (ADC5)
I/O PORTA, Pin 5
ADC Channel 5
36
PA4 (ADC4)
I/O PORTA, Pin 4
ADC Channel 4
37
PA3 (ADC3)
I/O PORTA, Pin 3
ADC Channel 3
38
PA2 (ADC2)
I/O PORTA, Pin 2
ADC Channel 2
39
PA1 (ADC1)
I/O PORTA, Pin 1
ADC Channel 1
40
PA0 (ADC0)
I/O PORTA, Pin 0
ADC Channel 0
Now for some brief introduction to stepper motors. I had a 4 lead motor available with me. But, 6 leads and 8 leads also come as a standard design. These leads are nothing but wires of the individual winding. Other classification is unipolar or bipolar. But this depends on how you connect the wires, whether in series, or in parallel. Another factor to choose a stepper motor is the accuracy required. We have standard industrial stepper motors available upto 50,000 steps per rotation. i.e. the shaft rotates once, if 50,000 pulses are given. If you are perplexed as to why we are talking about steps here, consider that a stepper motor has 50,000 ppr (pulses per rotation). Its minimum angle of rotation will be 360/50000 = 0.0072 degrees! See that? It becomes very precise as the number of steps increases. We can also implement micro-stepping to further enhance the accuracy. Higher number of steps leads to another hidden advantage - the motor performs a very smooth motion without any jerking. 

We know that a microcontroller can source only a few tens of milli amperes at the outputs. How do we get to drive such high currents required to energize the motor windings? Well we use a motor driver to achieve this task. I prefer L293D, which is a simple H bridge motor driver. What it does is simply takes the input from the microcontroller, amplifies it and gives this amplified output to run the motor.

Now that we know a brief background of our controller and motor, we will proceed to interfacing the products. As with any microcontroller, we need to provide 5 volt regulated supply to the IC. I use a IC7805 to regulate 12 VDC produced from a RPS. Then, to generate the clock frequency, I use a crystal oscillator. Next, I rig up the USART interfacing set-up to burn the code. We need ports to plug in motor cables and sensors, right? So, I solder ports to help me connect the cables. Since many cables are required to be soldered, its better to go for a printed circuit board (PCB). You could get an evaluation version of eagle or proteus (I used proteus) and do the PCB designing. Trust me, after an hour of watching online youtube videos, PCB designing using these softwares is a cakewalk. You could print the inverted image of this Gerber on a A4 sheet using an inkjet printer (preferably print the design several times on the same sheet) and reverse iron it on the PCB base. Now, dip this PCB into ferric chloride solution and rub off the ink transferred onto the PCB (while you pressed the paper) with some thinner or nail polish remover.

(OR) simply get one these cool development kits from an online store, as I did :p Trust me, it saves hell a lot of time and efforts, let alone the money. I bought one from Robosapiens India. The kit included a development board, a programming interface, an USB cable and an instruction CD. The CD contained the programming software, AVR View, the program transferring tool, Burn-O-Mat and Win AVR. The language used to program was embedded C, which when compiled was converted into RISC instructions and transferred to the controller.


This one's the burner.

We'll write a basic program to run a stepper motor now. This program will run the stepper motor one rotation forward and one rotation reverse.

#define F_CPU 12000000UL
#include
#include
int i;
int main(void)
{
DDRD=0xFF;
for(i=10;i!=0;i--)
{
PORTD=0b00110100;
_delay_ms(50);
PORTD=0b00111000;
_delay_ms(50);
PORTD=0b01110000;
_delay_ms(50);
PORTD=0b10110000;
_delay_ms(50);
}
_delay_ms(1000);
for(i=10;i!=0;i--)
{
PORTD=0b10110000;
_delay_ms(50);
PORTD=0b01110000;
_delay_ms(50);
PORTD=0b00111000;
_delay_ms(50);
PORTD=0b00110100;
_delay_ms(50);
}
}

As you may have spotted, I had connected the stepper motor leads to PORTD. With minor modifications in the code, you can run the motor, one rotation forward and one rotation reverse, indefinitely. Got it? Yes, put a "while(1)" instruction at the top of the code!

Happy playing with your stepper motor! :)

-Cheers,
Vijay.