Author Topic: Servo Control  (Read 2467 times)

0 Members and 1 Guest are viewing this topic.

Offline JohnMTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Servo Control
« on: September 03, 2009, 09:02:26 PM »
I have an Axion microcontroller and have jsut started to play iwth it. turned on the light witht he button all worked well. now aI am trying to move a server but having no luck. i have read everything on here I can find and i tink this shoudl work ????

What am I doing wrong. ther servo does not move, but the light flashes (I know it is running).

thanks

   //add 1.7s delay for potential power issues
   delay_cycles(65535);
   delay_cycles(65535);
   delay_cycles(65535);
   delay_cycles(65535);
   delay_cycles(65535);
   delay_cycles(65535);
   delay_cycles(65535);

   configure_ports()  ;

   while(1)
      {
      if (button_pressed() )
         {   
         LED_on();
         PORT_ON(PORTE,2) ;
         delay_cycles(1*234) ;
         PORT_OFF(PORTE,2) ;

         }
      else
         {   
         LED_off() ;
         PORT_ON(PORTE,2) ;
         delay_cycles(2*234) ;
         PORT_OFF(PORTE,2) ;


         }

      delay_cycles(18*234) ;

      }

Offline JohnMTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: Servo Control
« Reply #1 on: September 03, 2009, 09:15:38 PM »
Sorry about the typo, here is what it was to say in English.

I have an Axion microcontroller and have jsut started to play with it. I wrote a nothing program to control the light with the button, all worked well. Now I am trying to move a servo but having no luck. I have read everything on here I can find about servos, and I think this should work ?

What am I doing wrong. the servo does not move, but the light flashes witht the button (I know it is running).

thanks

Offline WhomBom

  • Full Member
  • ***
  • Posts: 64
  • Helpful? 0
Re: Servo Control
« Reply #2 on: September 04, 2009, 03:16:50 AM »
perhaps you should try typing delay_cycles(18*234) ; at he end of your if and else statement instead of just once at the end... just a thought

Offline JohnMTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: Servo Control
« Reply #3 on: September 04, 2009, 05:13:05 AM »
I could do that but I would have to put a delay_cycles at the end of the IF and the ELSE so the total time spent in the loop was the approx. 20 ms wheather the button was pushed or not. 

Initially I used the servo function, when that did not work I broke it out to PORT_ON / DELAY / PORT_OFF still no good so I just did PORT_ON on button press and PORT _OFF on no button the found with my meter the the voltage on the pin does change. Then I realized the delay at the end was the same for both so I moved it just to make a smaller program.

Wish I had an oscilloscope.

?????????????????????????????????????


Offline klims

  • Robot Overlord
  • ****
  • Posts: 190
  • Helpful? 2
Re: Servo Control
« Reply #4 on: September 04, 2009, 07:41:02 AM »
First of all, why not use a delay_ms(1700) instead of all those delay_cycle() function?

What type of servo are you using? My guess is analogue.
If you are using analogue you need to poll the servo at a specific frequency to tell it what position to go to, otherwise it goes limp.
I don't quite know the specifics of how to do that on the Axon, but hopefully one of the more experienced guys will post some code to show us how to do it...

Offline JohnMTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: Servo Control
« Reply #5 on: September 04, 2009, 12:39:01 PM »
It is a great idea but my delay_ms does not work, I get complier errors. Looks stupid agree but should work. I saw in one of the demo projects:

   //add 1.7s delay for potential power issues
   delay_cycles(65535);
   delay_cycles(65535);
   delay_cycles(65535);
   delay_cycles(65535);
   delay_cycles(65535);
   delay_cycles(65535);
   delay_cycles(65535);

so being desperate I thought I would put it in...... but it did not help.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,702
  • Helpful? 173
    • Society of Robots
Re: Servo Control
« Reply #6 on: September 05, 2009, 06:16:25 AM »

Offline JohnMTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: Servo Control
« Reply #7 on: September 05, 2009, 06:53:10 PM »

I thought that is what I had??? What part of that am I missing?

I configure the ports (although that is not explicitly told to do). Then I turn on and off the port using the timing in the cycles to ms conversion I found inthe comments of a program.

what am I doing wrong. Can someone else try this very simple program and let me know the results?? 

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,702
  • Helpful? 173
    • Society of Robots
