

Search Here
MISC
SKILLS
HARDWARE
SCIENCE 
C Variables
C Variable Reference Chart
Limited Memory
Limited Processing Speeds
You should also avoid all use of exponents and trigonometry  both because they are software implemented and require heavy processing. What if your robot requires a complex equation and there is no way around it? Well, what you would do is take shortcuts. Use lookup tables for often made calculations, such as for trigonometry. To avoid floats, instead of 13/1.8 use 130/18 by multiplying both numbers by 10 before dividing. Or round your decimal places  speed is almost always more important than accuracy with robots. Be very careful with the order of operations in your equation, as certain orders retain higher accuracy than others. Don't even think about derivatives or integrals.
Overflows
variable = variable+1; //variable will now equal 0, not 256!!! To avoid this overflow, you would have to change your variable type to something else, such as a long int. You might also be interested in reading about timers, as accounting for timer overflows is often important when using them.
Signs
In reality you do not always need a negative number. A positive number can often suffice because you can always arbitralily define the symantics of a variable. For example, numbers between 0 and 128 can represent negatives, and numbers between 129 and 255 can represent positive numbers. But there will often be times when you would perfer to use a negative number for intuitive reasons. For example, when I program a robot, I use negative numbers to represent a motor going in reverse, and a positive for a motor going forward. The main reason I would avoid using negative numbers is simply because a signed int overflows at 128 (or 128) while unsigned overflows at 256 (or 0).
Extras
Examples of Variables in C Code:
Defining variables:
int answer; signed long int answer2; int variable = 3; signed long int constant = 538;
variable math examples (assume answer is reset after each example):
answer = variable / 2; //answer = 1 (because of rounding down) answer = variable + constant; //answer = 233 (because of overflows and signs) answer2 = signed long int(variable) + constant; //answer2 = 535 answer = variable  4; //answer = 255 (because of overflow) answer = (variable + 1.2)/3; //answer = 1 (because of rounding) answer = variable/3 + 1.2/3; //answer = 1 (because of rounding and order of operations) answer = answer + variable; //answer = RANDOM GARBAGE (because answer is not defined) 

Has this site helped you with your robot? Give us credit 
link back, and help others in the forums! Society of Robots copyright 20052014 