To all,
I was wondering about the numbers 25 and 44 from the photovore_v1.h file that are used to move the robot. I spent some time and I think I can provide a good explanation for the people that are wondering for the same reason.
Please, if you see anything wrong in my explanation (maybe everything at all), please feel free to correct. The following is what I think that is happening, but again, I am not 100% sure.
Topic: About the “magic” numbers 25 and 44 on the photovore_v1.h file.
A non-modified servo motor can move from a variety of positions from a full left to full right. The time (duration in milliseconds) of a high voltage signal applied to the motor is the factor that determines what is the new position that the servo-motor must go. Therefore it is not the level of the voltage itself, but for how long that voltage is applied to the servo-motor.
For our case, this time varies from 1 millisecond to 2 milliseconds for the full left to the full right positions. Providing 1.5 milliseconds will place the motor in the middle position.
The photovore_v1.h code operates in a variable based on the number of cycles (just an integer number) and not TIME. However, as a comment in the code states, we can correlate the variable "cycles" with "time" as follows
23/.992*(time in milliseconds) = number of cycles
Now let’s understand those 44 and 25 “magic” numbers.
For the MODIFIED servo-motor used for this robot, the 1.5 ms signal will make the motor to stop rotation (it will not go either forward nor backward), while any signal smaller than 1.5 ms will make the motor to run continuously to the left, and any signal longer that it will make the motor to run continuously to the right..
Let’s compute how many cycles the 1.5 ms correspond. For this case, the number of cycles would be…
23/.992*(1.5) = 34.8 (let’s make an integer of 35).
If we give a lower cycle number, let’s say 25 (or about 10 cycles less), the motor will rotate in one direction. And if we give a higher number, let’s say 44 (or about 10 cycles more (remember the round-off that we needed to do for 34.8 above), then the servo motor will go in the other direction for about the same speed (but in the reverse direction) as the one provided by the 25 cycles.
Therefore that is the reason for the 25 and 44: they are 10 cycles for less or for more of the “neutral” (stop) position.
Now, let’s talk about why the number 25 and 44 are placed in that way in the code. I will discuss only the “go straight” else statement, since the others are easily understood if you understand this one.
//light is about equal on both sides
else
{
//go straight
servo_left(25);
servo_right(44);
}
Why the numbers are 25 for a motor and 44 for the other if they are running straight forward? It is due to the fact that we have mounted both motors in the robot chassis in reversed with relation to each other, i.e., to go straight forward one motor must go forward while the other must go backwards. That’s why the left servo is set to 25 (backward movement) while the other is set to 44 (forward movement). Both are 10 cycles apart from the middle (stop) position, providing this way the same speed and movement direction on both motors.
I hope this explanation can help someone that did not had figured out about those numbers before, like me a day ago!
Please make any comment on this as necessary. There will be no hard feelings, ahhhaahh
Paulo Brasko (Brazilian Greetings!)