Author Topic: Another posr on servo issues...  (Read 2828 times)

0 Members and 1 Guest are viewing this topic.

Offline roi_tauTopic starter

  • Jr. Member
  • **
  • Posts: 19
  • Helpful? 0
Another posr on servo issues...
« on: November 20, 2008, 02:43:55 PM »
Hello everyone.

First of all,thank you so much for this great forum and help

This is my first post so I hope I wont embarase myself..

I have a software question o modified servos (the 50$ robot source code)

I'm using Pic but it shouldn't make a difference (I think)

Here is the code for servo functions:

void servo_left(signed long int speed)
   {
   PORT_ON(PORTD, 0);
   delay_cycles(speed);
   PORT_OFF(PORTD, 0);//keep off
   delay_cycles(200);
}

                                {//go straight
         servo_left(25);
         servo_right(44);
         }

Now,I  understand why for straight the values are different (opposite motors) but the servos will only rotate for a very short period of time (Only one T)

And why the "Off time" is always 200??? It shouled be a function of the "On Time".

If the freq is 50Hz =>T=20ms

If T_on=1.5ms(stop the servo) , so T_off should be 20-1.5=18.5ms

Please help me.

Roi


Offline roi_tauTopic starter

  • Jr. Member
  • **
  • Posts: 19
  • Helpful? 0
Re: Another posr on servo issues...
« Reply #1 on: November 20, 2008, 02:48:13 PM »
And the most important question:

How do they rotate together?

the function first "calls" servo_left() and only after servo_right(); so how can they spin simultaneously?

Roi


Offline mbateman

  • Full Member
  • ***
  • Posts: 82
  • Helpful? 0
    • Robotics 4 Fun
Re: Another posr on servo issues...
« Reply #2 on: November 20, 2008, 02:51:27 PM »
Technically, the off time should be a function of the on time, but servos are very forgiving about the base frequency. As long as it is within an acceptible range, they really only care about the pusle width of the on time. Therefore, you can use the simpler function and skip the subtraction step.

Offline roi_tauTopic starter

  • Jr. Member
  • **
  • Posts: 19
  • Helpful? 0
Re: Another posr on servo issues...
« Reply #3 on: November 20, 2008, 03:02:47 PM »
This is how I programed my NON modified servo:

while(a<85)
{
PORTB.F0=1;
delay_us(600);
PORTB.F0=0;
delay_us(19400);
a++;
} [the datasheet says from 600us to 2400us]

Is there a diifrence between delay_ms()  and the delay_cycles() functions? How can the 2 servos work together?

Roi

Offline szhang

  • Robot Overlord
  • ****
  • Posts: 140
  • Helpful? 1
    • szhang.net
Re: Another posr on servo issues...
« Reply #4 on: November 22, 2008, 12:01:12 AM »
delay_ms(x) delays x number of milliseconds
delay_cycles(x) delay x number of processor cycle, the exactly time depend on the processor frequency.

Usually you make two servos work together but using CCP module's PWM mode.  In a pinch, you can also write timer interrupt based code to do the same thing.

Offline roi_tauTopic starter

  • Jr. Member
  • **
  • Posts: 19
  • Helpful? 0
Re: Another posr on servo issues...
« Reply #5 on: November 22, 2008, 10:04:59 AM »


So in the 50$ robot code, the servos don't work exactly simultaneously,

The only way to make 2 (or more) servos to work together is the CCP or interrupt,yes?

Isn't another way ?(Like the fork in UNIX to operate 2 function at the same time?)

Please help me

Roi

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
    • RazorConcepts
Re: Another posr on servo issues...
« Reply #6 on: November 22, 2008, 11:33:29 AM »
They dont work exactly simultaneously, but its close enough that a human could never tell. It should be fine  ;D

Offline szhang

  • Robot Overlord
  • ****
  • Posts: 140
  • Helpful? 1
    • szhang.net
Re: Another posr on servo issues...
« Reply #7 on: November 22, 2008, 01:27:33 PM »


So in the 50$ robot code, the servos don't work exactly simultaneously,

The only way to make 2 (or more) servos to work together is the CCP or interrupt,yes?

Isn't another way ?(Like the fork in UNIX to operate 2 function at the same time?)

Please help me

Roi

You'll need to run a RTOS for that...

A vanilla microcontroller don't have a scheduler to do stuff like fork(), and fork isn't simultaneous either unless you're running multiple cores.  Interrupt is basically "fork", though alot more lower level.

CCP is usually the easiest way to do stuff like PWM.

Offline roi_tauTopic starter

  • Jr. Member
  • **
  • Posts: 19
  • Helpful? 0
Re: Another posr on servo issues...
« Reply #8 on: November 22, 2008, 02:01:19 PM »
Thank you all for your answers.


What is RTOS?

I got the idea that it isn't exactly at the same time but it close enough.

I have 2 more questions:

1.How important is the 50Hz thing? If I send 1.5ms pulse in 100Hz or in 25Hz,will it damage my servo?

2.Is there a way to know ithe location of the servo (beside looking at it...)

My question is if I can write (Pseudo code)

      IF servo arrived to location

Offline szhang

  • Robot Overlord
  • ****
  • Posts: 140
  • Helpful? 1
    • szhang.net
Re: Another posr on servo issues...
« Reply #9 on: November 22, 2008, 02:45:45 PM »
RTOS is a real-time operating system, pretty much like a very stripped down version of linux.  I don't recommend using it on small projects because it takes up alot of space and increase complexity.

50Hz is somewhat important, if you sent 100Hz or 25Hz the servo probably won't do the right thing.  You do have a bit of leeway so it doesn't have to be exactly 50Hz.

The location of the servo is usually assumed to be the command you sent it, i.e. you assume it is centered if you send a 1.5ms PWM signal.  The servos usually have a good enough control loop so the assumption is pretty close.

You can't read the current position of the servo though, unless you take the servo apart and connect the wiper in the potentiometer to an ADC port.

 


data_list