Dear Friends,
Since I finished my PhD degree at QUT, I have found a research position in a Chinese university named Central South University. Due to the internet censorship in Chinese mainland, it is not straightforward to use google service. This blog is totally closed without any updates from my side. Please feel free to check out my recent status using my research lab website (http://ami.csu.edu.cn)
Thanks.
Hu He
hehuvision
I personally would like to post something relating to my own interests, such as my research interests(visual odometry, 3D reconstruction, segmentation, energy minimisation), hobbies(photography, cooking) ...
Monday, 5 September 2016
Friday, 5 April 2013
How to use Latex to prepare the academic CV?
In the post, I attached a academic resume template in Latex that I stolen from Web, and I am also keen to helping someone who just needs it.
Note that I also include some chinese characters in my CV, in case you modify it for your purpose, you should use XeLatex to compile or use Latex after removing the following lines:
One snapshot of the CV can be viewed as follow:
Note that I also include some chinese characters in my CV, in case you modify it for your purpose, you should use XeLatex to compile or use Latex after removing the following lines:
Meanwhile the bibliography is managed using bibtex. I put all the publications in a single file (*.bib), and then I include them in tex file.%%% Chinese typesetting %%%%%%%%%%%\usepackage{xeCJK}\setCJKmainfont{STFangsong}\XeTeXlinebreaklocale "zh"\XeTeXlinebreakskip = 0pt plus 1pt
One snapshot of the CV can be viewed as follow:
Monday, 10 December 2012
Associate file with specified program
Under windows OS, sometimes file might have the incorrect or improper association with application program. How to associate the file with the customized program, the straightforward way is right click file, and then select properties, and associate the program with file in the "Open with" pop-up window.
However, this might not work sometimes, especially when you install the same program with different version on the same machine. You might not link to the program using the above method.
In order to solve this issue, you should open register (click "start" -> run -> regedit), and then find
HKEY_CLASSES_ROOT\Applications\Binary file that you want to associate\Shell\new\command, and assign the value of variable as the path of this binary program.
However, this might not work sometimes, especially when you install the same program with different version on the same machine. You might not link to the program using the above method.
In order to solve this issue, you should open register (click "start" -> run -> regedit), and then find
HKEY_CLASSES_ROOT\Applications\Binary file that you want to associate\Shell\new\command, and assign the value of variable as the path of this binary program.
Tuesday, 28 August 2012
What if Finder froze and crash in your Mac?
Today after I search on google for Finder crashing in my Mac, I found this brilliant solution.
From: http://www.statusq.org/archives/2011/08/16/3495/
Geeky post to help those who might be Googling for this stuff. To anyone who saw the title and came here hoping to read about an accident-prone safari guide, my apologies.I know people have mixed experiences with Mac OS X Lion, but for me it’s been almost all good, and I’m very happy with the upgrade.
I did, however, run into a curious problem today on one of my machines, which took a while to sort out. The Finder was crashing and rebooting repeatedly, each time asking me if I wanted to restore the windows it had been displaying before.
I tried all sorts of things: moving stuff off the desktop, deleting the Finder’s preferences file, unmounting drives, booting in safe mode… but in the end it proved to be the Trash that was causing the problem.
I started Terminal (which is always in my Dock, but you can start from Spotlight if you don’t have a Finder running) and did:
sudo rm -rf ~/.Trash
…after which my world came back to normality again. (You’ll need to type your admin password).
Hope that’s useful for someone out there!
Sunday, 26 August 2012
Refer to http://www.cprogramming.com/tutorial/bitwise_operators.html
It is a good article addressing what the bitwise is in c/c++ programming language.
Basically, BitWise can be used as multiplication and division with factor of corresponding power of 2 depending on leftshift or rightshift, and logical operation such as AND, OR, XOR, ~.
There are also times when you need to use bitwise operators: if you're working with compression or some forms of encryption, or if you're working on a system that expects bit fields to be used to store boolean attributes.
Works on bits for left argument, takes an integer as a second argument
Works on the bits of both arguments
Skills and knowledge You also know a couple of neat tricks that you can use when performance is critical, or space is slow, or you just need to isolate and manipulate individual bits of a number.
It is a good article addressing what the bitwise is in c/c++ programming language.
Basically, BitWise can be used as multiplication and division with factor of corresponding power of 2 depending on leftshift or rightshift, and logical operation such as AND, OR, XOR, ~.
When should you use bitwise operators?
Bitwise operators are good for saving space -- but many times, space is hardly an issue. And one problem with working at the level of the individual bits is that if you decide you need more space or want to save some time -- for instance, if we needed to store information about 9 cars instead of 8 -- then you might have to redesign large portions of your program. On the other hand, sometimes you can use bitwise operators to cleverly remove dependencies, such as by using ~0 to find the largest possible integer. And bit shifting to multiply by two is a fairly common operation, so it doesn't affect readability in the way that advanced use of bit manipulation can in some cases (for instance, using XOR to switch the values stored in two variables).There are also times when you need to use bitwise operators: if you're working with compression or some forms of encryption, or if you're working on a system that expects bit fields to be used to store boolean attributes.
Summary
You should now be familiar with six bitwise operators:Works on bits for left argument, takes an integer as a second argument
bit_arg<<shift_argShifts bits to of bit_arg shift_arg places to the left -- equivalent to multiplication by 2^shift_arg
bit_arg>>shift_argShifts bits to of bit_arg shift_arg places to the right -- equivalent to integer division by 2^shift_arg
Works on the bits of both arguments
left_arg & right_argTakes the bitwise AND of left_arg and right_arg
left_arg ^ right_argTakes the bitwise XOR of left_arg and right_arg
left_arg | right_argWorks on the bits of only argument
~argReverses the bits of arg
Skills and knowledge You also know a couple of neat tricks that you can use when performance is critical, or space is slow, or you just need to isolate and manipulate individual bits of a number.
Tuesday, 21 August 2012
What kind of data type you should use?
Cited from http://www.programmersheaven.com/user/pheaven/blog/191-Float-Double-and-Decimal-do-you-know-the-differences/
Float, Double and Decimal: do you know the differences?
There are a number of data types available in the .Net framework for storing numbers with fractional parts. They are each appropriate for different situations, and using the wrong one can lead to errors in calculations.
Thinking About Accuracy
In some applications, you require that calculations involving numbers with fractional parts are exact. Examples of this are in financial applications, where losing the odd cent here and there in a calculation is unacceptable. Customers expect their accounts to be completely accurate, not to mention the tax man.In other applications, you don't care about exact results, but you are interested in having an answer that is correct to a certain number of significant digits. This is the case in experimental physics, for example. When you make a measurement of something, you can only measure it as accurately as your equipment will allow you. Therefore, you have an inherent error in that value already, which is going to cascade through any calculations you do with it. This means that while your computed answer may be 5.1826, you may know that the values this answer was calculated from were only accurate to three significant digits, and so the last two digits in this result (the 0.0026) don't matter. If there is a computational error in them, so be it - it's not going to hurt us.
Number Representations
There is more than one way to represent a number with fractional parts. Decimal represents the number as an integer, then also stores an integer power of ten (the exponent) that states where the decimal point is. The .Net decimal type allows you to shift it between 0 and 28 places to the left, so the most fractional places you can have is 28. Since both the value and the position of the point are represented as integer types, and because (with enough bits) we can represent any integer value exactly in binary, we can store the number exactly.Single and Double (also known as float and double, depending on your language) work differently. Glossing over a few details (but if you want them, look up the IEEE 754 standard), they are stored with both a mantissa (which specifies the digits making up the number) and an exponent, which specifies where the binary point goes. That is, we're working in base two for everything. Further, the mantissa is normalized, so your number is always stored as something of the form 1.10010101 (with only a single bit to the left of the point) followed by binary columns that represent a half, a quarter, and eighth and so forth.
The important thing to realize here is that many decimal numbers are not exactly representable in binary. Consider decimal 0.3, for example. If we try to represent it as the sum of powers of two, we end up with a sequence like 1/4 + 1/32 + 1/64 + 1/512 + ... - in fact, we never actually get to an exact value. We'd need infinitely many bits. This is not unique to binary; in decimal, for example, we can not specify 1/3 exactly. However, it does mean that we have the potential to lose data.
Range
The decimal data type uses 96 bits to store the number itself. There is a special bit for storing the sign, meaning that you get a range of -79,228,162,514,264,337,593,543,950,335 to 79,228,162,514,264,337,593,543,950,335, if you have no fractional parts. This is 29 digits, meaning that you can move decimal point all the way to just after the initial digit. This is, with the maximum exponent you get a range of -7.9228162514264337593543950335 to 7.9228162514264337593543950335.With floating point types (float and double), you store the mantissa in a normalized form, meaning you can shift the binary point in either direction to get really small or really large numbers. However, remember that unlike the decimal data type, you are not able to represent every value in the range. You get it accurate to a certain number of significant bits.
With a float, you can store numbers from -3.402823e38 to 3.402823e38, where e38 means "10 raised to the power of 38" - a bit of a wider range than with decimal. However, also interesting is the smallest positive or smallest negative number you can represent, which is around 1.4e-45 - really very tiny.
With a double, the range is -1.79769313486232e308 to 1.79769313486232e308, and the smallest is around 5e-324! While the range is greater, the main advantage of the double type isn't so much the extra range of values - due to a small increase in exponent size - but a big increase in precision by having a much larger mantissa. That is, you get a lot more significant digits.
Size In Memory
A float (Single) takes 32 bits of memory, a double takes 64 bits of memory and a decimal takes 128 bits of memory. Note that the reason a decimal is so much larger is because it can store a huge number of significant digits, giving a great deal of accuracy/precision. Note that a 32-bit float can only represent as many values as a 32-bit integer; you are trading in precision to get an increased range. It's worth noting that about half of the values you can represent with a floating point number are between -1.0 and 1.0.Performance
In any modern PC, your CPU will have a dedicated Floating Point Unit, which is a chunk of hardware that performs operations on floating point numbers (floats and doubles). However, in embedded environments you may not have an FPU available. If you do have an FPU, operations on floats and doubles will be fast (and the non-floating point execution units can also be used to do other integer computation in parallel, thanks to in-hardware optimization). If you don't and it is being emulated in software, it will be much slower.The exact performance differences in operations on floats and doubles is highly platform and application specific. We can certainly say that floats require double the memory, and thus twice as much CPU cache space, but how much that actually impacts performance is specific to how your application uses memory. Due to the fact that cache lines store multiple words anyway, there's not an obvious answer.
The decimal type does integer operations. Normally that would be faster than floating point ones, apart from there isn't dedicated hardware to deal with the 96-bit values, not to mention handling differences in the exponent, so it can wind up being much slower. If you didn't have an FPU, fixed point would likely beat floating point. It's the hardware support that makes the big difference here.
Conclusions
Always remember that floating point numbers can't represent every value in the range they cover, while decimal numbers can (though the range is somewhat smaller).The inability of floating point numbers to represent every possible value in the range they cover can have important consequences in application design. For example, adding a bunch of numbers smallest first to largest first can end up with a different result to if you had done the largest first and finished up adding on the smallest one. The reasons behind that are complex and for another post, but it's good to be aware that there are a lot of subtleties to worry about when working with floating point. The other big thing to avoid in most circumstances is comparing floating point values exactly, rather than checking that the difference between them doesn't lie in an acceptably small range.
Wednesday, 1 August 2012
AVR GCC I/O ports
This semester I will tute microcontroller course, unfortunately, I still confuse with microcontroller's I/O pins manipulation. Today, I found a really good tutorial from this website (http://iamsuhasm.wordpress.com/tutsproj/avr-gcc-tutorial/)
!The following contents are totally borrowed from that guy's website.!
!The following contents are totally borrowed from that guy's website.!
VR GCC Tutorial (1) – Basic I/O Operations
Atmel has come up with a whole range of superb AVR microcontrollers which are the dream of every hobbyist. However, the real icing on the cake is that these µControllers can be programmed with just a parallel port connector and nothing else!!!. However, Atmel µC’s have their downsides too. They have to be programmed in either Assembly or in C. There is one program – Bascom AVR – which reportedly allows programming in BASIC. But, unfortunately it doesn’t seem to work (?) with the el-cheapo parallel port programmers . So, the only option left is C, unless you are willing to dabble with Assembly.
I’ll attempt to give a brief introduction to basic I/O operations in C for AVR microcontrollers.
First of all, you need a programmer to program. As i told you, its all very simple, you just need a parallel port cable. Follow this excellent tutorial by The Real Elliot at Instructables.com
So, first make a simple programmer, test out the blinking LED program and then come back.
PS: Your programmer doesn’t have to include all the header pins, a board etc, that Real Elliot has shown in his tutorial. A basic parallel port connector with a few wires and resistors soldered directly on it is what i have been using from the past couple of months. It works just as well.
Before starting, there are a few things i would wish to tell. First of all, at first sight , (especially to those unacquainted to C), all this “_BV(PD4)” stuff may seem a little too cryptic. At one point, you probably will be tempted to ditch GCC and learn Assembly. However, i assure you that Assembly is much more frightening than AVR C. AVR C is not at all hard to learn, it just looks a bit alarming because of those weird symbols like << >> ~ which keep floating around. Once, you understand what all that is about, it’ll all be a piece of cake.
What you should know before reading this tutorial:
1) I expect that you are somewhat well acquainted with atleast any 1 high level programming language. (BASIC, Java, C/C++ etc)
2) I expect that you are reasonably comfortable with the C syntax. You do not need to know all the stuff that comes in the 10th and 11th chapters of C++ books. Just the basics – Program syntax, header files, functions, if then else, loops - should be enough.
3) I expect you to be comfortable with binary numbers, logic gates and Boolean algebra.
If the answer to any of the above is no , then brush up and then come back.
I also recommend that everyone goes through this excellent pdf to brush up you C skills in case they are a bit rusty.
The Port Control Registers
For easier access , the I/O pins on an AVR uC are grouped into a number of ports. Each port contains a number of pins ranging from 3 to a maximum of 8. To control these Ports , 3 registers have been provided. Each register controls a specific feature of the Port. Let us examine each Register one by one.
And , one more thing. Unfortunately , both the register PORTx and the Portx physical pins are referred to by the same name. To avoid confusion , i will be referring to the register as PORTx and the physical pins as Portx.
Defining a pin as either Input or Output – The DDRx Registers
If you take a look at the tiny2313 datasheet, it says something on the 1st page – “18 I/O lines”. This means that out of the 20 pins of tiny2313, 18 can be used as either input or output pins.
But then, immediately the doubt arises ”How do I tell the micro controller whether I want to use a pin as input or as output?”
For this purpose, there exists a register known as the DDRx register for every port. The “x” stands for the port alphabet. Every bit in the register controls a single pin of the port.
In case of the DDRx register, each bit controls the I/O of the respective port pin. I.e., the 5th bit controls the 5th pin of the PORT et cetera.
To make a pin work as Input, just write a LOW to its respective bit in the appropriate DDRx register.
To make a pin work as Output, just write a HIGH to its respective bit in the appropriate DDRx register.
Now suppose, i wanted to configure the 3rd and 7th pin of portb as output and the rest as input :
DDRB = 0b10001000;
Notice that the 7th and the 3rd bits are made high. And the rest are all LOWs. The above command, when executed, will configure PORTB as we selected.
Similarly, you do the same thing for other ports as well.
Suppose you wanted to make all the pins of portd as output:
PORTD = 0b11111111;
But, if you are a keen observer , you might have noticed one thing. PORTD has only 7 pins. However, we have written an 8 bit value to the DDRD register. So, what happens to the last bit? The answer is: nothing. Nothing happens. The eight bit is simply ignored by the microcontroller.
Making a pin go HIGH or LOW – The PORTx register
There is one more register that controls the HIGH/LOW status of a pin. That register is called the PORTx register. Every bit in the register controls the state of the respective bit in that port. i.e. the 5th bit controls the 5th pin of the port etc.
It has 2 functions:
Case 1 : To make a pin go high or low ( if it is an output pin).
DDRB = 0b10001111; /* Configuring I/O pins of portb */
PORTB = 0b10001010 /* Write this byte to PORTB */
Now, the 7th bit, 3rd bit and the 1st bit will be set. The 0th and 2nd bit will be reset. The other bits will be in a High-Z state as they are configured as input pins.
Case 2 : To activate / Deactivate pull up resistors.
The input pins of tiny2313 are generally in the Hi-Z state. This makes them prone to catching noise and picking up false signals. Hence, it is advisable to put a pull-up resistor to reduce noise. The resistor will normally hold the input pin at logic HIGH. Any external source can pull the voltage down to LOW when required.
Fortunately, Atmel has already included internal pull-up resistors. You can enable them by writing a HIGH to the appropriate bit of the PORTx register.
DDRB = 0b00000000; /* Configuring I/O pins of portb */
PORTB = 0b01110101; /*enable internal pull-up resistors on output pins 1 , 3 , 5 , 6 , 7 */
Reading the status of an Input Pin - The PINx register
To put it bluntly, the PINx register contains the status of all the pins in that port. If the pin is an input pin, then its corresponding bit will mimic the logic level given to it. If it is an output pin, its bit will contain the data that has been previously output on that pin.
DDRD = 0b00000000; /* Set all pins as input */
uint8_t status; /* Define a 8 bit integer variable */
status = PIND; /* Store the current value of PIND in status */
The above code will cause whatever input has been given to the 8 pins to be written to the variable status.
PS : Dont worry yourself if you cant understand the uint_8 stuff. All you need to understand is that we have just created a 8 bit variable with the name “status”. “uint8_t” in AVR C is kinda like the equivalent of “int” in ANSI C.
The Practical Stuff
Now that you know about the 3 registers , you are all set to actually start programming some real stuff. Why dont we program a running light sequence?
In our running light sequence , there will be 8 LEDs which will light up in sequence. It will be something very similar to a ring counter made using a CD4017.
Since ,we are using 8 LEDs , we must use a port that has 8 pins. That port in the Attiny2313 is the Portb.
So , first we must configure all the pins of Portb as output. For that we need to set all the bits in the DDRB register high.
DDRB = 0b11111111;
Now that we have configured the LEDs as output , we are now ready to start lighting the LEDs one by one. We will set each bit in PORTB register high one after the other , with a small delay in between
DDRB = ob11111111
PORTB = 0b10000000;
_delay_ms(50);
PORTB = 0b01000000;
_delay_ms(50);
PORTB = 0b00100000;
_delay_ms(50);
PORTB = 0b00010000;
_delay_ms(50);
PORTB = 0b00001000;
_delay_ms(50);
PORTB = 0b00000100;
_delay_ms(50);
PORTB = 0b00000010;
_delay_ms(50);
PORTB = 0b00000001;_
delay_ms (50);
With the above code , the LEDs will just run once and then stop. We need to it keep on running in a cycle like in a CD4017. To do that , let us add a infinite loop. We also have to declare the main function and include the all essential header files.
#define F_CPU 1000000UL /* Clock Frequency = 1Mhz */#include <inttypes.h>
#include <avr/io.h>
#include <util/delay.h>int main(){ // The main functionDDRB = 0b11111111; // Set all the pins of PortB as outputwhile (1) { // Set up an infinite loopPORTB = 0b10000000; // Turn on LED1
_delay_ms(50); // Wait
PORTB = 0b01000000; // Turn on LED2
_delay_ms(50); // Wait
PORTB = 0b00100000; // The same sequence repeats…
_delay_ms(50);
PORTB = 0b00010000;
_delay_ms(50);
PORTB = 0b00001000;
_delay_ms(50);
PORTB = 0b00000100;
_delay_ms(50);
PORTB = 0b00000010;
_delay_ms(50);
PORTB = 0b00000001;
_delay_ms(50);
}}
The statment while (1) is forever true , so the LEDs keep cycling forever.
There’s just one teeny weeny thing left : the Makefile. You can use the same one that Real Elliot provides in his Ghetto programming tutorial here. For your convenience i have uploaded both here :
Ready to use Makefile – The full credit goes to Real Elliot.
Dont forget to remove the .txt extension from the makefile after you download it.
If you compile it and load it into your Attiny2313 , you will see the LEDs on PortB running in a chain like this :
Note : This code is a terrible example of how to make an LED chain. The same thing can be accomplished more efficiently by a loop in less than 5 lines of code.
Selective bit modification in Registers
However there is a huge disadvantage in the modifying registers in this way! Suppose you want to set the 7th bit of PORTB and reset the 3rd bit without affecting the rest, how would you do it?
It seems like its impossible, because bits in the AVR registers cannot be accessed individually. Despite this fact, with a little bit of Boolean algebra , it is possible to modify just the bits we need without touching the rest. I’m still writing the post on this. So, I’ll post the tut on selective bit modification later.
Thats all for now,
Subscribe to:
Posts (Atom)