Shop OBEX P1 Docs P2 Docs Learn Events
problems with repeat and quit — Parallax Forums

problems with repeat and quit

nomadnomad Posts: 276
edited 2007-03-01 09:42 in Propeller 1
hi
i have a problem in my program.
-> in repeat
··· -> the whohle repeat-statement stopped
········if the littlest value is stopped

also
PUB ElbowServo3
· .................
· ............
· if ticks3 == 4
····QUIT

ShoulderServo1 = stopped
ShoulderServo2 = stopped

have somebody a solutions for this problem????
·····
all help is welcome
regards
nomad

attachment: LegSequencer.spin

part of the program:
......................
PUB Main
· Init
··
· cognew(ShoulderServo1,@cogStack1)
· cognew(ShoulderServo2,@cogStack2)
· cognew(ElbowServo3,@cogStack3)

· zeroPosition

· repeat
··· ShoulderServo1
··· if ticks1 == 96
····· QUIT
·····
··· ShoulderServo2
··· if ticks2 == 64
····· QUIT
··· ElbowServo3
··· if ticks3 == 4
····· QUIT
.......................

PUB ShoulderServo1· ' generate servopulse· Servo1
· outa[noparse][[/noparse]2]~~
· waitcnt (timebase += pulsetime1)
· outa[noparse][[/noparse]2]~
················
· pulsetime1 += (clkfreq / 100_000)
· new_periode1 := periode1 - pulsetime1
· waitcnt (timebase += new_periode1)

· ticks1++

PUB ShoulderServo2··· ' generate servopulse· Servo2
· outa[noparse][[/noparse]3]~~···········································
· waitcnt (timebase += pulsetime2)
· outa[noparse][[/noparse]3]~
· pulsetime2 += (clkfreq /·100_000)
· new_periode2 := periode2 - pulsetime2
· waitcnt (timebase += new_periode2)

· ticks2++
····
PUB ElbowServo3·· ' generate servopulse· Servo3
· outa[noparse][[/noparse]4]~~···········································
· waitcnt (timebase += pulsetime3)
· outa[noparse][[/noparse]4]~
························································
· pulsetime3 -= (clkfreq / 100_000)····
· new_periode3 := periode3 - pulsetime3···················
· waitcnt (timebase += new_periode3)···········
···
· ticks3++
......................
..................