Re: Servo Control
« Reply #8 on: September 05, 2009, 07:05:27 PM »
change your code to this:

Code: [Select]
   //add 1.7s delay for potential power issues
   delay_cycles(65535);
   delay_cycles(65535);
   delay_cycles(65535);
   delay_cycles(65535);
   delay_cycles(65535);
   delay_cycles(65535);
   delay_cycles(65535);

   configure_ports()  ;

   while(1)
      {
      if (button_pressed() )
         {   
         LED_on();
         PORT_ON(PORTE,2) ;
         delay_cycles(900) ;
         PORT_OFF(PORTE,2) ;

         }
      else
         {   
         LED_off() ;
         PORT_ON(PORTE,2) ;
         delay_cycles(400) ;
         PORT_OFF(PORTE,2) ;


         }

      delay_ms(30) ;

      }

Offline JohnMTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: Servo Control
« Reply #9 on: September 06, 2009, 08:13:44 AM »
Sorry does not work either. I tried all kinds of numbers inthe delays since I do not have a scope to see the results. I even have tried a new servo figuring I broke the first ... no movement.

The only part of the code you put that I had to change is the delay_ms. As I posted earlier this does nto work on mine (get compile errors). So I substitued delay_cycles(7020) or 30*234. If you post the dealy_ms code or the include file it is in I will include it.  I have the timer640.h and sor_utils.h already included.

Thanks for your help.   

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,702
  • Helpful? 173
    • Society of Robots
Re: Servo Control
« Reply #10 on: September 06, 2009, 08:23:53 AM »
Quote
The only part of the code you put that I had to change is the delay_ms. As I posted earlier this does nto work on mine (get compile errors).
You shouldn't be getting compile errors. What are the errors you are getting?

Did you change any fuses?

The correct cycles delay for servos on the Axon should be ~400 to ~1100.

Does the default photovore code work?

Offline JohnMTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: Servo Control
« Reply #11 on: September 06, 2009, 06:10:29 PM »
Well very interesting. I got servos to work. I down loaded the Servo controler RoboRelm app. and it works, so I know the hardware is working. So it is a software problem.

Fuses, did notknow it had fuses, no did not change any.

the complie error is:

Build started 6.9.2009 at 20:07:45
avr-gcc.exe  -mmcu=atmega640 -Wall -gdwarf-2 -std=gnu99 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT Axion1.o -MF dep/Axion1.o.d  -c  ../Axion1.c
../Axion1.c: In function 'main':
../Axion1.c:65: warning: implicit declaration of function 'delay_ms'
avr-gcc.exe -mmcu=atmega640 -Wl,-Map=Axion1.map Axion1.o     -o Axion1.elf
Axion1.o: In function `main':
C:\MyRobots\Axion1\default/../Axion1.c:65: undefined reference to `delay_ms'
make: *** [Axion1.elf] Error 1
Build failed with 1 errors and 1 warnings...


Could I be using bad header files??


Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,702
  • Helpful? 173
    • Society of Robots
Re: Servo Control
« Reply #12 on: September 06, 2009, 06:20:29 PM »
Well, you spelled your C file as 'Axion', but in your makefile, you probably have it spelled as 'Axon'.

Your mistake is a probably a misspelling . . .

Offline JohnMTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: Servo Control
« Reply #13 on: September 08, 2009, 04:13:09 PM »

No misspelling. I  will get it working and post the code.

thanks  ;)

Offline airman00

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Servo Control
« Reply #14 on: September 08, 2009, 05:01:19 PM »
../Axion1.c: In function 'main':
../Axion1.c:65: warning: implicit declaration of function 'delay_ms'

Axion1.o: In function `main':
C:\MyRobots\Axion1\default/../Axion1.c:65: undefined reference to `delay_ms'
Hi,
Implicit declaration means that you called delay_ms , before declaring it.

For example , this is a case where there is implicit declaration
delay_ms(100);
#include "timer640.h"

This is a corrected version
#include "timer640.h"
delay_ms(100);

Also, you should press Rebuild All when changing SoR_Utils.h and other files. Rebuild All takes longer, but guarantees that you're building correctly.

Can you paste the contents of your makefile and of SoR_Utils.h . Or better yet, zip up all your code and upload it. I'd be happy to fix it for you, as its probably a simple problem.
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

 


Get Your Ad Here