Servo not working on dagu rover 5 from sparkfun

WP_20140619_002.jpg (341869Bytes)
WP_20140619_004.jpg (382355Bytes)
Schermafbeelding_2014-06-19_om_15.15.34.png (155615Bytes)

Hello everyone!

i've made a robot but the servo (a Standard Servo from Parallax) I use doesn't work, it turns all the time to one side, even if i don't use it!

I connected it to a 20M2, the servo does work when the robot isn't moving but from the moment it moves, the servo turns.

Here's the code:

symbol LTPWM =C.2
symbol RTPWM =C.3
symbol LTDir =C.1
symbol RTDir =C.4
symbol IR =C.7
symbol RServo = B.0

;setup
servo RServo, 145
pause 1500
high RTDir ;by default forward
high LTDir

;wait some seconds
nap 8

;main 1
do
    ;measure front view
    readadc IR, b0
    ;if there is an object in front, then look left and right
    if b0 >105 then
        low LTPWM
        low RTPWM
        servopos RServo, 40
        pause 1500
        readadc IR, b1
        servopos RServo, 220
        pause 1500
        readadc IR, b2
        servopos RServo, 145
        ;choose the best direction, if both directions are good, then take by default the left direction
        if b1>b2 then
            low LTDir
            high RTPWM
            high LTPWM
            pause 750
            high LTDir
            low RTPWM
            low LTPWM
        else
            low RTDir
            high LTPWM
            high RTPWM
            pause 750
            high RTDir
            low LTPWM
            low RTPWM
        endif
    ;if there is no object in front, then go forward
    else
        high LTPWM
        high RTPWM
    endif
loop

;compiler commands
#PICAXE 20M2

 

Here are some pictures:

The upper left connection is the servo, the bottom left is the analogue sensor and the in the bottom right are the connections for the Dagu Rover 5 Motor Driver Board.

Maybe a dumb question…

… but can noise of the motors jam servos?

i have that same servo

that servo has a trim its the hole in the side with the yello phillips head

So confusing…

i’ve tried it now with this:

servo 0, 145
wait 2
do
    servopos 0, 40
    wait 2
    readadc C.7,b0
    servopos 0, 220
    wait 2
    if b0>100 then
        high C.3
        high C.2
    else
        low C.3
        low C.2
    endif
    servopos 0, 145
loop

all working well…

Will check the other program

I think I got it!

Maybe i have to put the servo command AFTER the nap, now the power get shutdown so then the servo command has to be repeated, right?

Why are you using nap instead of pause or sleep?

Taking a quick 4 second power nap before you actually run your main code seems odd to me.

Minor critique. Your code looks very nice apart from your magic numbers. :slight_smile: Make your left, right, center, obstacle numbers in to symbols at the start of your program and you only have to change them once, if you really need to. There is no longer hunting through the program to make sure you get them all changed.