means microcontroller gets interrupts after every 7000 instructions. Hence floating point
calculation should be avoided at all cost as microcontroller is already quite loaded. If we are
using this algorithm then use of LCD is not recommended. It might interfere with the stability of
the code.
Algorithm:
1. Timer 1 gets overflowed at every 2.5ms (400Hz). It also generates Timer 1 overflow
interrupt each time it gets overflowed "ISR (TIMER1_OVF_vect)".
2. In the timer 1 overflow interrupt unsigned char variable "arm_number" (0 to 6) gets
incremented every time ISR occurs. It can only incremented from 0 to 7 and then back to
0.
3. Function like set_1A () and reset_1A () are used to set or reset particular control pin of
the servo motor.
4. When there is a particular arm number is in the ISR, pins corresponding to that arm are
set to logic 1 using functions like set_1A () where arm number can be from 1 to 6 and
motor location from A to C. It means that each pin gets set only for 400Hz / 8 = 50 times
a second. In this way control frequency of 50 Hz is generated for each servo motor.
5. Corresponding pins are reset to logic 0 in the OCR interrupts when the particular arm
number is set by the timer 1 overflow ISR. In this way desired pulse width between
0.5ms to 2.2ms is obtained.
6.4 Servo angle control
Desired servo angle is calculated in the function "angle_value_calculation ()".
"angle_value_calculation ()" calculates the 16 bit OCR value for the particular servo motor
and separates upper and lower bytes which are to be loaded in to the corresponding OCRs for
setting the corresponding servo angle. This function is used by all the functions such as
"angle_1A(unsigned char angle)"to set individual angle. In this function constant of 139 is
used instead of 139.4 which adds some error in the angle calculation but by using unsigned char
instead of floating point number, lots of computational requirement is saved.
6.5 Servo motor calibration
This function is used for calibrating servo motors. If you need to replace any servo then call
"robot_arm_calibration ()" function. All the motors are set in the 90 degrees standup position.
Now any of the servos can be replaced. This function must be the first function to be called after
"init_devices ()" in the main function to initialize the motors. If its is not called first then all the
servos will assume 0 degree angle and all the arms will get twisted and robot might take sudden
fall and servos might get damaged because of the impact. This function is also used frequently in
various motion functions.
6.6 Robot forward and backward motion
"forward ()" and "back ()" functions moves robot forward and back. In the forward and back
motion in each step a pair of legs from the both side is lifted and moved in the desired direction,
call the function "fwd_front_step ()" for forward step or call "back_front_step ()" for back
step. Once all the legs are moved, robot pushes itself in the desired direction by calling the
function "walk_stroke()". Same motion can be achieved as shown in the video "Hexapod 1" in
the video folder which is located in the documentation CD.
© NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA
Fire Bird V ATMEGA2560 Hexapod Robot User Guide
27
Need help?
Do you have a question about the Fire Bird V ATMEGA2560 HEXAPOD and is the answer not in the manual?