Author Topic: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)  (Read 1685 times)

0 Members and 1 Guest are viewing this topic.

Offline kjleitzTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
I've been trying for a week to get a servo to even do *anything*, but they don't turn on or even twitch. I've tried multiple servos in multiple ports, using hardware and software PWM. I assume it's a problem with my terrible programming skills. Here's my code:

Code: [Select]
#include "sys/axon2.h"
#include "uart.h"
#include "rprintf.h"
#include "servos.h"
#include "a2d.h"

// Make my one lonely servo
SERVO elbow_servo = MAKE_SERVO(FALSE, H5, 1500, 500);

SERVO_LIST servos[] = {&elbow_servo};

SERVO_DRIVER bank1 = MAKE_SERVO_DRIVER(servos);

// Initialize hardware
void appInitHardware(void){

// Initialize USB
uartInit(UART1, 115200);

// rprintf to USB
rprintfInit(&uart1SendByte);

// Initialize hardware PWM servos
servoPWMInit(&bank1);

// Pretty sure this is how they are initially
// set, but it couldn't hurt to set it to stop.
act_setSpeed(&elbow_servo, 0);

}

// Initialize software
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
return 0; // Don't stop, man!
}


// Start main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){

while(1){
// Set servo to center
act_setSpeed(&elbow_servo, DRIVE_SPEED_CENTER);
delay_ms(20);

// Print the speed
uint8_t speed1 = act_getSpeed(&elbow_servo);
rprintf("Servo speed: %u\n", &speed1);
}

return 20000;
}

Can anyone tell me what's wrong? I'm building a quadruped, so servos are kind of a must.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
« Reply #1 on: July 03, 2011, 10:45:50 AM »
Plug your servo into H5 and try this code below. Also, check your battery to make sure it's fully charged and that your servo isn't plugged in backwards (hey, it happens to the best of us sometimes :P).

Code: [Select]
#include "sys/axon2.h"
#include "uart.h"
#include "rprintf.h"
#include "servos.h"
#include "a2d.h"

// Make my one lonely servo
SERVO elbow_servo = MAKE_SERVO(FALSE, H5, 1500, 500);

SERVO_LIST servos[] = {&elbow_servo};

SERVO_DRIVER bank1 = MAKE_SERVO_DRIVER(servos);

// Initialize hardware
void appInitHardware(void){

// Initialize USB
uartInit(UART1, 115200);

// rprintf to USB
rprintfInit(&uart1SendByte);

// Initialize hardware PWM servos
servoPWMInit(&bank1);

// Pretty sure this is how they are initially
// set, but it couldn't hurt to set it to stop.
act_setSpeed(&elbow_servo, 0);

}

// Initialize software
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
return 0; // Don't stop, man!
}


// Start main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){

// Set servo to left
act_setSpeed(&elbow_servo, -70);
delay_ms(2000);

// Set servo to right
act_setSpeed(&elbow_servo, 70);
delay_ms(2000);

// Print the speed
uint8_t speed1 = act_getSpeed(&elbow_servo);
rprintf("Servo speed: %u\n", &speed1);

return 0;
}

Offline kjleitzTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
« Reply #2 on: July 03, 2011, 04:01:33 PM »
Thanks for the quick response! So, I tried what you gave me; nothing happened. The servo doesn't move, doesn't seem to even turn on. It's able to be turned easily by hand, and when I do, the little red "power" light briefly lights up.

I checked the battery, it's unlikely that's the problem; it's fully charged, and I also tried with simply making a 6V battery pack out of AAs. Still nothing. I'm very confused.

Also, I only just realized it would be important to note (sorry) that hyperterminal (and minicom in linux) returns "Servo speed: 8677" repeatedly, with no change to the value.

I've also noticed in other servo-test-programs I've made that this [or a similar] number increases by 2 each time if I have a servo do this upon pressing a button: DRIVE_SPEED_CENTER, then delay_ms(20), then DRIVE_SPEED_MAX, then delay_ms(20), then DRIVE_SPEED_MIN, then delay_ms(20), printing the getSpeed value after each delay. Regardless of the order of min/max/center, it increases by two each time, then when I press the button and does it again the same way with the original three numbers.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
« Reply #3 on: July 03, 2011, 04:15:45 PM »
First, with everything plugged in, measure the voltage across the power bus that the servo is on. It should match the battery voltage exactly.

