Society of Robots
     | Robot Forum | Robot Tutorials | Robot FAQ |
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 20, 2009, 05:49:33 PM

Login with username, password and session length
Search:     Advanced search
SoR Robot Chat every friday night. Join us!
http://www.societyofrobots.com/robotforum/chat/

Robot Forum
72,657 Posts in 9,264 Topics by 5,289 Members
Latest Member: rac34125
* Home Help Help Login Register
0 Members and 1 Guest are viewing this topic.
Pages: [1] Print
Author Topic: About the “magic” numbers 25 and 44 on the photovore_v1.h file  (Read 6027 times)
paulobraskoTopic starter
Beginner
*

Helpful? 0
Offline Offline

Posts: 6


View Profile
« on: December 30, 2007, 06: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!)
Logged
ed1380
Supreme Robot
*****

Helpful? 2
Offline Offline

Posts: 1,458



View Profile
« Reply #1 on: December 30, 2007, 06:52:09 PM »

good post
Logged

Problems making the $50 robot circuit board?
click here. http://www.societyofrobots.com/robotforum/index.php?topic=3292.msg25198#msg25198
Admin
Administrator
Supreme Robot
*****

Helpful? 62
Offline Offline

Posts: 8,609



View Profile WWW
« Reply #2 on: December 30, 2007, 06: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.
Logged

silent069
Full Member
***

Helpful? 0
Offline Offline

Posts: 49



View Profile
« Reply #3 on: July 08, 2008, 03:22:02 PM »

This topic is really helpful to understanding servos! very nice Smiley
Logged
pomprocker
Supreme Robot
*****

Helpful? 15
Offline Offline

Posts: 1,411


Sorry miss, I was giving myself an oil-job.


View Profile WWW
« Reply #4 on: July 08, 2008, 04: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.
Logged

pulkitgulati
Beginner
*

Helpful? 0
Offline Offline

Posts: 1


View Profile
« Reply #5 on: September 13, 2008, 03:20:34 AM »

Very useful to improve upon the understanding with the servos for future uses as well....
Thanks a lot!!!!
Logged
Metal Slug 2
Robot Overlord
****

Helpful? 4
Offline Offline

Posts: 195


Imagination is more important than knowledge


View Profile
« Reply #6 on: January 26, 2009, 11:00:17 PM »

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.
Logged

The difference between genius and stupidity is that genius has its limits ~ Albert Einstein

The only thing that interferes with my learning is my education ~ Albert Einstein
RoBoTicS
Full Member
***

Helpful? 0
Offline Offline

Posts: 80


Man is a robot with defects


View Profile
« Reply #7 on: January 27, 2009, 06:58:54 AM »

awesome thanks
Logged
Miles
Jr. Member
**

Helpful? 1
Offline Offline

Posts: 47


View Profile
« Reply #8 on: January 27, 2009, 09: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?Huh
Logged
Admin
Administrator
Supreme Robot
*****

Helpful? 62
Offline Offline

Posts: 8,609



View Profile WWW
« Reply #9 on: February 12, 2009, 10:24:57 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?Huh
I used my oscilloscope to time it.
Logged

Pages: [1] Print 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
About the values used in the DELAY_CYCLES command in the photovore_v1.h
Software
paulobrasko 2 1216 Last post January 01, 2008, 09:31:53 AM
by paulobrasko
Solder by numbers
Misc
javafiend 1 702 Last post December 02, 2008, 02:34:38 PM
by pomprocker
help - "magic numbers"
Software
byuri 6 716 Last post January 30, 2009, 03:18:07 AM
by byuri
Photovore_v1.c:108: fatal error: opening dependency file .dep/Photovore_v1.o.d:
Software
Becky 5 1153 Last post May 10, 2009, 08:10:01 AM
by LIONS*LEADER
Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!


Advertise on this Forum