If for whatever reasons you don't want to use libraries, what is the most robust go-to practice of controlling servos? The "industry standard" so to say. Right now I'm using "millis()" for counting control signal period and "delayMicroseconds()" to measure pulse width. I also experimented with using "micros()" for pulse width, but I've read that this method is too fragile for precise control.
If you would need to create a code from scratch for a servo control, how would you approach it?
You may know that you can read all the source code for anything that ends up in a project you compile, and it is all on you machine somewhere.
If a real programmer were to "create a code from scratch for a servo control", she would probably use counter/timer peripherals and end up with something that might look quite a bit like the servo library code.
The answer is quite dependent on what else the code must do/tolerate. Interrupts for serial, for millis(), and anything else are quite likely to disrupt even the most carefully crafted pulse generating code; using a hardware timer might help, but is again dependent upon approach.
If you need "precise control" as you mentioned then I would use hardware timers but as @alto777 mentioned you will probably just wind up recreating the servo library.
1. Make a semicircle dial (0 deg to 180 deg) with 10 degrees intervals and mark them properly. Position the shaft of te Servo (assume: SG90) at the center of the semicircle.
2. Create a sketch to generate a 50 Hz Fast PWM signal using TC1 of Arduino UNO.
3. Connect a Pot with UNO to manually control the duty cycle of the PWM signal of Step-2.
4. Connect a scope to measure the duty cycle of the PWM signal. You can also compute it.
5. Uplaod the sketch of Step-2.
6. Adjust the duty cycle of the PWM signal so that the horn of Servo (Assume: SG90) aligns with 0 degree of the dial.
7. Repeat Step-6 for each 10 degree incremental advance of the horn of the Servo.
8. Record and post Rotational_degree vs PWM_Duty_Cycle of the Servo.
9. Finally, convert the record of Step-8 into Programming Codes so that you can control the shaft position using a software command rather than using the hardware Pot.
There doesn't have to be because it uses the higher level main function.
Everything up to the while statement is the setup function in the normal IDE, and everything after the while statement is the equivalent of the loop function.
However, the main function is supposed to return a int variable and no such variable is set to return anything. It then probably returns a null which is why you can get away with this error.
And the 3x growth is because? I would expect that for one, the millisecond timer is now running, but I doubt that is all; what else has been stood up behind the Arduino curtain?