Shop OBEX P1 Docs P2 Docs Learn Events
increasing servo start position error using a series of steps — Parallax Forums

increasing servo start position error using a series of steps

graffixgraffix Posts: 389
edited 2011-11-28 13:21 in BASIC Stamp
I wrote a quick code for increasing the step pattern of a servo.As the program progresses through the start position moves slightly.Any ideas how to correct this cumulative error?I suspect its a timing problem.I tried adding an extra pause in different spots with different values,but it effected the step speed.
' {$STAMP BS2}
' {$PBASIC 2.5}
ramp_start_end_position       VAR     Word
FOR ramp_start_end_position = 175 TO 1120
  PULSOUT 15, ramp_start_end_position
  PAUSE 20
 NEXT
 FOR ramp_start_end_position = 175 TO 1120 STEP 2
  PULSOUT 15, ramp_start_end_position
  PAUSE 20
 NEXT
 FOR ramp_start_end_position = 175 TO 1120 STEP 3
  PULSOUT 15, ramp_start_end_position
  PAUSE 20
 NEXT
 FOR ramp_start_end_position = 175 TO 1120 STEP 4
  PULSOUT 15, ramp_start_end_position
  PAUSE 20
 NEXT
 FOR ramp_start_end_position = 175 TO 1120 STEP 5
  PULSOUT 15, ramp_start_end_position
  PAUSE 20
 NEXT
 FOR ramp_start_end_position = 175 TO 1120 STEP 6
  PULSOUT 15, ramp_start_end_position
  PAUSE 20
 NEXT
 FOR ramp_start_end_position = 175 TO 1120 STEP 7
  PULSOUT 15, ramp_start_end_position
  PAUSE 20
 NEXT
 FOR ramp_start_end_position = 175 TO 1120 STEP 8
  PULSOUT 15, ramp_start_end_position
  PAUSE 20
 NEXT

FYI:the test servo is not a parallax brand

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-11-28 07:28
    FOR ramp_start_end_position = 175 TO 1120
    PULSOUT 15, ramp_start_end_position
    PAUSE 20

    That PAUSE has to be 20ms - the PULSOUT time or you'll blow the 20msec period.

    *** You likely need to loose a few msec for code execution time, too, a little 'fudge factor'.
  • graffixgraffix Posts: 389
    edited 2011-11-28 07:32
    ok,forgive me PJ so it should be ?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-11-28 07:36
    The servo has to get ticked every 20msec.

    So you PAUSE for 20msec - the time of the PULSOUT (previous) - x_msec (2-3?)
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-11-28 07:39
    And... is 175 a valid servo PULSOUT?
    I don't have the PBASIC reference here in fron of me (PULSOUT x = ??usec), is it 2?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-11-28 07:53
    I think the valid range of servo pulses is approx 1000-2000 usec (1-2msec).
    So the ramp_start_end PULSOUTs should range 500-1000.
    PAUSE 17 ought to get you there, +/-.
  • graffixgraffix Posts: 389
    edited 2011-11-28 08:20
    I'm reading WAM v.3 pdf. it seems to go into some more detail on the topic than the version 2.2 book I own.So I'll get back to this post in a bit.TY
  • ercoerco Posts: 20,256
    edited 2011-11-28 08:35
    Each time one of your for/next loops ends at 1120, you instantly start the next loop at 175 (you sure about that number?). You aren't giving the servo any time to return to the 175 starting position. Insert a loop like this between each of your current for/next loops (you could make it a subroutine to save space):

    for b0=1 to 30' adjust this number of loops to make sure the servo has time to return to the initial position
    pulsout 15,175
    pause 20
    next
  • graffixgraffix Posts: 389
    edited 2011-11-28 08:45
  • graffixgraffix Posts: 389
    edited 2011-11-28 09:43
    I'm not sure on any of it.b0 I thought was a variable.lol First I recall seeing it was yesterday on ercos post.I was wondering why it came up purple in the editor.I looked it up in the syntax ref. today and it all seems greek to me.ps I dont know greek
    perhaps writing a whole code that does what I want would help.I was under the impression that the 175 was a start point for the servo.To get a full range of motion in the first loop.I know you dont like doing it.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-11-28 12:13
    It's like you forgot everything you did with the Labyrinth project or something?
  • graffixgraffix Posts: 389
    edited 2011-11-28 13:21
    Your smarter than that.So I thought.There isnt one servo ramp in that code its right there.Yes that's what I was working on earlier today.Before I only managed to control it with a memsic.There was more I wanted to do with it.One would be code it to do it autonomously.Two would be wireless control via 433 transceiver.that I could do.Also I'd like to try and mount a memsic under it and output info on a lcd.
    After my last post earlier I had to go to my real job:)Also that project was how long ago?6months I've remodeled most of the house I just sold.Done major renovations on the house I live in now.While caring for three kids two of which are under the age of two.A blind grandmother who just past away end of August.Amongst other things.Most of the time I'll get ten minutes here and there in between that stuff or lose sleep trying to do it at night after work.yes I forgot some thanks.-1
Sign In or Register to comment.