Author Topic: Axon servo problem  (Read 2865 times)

0 Members and 1 Guest are viewing this topic.

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Axon servo problem
« on: February 17, 2009, 11:12:00 AM »
When I send a signal like this to my servo:
Code: [Select]
servo_1=280rather than the servo going to the -90 degrees like it should it goes to about 65 degrees. The same thing happens if it's anywhere between 280 and 399 But when I give it any signal above 399 cycles it goes to the right postition. Does anybody know what could be going wrong? I tested it with a different servo and the same thing happened.
« Last Edit: February 17, 2009, 11:13:21 AM by Jdog »

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,430
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
Re: Axon servo problem
« Reply #1 on: February 17, 2009, 01:41:01 PM »
Could you please provide more information about your servo, like what kind is it

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: Axon servo problem
« Reply #2 on: February 17, 2009, 05:45:42 PM »
I tried it on an hs-311 and a futaba S3003. They both did the same thing.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,659
  • Helpful? 169
    • Society of Robots
Re: Axon servo problem
« Reply #3 on: February 18, 2009, 01:23:38 AM »
Hmmm can you show us your code?

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: Axon servo problem
« Reply #4 on: February 18, 2009, 10:01:29 AM »
Code: [Select]
/****************************************************************************
*
*   Copyright (c) 2008 www.societyofrobots.com
*   (please link back if you use this code!)
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License version 2 as
*   published by the Free Software Foundation.
*
*   Alternatively, this software may be distributed under the terms of BSD
*   license.
*
****************************************************************************/

//Add your code here
int servo_1;
int servo_2;

void servo_right(void)
{
servo_1=1119;
servo_2=1119;
}
void servo_left(void)
{
servo_1=280;
servo_2=280;
}
void servo_middle(void)
{
servo_1=700;
servo_2=700;
}
void control(void)
{
while(1)
{
char cByte = uart1GetByte(); // get byte from UART1 on the axon
if (cByte == 'r') // if character received is b then
{
servo_right();
LED_on();
}
if (cByte == 'l')
{
servo_left();
LED_off();
}
if (cByte == 'm')
{
servo_middle();
}
servo_1(servo_1);
servo_2(servo_2);
}
}


Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,659
  • Helpful? 169
    • Society of Robots
Re: Axon servo problem
« Reply #5 on: February 18, 2009, 10:36:06 AM »
Here is your first problem:
Code: [Select]
int servo_1;
int servo_2;

void servo_right(void)
{
servo_1=1119;
servo_2=1119;
}
You initialized servo_1 as an int, that can't go higher than 255, yet you are storing 1119 in it :P


And for testing, use this code for control instead. Every time you push 'r', the servo should do something while the value it is at will be printed out to hyperterminal.