Comments

  • Stan671Stan671 Posts: 103
    edited 2007-02-27 16:34
    repeat 
      ShoulderServo1 
      if ticks1 == 96 
        QUIT 
    
      ShoulderServo2 
      if ticks2 == 64 
        QUIT 
    
      ElbowServo3 
      if ticks3 == 4 
        QUIT
    

    Nomad, I am not sure what you expect to happen here.· Effectively, with the three IF statements·and QUITs, if ticks1 == 96 OR ticks2 == 64 OR ticks3 == 4, then the entire REPEAT loop will stop.· That is the way it is supposed to work.

    ·
    cognew(ShoulderServo1,@cogStack1) 
    cognew(ShoulderServo2,@cogStack2) 
    cognew(ElbowServo3,@cogStack3)
    

    I am not sure why you are kicking off these three methods to thier own cogs when each method only runs once and then stops.· Usually when something is launched in a new cog, it is something that runs continously by itself until it's job is done.

    Later, in your main routine, you run these methods again.· I would think it is bad form to run a method in a new cog and also run it in your main routine.· I think you·are misunderstanding how new cogs are most effectively used.· Perhaps you mean to do something more like this:

    PUB Main 
      Init 
    
      cognew(ShoulderServo1,@cogStack1) 
      cognew(ShoulderServo2,@cogStack2) 
      cognew(ElbowServo3,@cogStack3) 
    
      zeroPosition 
    
      repeat 
    
     
    ....................... 
    
    PUB ShoulderServo1 ' generate servopulse Servo1 
    
     
      repeat 96
        outa[noparse][[/noparse]2]~~ 
        waitcnt (timebase += pulsetime1) 
        outa[noparse][[/noparse]2]~ 
    
        pulsetime1 += (clkfreq / 100_000) 
        new_periode1 := periode1 - pulsetime1 
        waitcnt (timebase += new_periode1) 
    
    
    PUB ShoulderServo2 ' generate servopulse Servo2 
    
     
      repeat 64
        outa[noparse][[/noparse]3]~~ 
        waitcnt (timebase += pulsetime2) 
        outa[noparse][[/noparse]3]~ 
    
     
        pulsetime2 += (clkfreq / 100_000) 
        new_periode2 := periode2 - pulsetime2 
        waitcnt (timebase += new_periode2) 
    
    
    PUB ElbowServo3 ' generate servopulse Servo3 
    
     
      repeat 4
        outa[noparse][[/noparse]4]~~ 
        waitcnt (timebase += pulsetime3) 
        outa[noparse][[/noparse]4]~ 
    
        pulsetime3 -= (clkfreq / 100_000) 
        new_periode3 := periode3 - pulsetime3 
        waitcnt (timebase += new_periode3) 
    
    
    

    This way, each cog runs a method that moves the servo to a specific spot and then stops.· The main routine really just does the initialization and then lauches the three cogs which move the three parts of the arms simultanously and independently.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Stan Dobrowski

    Post Edited (Stan671) : 2/27/2007 4:50:31 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-27 16:39
    You're executing two copies of each of the routines (ShoulderServo1,ShoulderServo2,ElbowServo3) at the same time, probably trying to use the same variables from each copy (one called with COGNEW and one called directly from your main program.

    I think you have to back up and think about what you're trying to do overall. This is way too complicated for what you're probably trying to do.

    Have you considered using one of the servo control objects in the Propeller Object Exchange? The Servo32 object will handle the control of up to 32 servos and let the rest of your program deal with the higher level control issues.
  • James LongJames Long Posts: 1,181
    edited 2007-02-27 16:54
    I see.....he is trying to implement all three servos at the same time. Like a simultaneous move. If he does one servo at a time..the move will not be simultaneous.

    I don't know anything about the object Mike mentioned...but they should be able to handle simultaneous moves, but I'm not sure.


    James L
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-27 17:04
    James,
    Both the Servo32 (in assembly) and Servo4 (in Spin) objects do essentially simultaneous movement. There may be some microseconds difference in time between the servo control pulses for each servo, but servo response time is on the order of milliseconds.
  • nomadnomad Posts: 276
    edited 2007-02-28 11:45
    hi
    thanks verry match for all the solutions.
    now, i think again and testing the stuff
    thanks
    regards nomad
  • nomadnomad Posts: 276
    edited 2007-02-28 12:35
    hi
    result of my testings
    1)

    PUB Main

    Init

    cognew(ShoulderServo1,@cogStack1)
    cognew(ShoulderServo2,@cogStack2)
    cognew(ElbowServo3,@cogStack3)

    zeroPosition

    ShoulderServo1
    ShoulderServo2
    ElbowServo3

    PUB ShoulderServo1
    repeat 96
    ......

    PUB ShoulderServo2
    repeat 64
    .....

    PUB ElbowServo3
    repeat 8
    .............

    Result: the servos runs one after the other
    bad...

    2)
    PUB Main

    Init

    cognew(ShoulderServo1,@cogStack1)
    cognew(ShoulderServo2,@cogStack2)
    cognew(ElbowServo3,@cogStack3)

    zeroPosition

    repeat
    if ticks1 < 96
    ShoulderServo1

    if ticks2 < 64
    ShoulderServo2

    if ticks3 < 8
    ElbowServo3


    PUB ShoulderServo1
    ......
    ticks++

    PUB ShoulderServo2
    ......
    ticks2++

    Pub ElbowServo3
    ......
    ticks3++

    Result: all 3 servos running simultan.
    Fine.


    this is what i would.
    then i can program more complex and dynamical
    behaveiors.

    when i have the whole sequence of a leg movement then i call back....

    regards
    nomad
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-28 14:11
    You will still get into trouble the way you've organized the program. If ticks1 < 96, you will execute one copy of ShoulderServo1 when another copy is executing in a separate cog. This is not what you want. The same problem occurs with ticks2 < 64 and ticks3 < 8.
  • nomadnomad Posts: 276
    edited 2007-03-01 08:30
    hi mike
    thanks for your comment.

    look what i want, is that the servos
    of the leg move on time (parallel
    and 1 servo = 1 cog) running.

    yesterday i have construct from
    a program with "servo32"
    its running but (seriell and only
    1 cog).

    have you a idea, that i can move
    the 3 servos with 3 cogs (with different moveDirections,
    speed, and counter) in parallel???

    for hints, tips source-snippets
    i am grateful.

    code:
    <<
    *******************************************************************
    Lynxmotion Extreme Hepapod III Simple Walking Routine using
    Servo32.Spin Object
    Chassis & 6 legs:


    ····························
    ····························· FRONT
    ······················· ==================
    ··········· LEG #1····· |··············· |······ LEG # 2
    ···· Ankle·· Knee·· Hip |··············· | Hip··· Knee··· Ankle
    ······················· |··············· |
    ······················· |··············· |
    ······················· |··············· |


    CON
    · _CLKMODE = RCFAST············· ' ex XTAL1 + PLL16X···· 'Set to ext crystal, 16x PLL, 80MHz Clock
    '· _XINFREQ = 5_000_000········· ' Frequency on XIN pin is 5 MHz

    ··· Leg1_Hip·· = 2············ ' Asignment of Servos to Pin Outputs of the Propeller
    ··· Leg1_Knee· = 3
    ··· Leg1_Ankle = 4

    ··

    VAR
    ··· LONG Leg1_Hip_ADJ··············· ' Variables used to fine tune/Adjust the position of every servo
    ··· LONG Leg1_Knee_ADJ·············· ' It can also be used to vary to vary height of the Hexapod
    ··· LONG Leg1_Ankle_ADJ············· ' Or shape of the legs during program execution

    ·
    OBJ
    · SERVO : "Servo32"

    PUB Hexapod_III | i

    ··· Leg1_Hip_ADJ·· :=·· 0·················· ' These values depend of the particular installation of the
    ··· Leg1_Knee_ADJ· :=· 35·················· ' Servos in every Hexapod... not every servo centers at exactly
    ··· Leg1_Ankle_ADJ :=· 50·················· ' the same location.. so these values help in adjusting the
    ··········································· ' center when a 1.5 ms pulse is sent to the servo
    ··
    ·························
    ··· 'Preset Servo's you want to use to center position

    ··· SERVO.Set(Leg1_Hip,· 1500 + Leg1_Hip_ADJ)
    ··· SERVO.Set(Leg1_Knee, 1500 + Leg1_Knee_ADJ)
    ··· SERVO.Set(Leg1_Ankle,1500 + Leg1_Ankle_ADJ)

    ·
    ··· 'Note: Servo pins that will be used must be preset before running "SERVO.Start".
    ··· '····· This is because the I/O direction is set here and is only executed
    ··· '····· at the beginning of "SERVO.Start".· Servo pins that aren't used will remain
    ··· '····· in their original direction state.

    ·SERVO.Start········································ 'Start Servo handler


    ·SERVO.Set(Leg1_Hip, 1650 + Leg1_Hip_ADJ)············ ' Reconfiguration of the Hips for

    ·repeat·····················
    ·· repeat i from 1500 to 900································ ' Raise Legs 1, 3 and 5···········
    ···· SERVO.Set(Leg1_Knee,······· i + Leg1_Knee_ADJ)
    ···· waitcnt (10_000 + cnt)
    ·································
    ·· repeat i from 1650 to 1350································ ' Move Hips
    ···· SERVO.Set(Leg1_Hip,········ i + Leg1_Hip_ADJ)
    ···· waitcnt (20_000 + cnt)

    ·· repeat i from 1500 to 900································ ' Move Ankle
    ···· SERVO.Set(Leg1_Ankle,········ i + Leg1_Ankle_ADJ)
    ···· waitcnt (20_000 + cnt)
    ··

    ·························
    ·· repeat i from 900 to 1500································· ' Lowering of Legs 1, 3 and 5···
    ···· SERVO.Set(Leg1_Knee,······· i + Leg1_Knee_ADJ)
    ···· waitcnt (50_000 + cnt)
    ·····························
    ·· repeat i from 1650 to 1350································· ' Move Hips···
    ···· SERVO.Set(Leg1_Hip, 3000· - i + Leg1_Hip_ADJ)
    ···· waitcnt (20_000 + cnt)

    ·· repeat i from 900 to 1500································· ' Lowering of Legs 1, 3 and 5···
    ···· SERVO.Set(Leg1_Ankle,······· i + Leg1_Ankle_ADJ)
    ···· waitcnt (50_000 + cnt)
    ····································
    ·
    ·····················
    >>

    regards
    nomad
  • nomadnomad Posts: 276
    edited 2007-03-01 09:42
    hi mike

    here my newest code (from Beau's Servo32_Demo.spin

    now its parallel running , but i have (i mean only one cog)?

    its possible, that the code can react dynamical on enviroment-datas

    (sensorDatas)??? z.B if the Foot have contact with the floor => then

    stop the whole stuff).

    regards

    nomad

    <<

    {
    · Servo32_Demo1.spin
    }
    CON
    ···· _CLKMODE = RCFAST

    ··· PanServo1 = 2

    ··· PanServo2 = 3
    ··· PanServo3 = 4

    ···
    OBJ
    · SERVO : "Servo32"

    PUB Servo32_DEMO | temp

    ··· 'Preset Servo's you want to use to center position
    ··· SERVO.Set(PanServo1,1500)
    ··· SERVO.Set(PanServo2,1500)
    ··· SERVO.Set(PanServo3,1500)
    ··

    ··· SERVO.Start········································ 'Start Servo handler
    ··
    ··· repeat

    ··· repeat temp from 1000 to 2000
    ····· waitcnt (cnt+125_000)
    ····· SERVO.Set(PanServo1,temp)
    ····· SERVO.Set(PanServo2,temp)
    ····· SERVO.Set(PanServo3,3000-temp)

    >>
Sign In or Register to comment.