And if that checks out fine, there is a chance that your servo is fried . . . Using only a battery and the servo (no Axon), power up the servo using the battery. You'll need jumper wires to do this. Now with a 3rd wire, connect one end to the + of your battery, and flick the other end very quickly across the signal line of your servo many times. The servo should twitch if it is ok.

Quote
I only just realized it would be important to note (sorry) that hyperterminal (and minicom in linux) returns "Servo speed: 8677" repeatedly, with no change to the value.
try this:
Code: [Select]
// Print the speed
int8_t speed1 = act_getSpeed(&elbow_servo);
rprintf("Servo speed: %d\n", &speed1);

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 109
Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
« Reply #4 on: July 03, 2011, 04:50:31 PM »
try this:
Code: [Select]
// Print the speed
int8_t speed1 = act_getSpeed(&elbow_servo);
rprintf("Servo speed: %d\n", &speed1);

Thats not gonna work either. Since you've put an '&' in front of 'speed1' in the rprintf then you are printing the memory address of the 'speed1' variable (which will always be constant) rather than the contents of the variable. So use this instead:
Code: [Select]
// Print the speed
DRIVE_SPEED speed1 = act_getSpeed(&elbow_servo);
rprintf("Servo speed: %d\n", speed1);
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
« Reply #5 on: July 03, 2011, 05:13:53 PM »
man, I'm just not paying attention these days lol . . .

Offline kjleitzTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
« Reply #6 on: July 03, 2011, 06:10:09 PM »
Haha, thanks for catching the getSpeed bug, that helped! It now reads the correct value.

As for the voltage across the power bus: I looked all over and couldn't find my voltmeter, so just as a test I ran a couple different little Christmas-tree-light replacements across both the 5V regulated and unregulated power buses. Lo and behold, the lights worked across the 5V but not across the unregulated.

I also tried the direct-to-power trick with the servo, and the servo worked! So, do you think the unregulated bus is faulty, then?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
« Reply #7 on: July 03, 2011, 06:34:34 PM »
Are you plugging the battery into the regulated bus, or on the B pin?

Flip your Axon 2 over. Is the power bus jumper soldered?

(to know what I'm talking about, go here and scroll down to VOLTAGE TOLERANCES)

There is a possibility you have it in dual battery configuration, in which case you need to solder a small jumper across two pins as shown at 0:21 in this video below. It should have shipped to you already soldered, but there is a possibility I missed it. It takes like 5 seconds to do, so no worries.

Axon II MCU Power Selection

Offline kjleitzTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
« Reply #8 on: July 03, 2011, 06:59:38 PM »
Oh, man! I've watched that video eight times for whatever reason, and it never occurred to me to check! It's in the dual-battery configuration, thanks so much! *off to grab my iron*

EDIT: And it works! I'm so happy, it's like feeling a pregnant woman's belly kick! Well, maybe that's exaggerating. But hey, I've been perplexed for literally a week, I think it's apt. Thank you so much, both of you!
« Last Edit: July 03, 2011, 08:01:08 PM by kjleitz »

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 109
Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
« Reply #9 on: July 04, 2011, 12:24:36 PM »
Glad you got it going and that 'the birth' was smooth.
You may want to checkout my Project Designer http://webbot.org.uk - it gives you a drag'n'drop visual way to build your project, shows you how to connect sensors etc, and also generates example code (for servos it will make them backwards and forwards).

Good luck
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline kjleitzTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
« Reply #10 on: July 04, 2011, 03:53:49 PM »
I've actually been using that pretty extensively, it's a great tool! I'm experimenting with Gait Designer now, actually. The only reason I didn't use it for that test was because I wanted to keep it simple and in one file, since I thought it was faulty programming. Great programs, though! Keep up the awesome work! You've vastly improved hobbyist robotics.

 


Get Your Ad Here

data_list