Shop OBEX P1 Docs P2 Docs Learn Events
Parallax servos rotate randomly — Parallax Forums

Parallax servos rotate randomly

jmerrelljmerrell Posts: 25
edited 2013-10-15 05:43 in General Discussion
I am trying to rotate 2 servos independently, which are each activated from a laser beam which hits a photo diode for each servo. Other minor circuitry in schematic. I would like each servo to rotate as its photo diode is hit with the laser and NOT rotate again until it is hit with the laser again, however the servos rotate at random...once at the start of the program and then after being hit with the laser. Is there someone who knows why? My PBASIC program is shown below. Thanks!


' {$STAMP BS2}
' {$PBASIC 2.5}

'========DIR===========================================
'OUTH = %00000000
'DIRH = %11111111

'=======VARIABLES======================================
counter VAR Word

'=======MAIN===========================================
MAIN:
DO
IF IN1 = 1 THEN
GOSUB TARGET1
ELSEIF IN2 = 1 THEN
GOSUB TARGET2
ELSEIF IN3 = 1 THEN
GOSUB TARGET3
ELSEIF IN4 = 1 THEN
GOSUB TARGET4
ENDIF
LOOP

'========SUBROUTINES====================================
Target1:

DEBUG "Target 1 hit", CR 'Target 1 hit"
FOR counter = 1 TO 25
PULSOUT 15,1400 'Servo rotates DOWN"
PAUSE 20
NEXT
FOR counter = 1 TO 25
PULSOUT 15, 660 'Servo rotates UP"
PAUSE 20
NEXT
PAUSE 2000
LOW IN1
RETURN


'
Target2:

DEBUG "Target 2 hit", CR 'Target 2 hit"
FOR counter = 1 TO 25
PULSOUT 14,1400 'Servo rotates DOWN"
PAUSE 20
NEXT
FOR counter = 1 TO 25
PULSOUT 14, 660 'Servo rotates UP"
PAUSE 20
NEXT
PAUSE 2000
'LOW IN2
RETURN

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2013-10-14 14:25
    jmerrell wrote: »
    ...however the servos rotate at random...once at the start of the program and then after being hit with the laser. Is there someone who knows why? My PBASIC program is shown below. Thanks!

    Once at the start of the program, then after being hit with the laser? That does not sound random. It is normal for servos to twitch briefly when powered up - and aren't they supposed to rotate after being lasered?

    I would add some code before the main loop to center the servos, that may help.

    Also, it is important that the power supply for the servos be adequate. A 9V battery is not.
  • jmerrelljmerrell Posts: 25
    edited 2013-10-14 14:42
    Thanks for the feedback W9GFO. The servos rotate 90 degrees CW, then 90 degrees CCW as shown in the file, but occasionally keep rotating.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-10-14 14:42
    Servos should really receive a pulse every 20ms even if just to tell it to stay stopped. The way your program is now, the servos go long periods without receiving a pulse. When it does receive a pulse it has to turn itself back on and this can cause jitter.

    They likely keep rotating since they aren't told to stop rotating.

    +1 To Rich's 9V battery advice. Please don't use a 9V as servo power.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-10-14 14:45
    Are these continuous rotation servos or normal servos?
  • jmerrelljmerrell Posts: 25
    edited 2013-10-14 16:10
    Thanks Duane. I always use the BOE power supply for servos, and they are not continuous rotation. I thought by adding the line "LOW IN1" the port1 (P1) would turn off the servo by going low, but that does not happen. The intention is to rotate the servo 90 degrees, then back 90 degrees. Does anyone have any suggestions where I could code I could stop it until it receives a another signal. This has me quite baffled.
  • W9GFOW9GFO Posts: 4,010
    edited 2013-10-14 17:33
    Your main loop should be telling the servos to stop. When conditions are met you go into a subroutine that tells them to move differently, then afterwards back to the main loop where they are commanded to stop. You will have to adjust the pause time in your main loop so that the servos get a pulse approximately every 20 milliseconds. The more instructions in your main loop the more time they take to execute so the smaller the pause time. I would start with a Pause 10 and see how that goes.

    What is the BOE power supply? Is it a 9V battery, four AA batteries or a wall wart? Do not use a 9V!
  • jmerrelljmerrell Posts: 25
    edited 2013-10-14 18:42
    W9GFO, power is from a wall power supply. I will take your advice and try it out. I will let you know what happens. THANKS!!!
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-10-14 19:00
    What is the BOE power supply?
    I think this is considered the BOE Bot power supply.
  • jmerrelljmerrell Posts: 25
    edited 2013-10-15 05:43
    I am using the 7.5 VDC 1 Amp Power Supply.
Sign In or Register to comment.