Society of Robots - Robot Forum

Software => Software => Topic started by: paulobrasko on December 30, 2007, 08:22:07 PM

Title: About the “magic” numbers 25 and 44 on the photovore_v1.h file
Post by: paulobrasko on December 30, 2007, 08:22:07 PM
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!)
Title: Re: About the “magic” numbers 25 and 44 on the photovore_v1.h file
Post by: ed1380 on December 30, 2007, 08:52:09 PM
good post
Title: Re: About the “magic” numbers 25 and 44 on the photovore_v1.h file
Post by: Admin on December 30, 2007, 08:54:15 PM
Wow ok this is 100% correct!
(I will link this to the tutorial right now for others to use)


Additions:

The exact numbers depend on various factors, including length of cycle time (determined by your specific microcontroller and timing crystal/settings). 25 and 44 are specific to the ATmega8 and ATmega168 running at 1Mhz (the default for the $50 robot tutorial).

The numbers also depend on your choice in servo type and brand and how you modified it.

By varying the number - say 22 or 27 instead of 25, you can slow down or speed up your servo. Servos make a different humming noise depending on the speed (because of the gears meshing at different frequencies).

There is another popular way to control servos instead of using cycles. This method involves using timer interrupts. The problem with this method is that it simply won't work if you have many servos (typically more than 4). Not a problem for the $50 robot, but definitely a problem for bipeds/hexapods/snake robots which have a dozen or so servos.
Title: Re: About the “magic” numbers 25 and 44 on the photovore_v1.h file
Post by: silent069 on July 08, 2008, 04:22:02 PM
This topic is really helpful to understanding servos! very nice :)
Title: Re: About the “magic” numbers 25 and 44 on the photovore_v1.h file
Post by: pomprocker on July 08, 2008, 05:16:24 PM
A good place to start to find your own magic numbers would be to first find a stand still for your robot and then increment and decrement from there.

For example: I haven't had time to tweak these settings in my $50 robot code, so my robot always veers to the left.. never goes very straight.
Title: Re: About the “magic” numbers 25 and 44 on the photovore_v1.h file
Post by: pulkitgulati on September 13, 2008, 04:20:34 AM
Very useful to improve upon the understanding with the servos for future uses as well....
Thanks a lot!!!!
Title: Re: About the “magic” numbers 25 and 44 on the photovore_v1.h file
Post by: Metal Slug 2 on January 27, 2009, 01:00:17 AM
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.

aha! i get it now =), thanks...that puzzled me for the longest time.
Title: Re: About the “magic” numbers 25 and 44 on the photovore_v1.h file
Post by: RoBoTicS on January 27, 2009, 08:58:54 AM
awesome thanks
Title: Re: About the “magic” numbers 25 and 44 on the photovore_v1.h file
Post by: Miles on January 27, 2009, 11:44:38 PM
Hello, i understand why the servo's are set to 25 and 44 but was just wondering how you figured this bit out:

23/.992*(1.5) = 34.8 (let’s make an integer of 35).



Where did you get the 23/.992*(1.5) from????
Title: Re: About the “magic” numbers 25 and 44 on the photovore_v1.h file
Post by: Admin on February 13, 2009, 12:24:57 AM
Hello, i understand why the servo's are set to 25 and 44 but was just wondering how you figured this bit out:

23/.992*(1.5) = 34.8 (let’s make an integer of 35).

Where did you get the 23/.992*(1.5) from????
I used my oscilloscope to time it.