Society of Robots - Robot Forum

Software => Software => Topic started by: kjleitz on July 03, 2011, 10:13:17 AM

Title: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
Post by: kjleitz on July 03, 2011, 10:13:17 AM
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.
Title: Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
Post by: Admin 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;
}
Title: Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
Post by: kjleitz 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.
Title: Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
Post by: Admin 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);
Title: Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
Post by: Webbot 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);
Title: Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
Post by: Admin on July 03, 2011, 05:13:53 PM
man, I'm just not paying attention these days lol . . .
Title: Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
Post by: kjleitz 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?
Title: Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
Post by: Admin 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 (http://www.societyofrobots.com/axon2/axon2_datasheet.shtml) 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 (http://www.youtube.com/watch?v=i2gmOtyk0DA#)
Title: Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
Post by: kjleitz 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!
Title: Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
Post by: Webbot 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 (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
Title: Re: [Axon 2, WebbotLib] Servos not working at all (TowerPro SG5010)
Post by: kjleitz 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.