void control(void)
   {
   servo1=100;
   while(1)
      {
      char cByte = uart1GetByte(); // get byte from UART1 on the axon
      if (cByte == 'r') // if character received is b then
         {
         servo1++;
         LED_on();
         }
      if (cByte == 'l')
         {
         servo1--;
         LED_off();
         }
      servo_1(servo_1);
      rprintf("%d\r\n",servo_1);
   }
}

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: Axon servo problem
« Reply #6 on: February 19, 2009, 05:03:00 PM »
Ok youre code worked but is there a way so that I don't have to hold down the key I want if I want it to move?
« Last Edit: February 19, 2009, 05:15:04 PM by Jdog »

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
Re: Axon servo problem
« Reply #7 on: February 19, 2009, 05:07:38 PM »
Yes, you can play around with the code, feel free to experiment to figure out what works well or not.

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,430
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
Re: Axon servo problem
« Reply #8 on: February 19, 2009, 05:44:00 PM »
What was the numbers returned from the print statement above when the servo was at its full left and right positions?

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: Axon servo problem
« Reply #9 on: February 19, 2009, 06:51:18 PM »
I fixed the holding down button problem, I put it in a while loop. It printed out the numbers it should. Full left was 280 and full right was 1110. (Those were the limits I set because I didn't want to accidentally go too far). The weird things that happen are as follows. At the start of my code I set the servo to 700. If when the axon is not powered on the servo is somewhere near the far right position, the servo goes to the far right position rather than the center although it tells hyperterminal it's value is 700 when it's turned on. If it isn't near the far right, then it goes to normal center. Also, when it is centered and I tell it to go far left, it goes to middle right. Also, when it is centered and I tell it to go far right, it goes far right, but then it can't go back to center. Here is my code:
Code: [Select]
long int servo_1=700;

void servo_left(void)
{
while (servo_1>280) //overflow protection
{
servo_1--;
}
}
void servo_right(void)
{
while  (servo_1<1110)
{
servo_1++;
}
}
void servo_middle(void)
{
servo_1=700;
}
void control(void)
{
while(1)
{
char cByte = uart1GetByte(); // get byte from UART1 on the axon
if (cByte == 'r') // if character received is r then
{
servo_right();
}
if (cByte == 'l')
{
servo_left();
}
if (cByte == 'm')
{
servo_middle();
}
servo_1(servo_1);
rprintf("%d\r\n",servo_1);
}
}


Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,659
  • Helpful? 169
    • Society of Robots
Re: Axon servo problem
« Reply #10 on: February 20, 2009, 12:11:24 PM »
I couldn't find anything wrong with your code . . . but I just wrote this code for my ERP gripper servo and I know it works. Give it a try.

Code: [Select]
int gripper=500;
char cByte;

rprintfInit(uart0SendByte);
while(1)
{
cByte=uart0GetByte(); //get byte from UART0 on the axon
if(cByte!=-1)//no new data
{
if (cByte == 'q')
LED_on();
if (cByte == 'w')
LED_off();
if (cByte == 'e')
gripper=gripper+25;
if (cByte == 'r')
gripper=gripper-25;

servo(PORTH,3,gripper);
rprintf("grip:%d photo:%d\r\n",gripper,a2dConvert8bit(0));
delay_ms(50);
}
}

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: Axon servo problem
« Reply #11 on: February 20, 2009, 04:56:05 PM »
If I do it like that I have no problem, but I'm trying to get it so that it goes all the way to the right with one keystroke and all the way to the left with another.

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
Re: Axon servo problem
« Reply #12 on: February 20, 2009, 05:17:38 PM »
then do
if btye = allthewayrightkey
servoright = 1110
if byte = allthewayleftkey
servoleft = 220

or whatever values make the servo go all the way. after that, use a loop to send the servo command to the servo for about 1 second, giving it enough time to move to the location

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: Axon servo problem
« Reply #13 on: February 20, 2009, 05:28:00 PM »
at the bottom of the infinite while, the term servo_1 is used as an function e.g. servo_1(servo_1);
whereas the exact same name servo_1 is being used also as a variable....
which is it? and is there maybe some confusion by the compiler that causes your erratic behaviour (the servo's erratic behaviour - not yours)

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: Axon servo problem
« Reply #14 on: February 20, 2009, 05:40:50 PM »
at the bottom of the infinite while, the term servo_1 is used as an function e.g. servo_1(servo_1);
whereas the exact same name servo_1 is being used also as a variable....
which is it? and is there maybe some confusion by the compiler that causes your erratic behaviour (the servo's erratic behaviour - not yours)
This is the way he has a simple pwm for servos setup on the axon. You declare an integer that is the amount of cycles between each pulse then you use that integer as a variable for a function he has setup in SoR_Utils.h to control servos. Also I don't think it's a compiling problem because I've tried compiled it and uploaded it many different times all with the same results because that was my first thought as to why it was acting that way.
then do
if btye = allthewayrightkey
servoright = 1110
if byte = allthewayleftkey
servoleft = 220

or whatever values make the servo go all the way. after that, use a loop to send the servo command to the servo for about 1 second, giving it enough time to move to the location
I tried it that way and I was getting sporadic behavior as mentioned in a post earlier up.

I realized that it only acted oddly when it was above 900 cycles but it worked okay when I was just hitting the key so I tried this but to no avail.
Code: [Select]
long int servo_1=700;

void servo_left(void)
{
if(servo_1>=900)
{
while(servo_1>=900)
{
servo_1--;
}
}
servo_1=280;
}
void servo_right(void)
{
servo_1=1119;
}
void servo_middle(void)
{
if(servo_1>=900)
{
while(servo_1>=900)
{
servo_1--;
}
}
servo_1=700;
}
void control(void)
{
while(1)
{
char cByte = uart1GetByte(); // get byte from UART1 on the axon
if (cByte == 'r') // if character received is b then
{
servo_right();
}
if (cByte == 'l')
{
servo_left();
}
if (cByte == 'm')
{
servo_middle();
}
servo_1(servo_1);
rprintf("%d\r\n",servo_1);
}
}


Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: Axon servo problem
« Reply #15 on: February 20, 2009, 05:45:58 PM »
try renaming

long int servo_1=700;

to something else like my_servo_1=700;

then all of the rest with it

then at the bottom have

servo_1(my_servo_1);


I really think this is the problem, there is no distinction between the servo_1 variable and the servo_1 function

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: Axon servo problem
« Reply #16 on: February 20, 2009, 07:15:25 PM »
I tried that and the same thing happened. The weird thing is I don't think it's hardware problem because the roborealm servo controller worked perfectly.
« Last Edit: February 20, 2009, 07:32:29 PM by Jdog »

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: Axon servo problem
« Reply #17 on: February 20, 2009, 07:53:26 PM »
Another weird thing, I tried my functions without the hyperterminal code and each one worked perfectly. It's very weird how when I add in the if the byte is this code then it acts very weirdly.
For example:
This works fine:
Code: [Select]
long int my_servo=700;
void servo_middle(void)
{
my_servo=700;
delay_ms(20);
}
void control(void)
                {
                 while(1)
                                {
                                 servo_middle();
                                }
                 }
But this acts weirdly:
Code: [Select]
long int my_servo=700;

void servo_left(void)
{
my_servo=280;
delay_ms(20);
}
void servo_right(void)
{
my_servo=1110;
delay_ms(20);
}
void servo_middle(void)
{
my_servo=700;
delay_ms(20);
}
void control(void)
{
while(1)
{
char cByte = uart1GetByte(); // get byte from UART1 on the axon
if (cByte == 'm')
{
servo_middle();
}
servo_1(my_servo);
rprintf("%d\r\n",my_servo);
}

}

Do you think maybe I should do a while cbyte == 'm' instead of if?
« Last Edit: February 20, 2009, 08:02:38 PM by Jdog »

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: Axon servo problem
« Reply #18 on: February 20, 2009, 08:10:55 PM »
Ive a funny feeling it may be the uart interrupt. admins code that seems to work has this line:

if(cByte!=-1)//no new data
         {




I know that this isnt perfect for your means but by moving

servo_1(my_servo);
rprintf("%d\r\n",my_servo);

outside of the if statement (along with the statutory delay) then it should work for you.

also another thing... admin has a delay of 50ms and not 20ms (this can also cause erratic servo behaviour if you got it wrong)

Code: [Select]
long int my_servo=700;

void servo_left(void)
{
my_servo=280;
}
void servo_right(void)
{
my_servo=1110;
}
void servo_middle(void)
{
my_servo=700;
}
void control(void)
{
while(1)
{

                                           if(cByte!=-1)//no new data
                           {

                          if (cByte == 'm')
        {
                    servo_middle();
        }



                                           }//end of if

                                           servo_1(my_servo);
           rprintf("%d\r\n",my_servo);
                                           delay_ms(50);




                                 }//end of while

« Last Edit: February 20, 2009, 08:14:53 PM by paulstreats »

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: Axon servo problem
« Reply #19 on: February 20, 2009, 08:37:41 PM »
Ive a funny feeling it may be the uart interrupt. admins code that seems to work has this line:

if(cByte!=-1)//no new data
         {




I know that this isnt perfect for your means but by moving

servo_1(my_servo);
rprintf("%d\r\n",my_servo);

outside of the if statement (along with the statutory delay) then it should work for you.

also another thing... admin has a delay of 50ms and not 20ms (this can also cause erratic servo behaviour if you got it wrong)

Code: [Select]
long int my_servo=700;

void servo_left(void)
{
my_servo=280;
}
void servo_right(void)
{
my_servo=1110;
}
void servo_middle(void)
{
my_servo=700;
}
void control(void)
{
while(1)
{

                                           if(cByte!=-1)//no new data
                           {

                          if (cByte == 'm')
        {
                    servo_middle();
        }



                                           }//end of if

                                           servo_1(my_servo);
           rprintf("%d\r\n",my_servo);
                                           delay_ms(50);




                                 }//end of while

I tried what you suggested and everything acted the same. The code I used was:
Code: [Select]
long int my_servo=700;

void servo_left(void)
{
my_servo=280;
delay_ms(50);
}
void servo_right(void)
{
my_servo=1110;
delay_ms(50);
}
void servo_middle(void)
{
my_servo=700;
delay_ms(50);
}
void control(void)
{
while(1)
{
char cByte = uart1GetByte(); // get byte from UART1 on the axon
if(cByte!=-1)
{
if (cByte == 'r') // if character received is b then
{
servo_right();
}
if (cByte == 'l')
{
servo_left();
}
if (cByte == 'm')
{
servo_middle();
}
}
servo_1(my_servo);
rprintf("%d\r\n",my_servo);
}

}


Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,659
  • Helpful? 169
    • Society of Robots
Re: Axon servo problem
« Reply #20 on: February 20, 2009, 09:03:42 PM »
Please show us the code for this function:
Code: [Select]
servo_1(my_servo);
Now using my code:
http://www.societyofrobots.com/robotforum/index.php?topic=7018.msg53419#msg53419

I made a slight change based on what you wanted:
Code: [Select]
int gripper=500;
char cByte;

rprintfInit(uart0SendByte);
while(1)
{
cByte=uart0GetByte(); //get byte from UART0 on the axon
if(cByte!=-1)//no new data
{
if (cByte == 'q')
LED_on();
if (cByte == 'w')
LED_off();
if (cByte == 'e')
gripper=280;//modified
if (cByte == 'r')
gripper=1110;//modified

servo(PORTH,3,gripper);
rprintf("grip:%d photo:%d\r\n",gripper,a2dConvert8bit(0));
delay_ms(50);
}
}

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: Axon servo problem
« Reply #21 on: February 20, 2009, 09:13:24 PM »
Code: [Select]
servo_1(my_servo)That's just saying that the servo_1 I defined in hardware.c is what I'm referring to when I say my_servo. It's what you did in the example photovore code and it doesn't work without it.

You're code worked perfectly :P. So the question is why didn't mine? What's the difference between
Code: [Select]
while(1)
{
cByte=uart1GetByte(); //get byte from UART0 on the axon
if(cByte!=-1)//no new data
{
if (cByte == 'm')
gripper=700;
if (cByte == 'e')
gripper=280;//modified
if (cByte == 'r')
gripper=1110;//modified

servo_1(gripper);
rprintf("grip:%d photo:%d\r\n",gripper,a2dConvert8bit(0));
delay_ms(50);
}
}
and
Code: [Select]
long int my_servo=700;

void servo_left(void)
{
my_servo=280;
delay_ms(50);
}
void servo_right(void)
{
my_servo=1110;
delay_ms(50);
}
void servo_middle(void)
{
my_servo=700;
delay_ms(50);
}
void control(void)
{
while(1)
{
char cByte = uart1GetByte(); // get byte from UART1 on the axon
if(cByte!=-1)
{
if (cByte == 'r') // if character received is b then
{
servo_right();
}
if (cByte == 'l')
{
servo_left();
}
if (cByte == 'm')
{
servo_middle();
}
}
servo_1(my_servo);
rprintf("%d\r\n",my_servo);
}
« Last Edit: February 20, 2009, 09:24:39 PM by Jdog »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,659
  • Helpful? 169
    • Society of Robots
Re: Axon servo problem
« Reply #22 on: February 20, 2009, 09:17:11 PM »
Quote
Didn't I already define this servo in hardware.c? Wouldn't this code mess it up unless I exclude hardware.c and if so how do I do that or what code should I use instead of this?
To help solve your problem, we should use my code (that we know works), and mix it with your cycle values (which could potentially be the problem).

After that, the next step would be to replace this line:
Code: [Select]
servo(PORTH,3,gripper);
with yours:
Code: [Select]
servo_1(gripper)
That will show whether your servo_1() function is written correctly or not. ;D

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: Axon servo problem
« Reply #23 on: February 20, 2009, 09:32:26 PM »
Admin, I believe you looked at my post before I edited it, look again :P.
Also I was wondering if I could have it look for 2 bytes or a certain amount of bytes so I could have the robot do something when I type in a certain phrase.
« Last Edit: February 20, 2009, 09:35:11 PM by Jdog »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,659
  • Helpful? 169
    • Society of Robots
Re: Axon servo problem
« Reply #24 on: February 20, 2009, 09:36:36 PM »
I suspect its still this line:
servo_1(gripper);

Use this:
servo(PORTH,3,gripper);

and report back :P

Offline JdogTopic starter

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: Axon servo problem
« Reply #25 on: February 20, 2009, 11:59:00 PM »
Mine did work when I tried servo_1(gripper). I was just wondering what the difference between the code you provided and the code I wrote that I abandoned didn't work when they seem like they should be doing the same thing. Nevermind it's unimportant, but thank you anyway.

 


Get Your Ad Here

data_list