Shop OBEX P1 Docs P2 Docs Learn Events
Project Plug, and am I trying to start too many cogs? — Parallax Forums

Project Plug, and am I trying to start too many cogs?

mhamen3mhamen3 Posts: 69
edited 2013-05-28 22:06 in Propeller 1
Hi Guys,

I've been working on a hybrid quad/tank robot and, while programming has been going pretty well for the most part, I've hit a snag. Shown below is a snippet of my OBJ block and my start method. For some reason, I don't think the Gait method is starting even though I believe the Startup method is only trying to call 8 cogs.
OBJ
  SERVO  : "Servo32v7"
  XB     : "Xbee_Object_2"
  FLTF   : "Float32Full"
  FLT    : "Float32"
 
PUB StartUp  
  Servo.Start
  XB.Start(XB_Rx,XB_Tx,0,XB_Baud)
  FLTF.Start
  FLT.Start
  
  cognew(RotSumIK, @RotTranStack)
  cognew(Gait, @GaitStack)
    
  SUMnSEND

Here's what I believe should be happening: The Startup method runs on cog0, Servo32v7 starts on cog1, XBeeObject starts on cog2, Float32Full starts on cog3 and cog4, Float32 starts on cog5, RotSumIK starts on cog6, Gait starts on cog7 then the startup method calls SUMnSEND and that runs on cog0. Is my understanding wrong?

EDIT: For clarification, both Float32Full and Float32 are used so that the RotSumIK method and Gait method don't try to call on the same method at the same time. Float32Full is used for RotSumIK and Float32 for gait.

Here's a vid of the bot running RotSumIK and Gait separately, haven't been able to incorporate remote control with gait yet.

I've got a flickr account with some pics of how I manufactured it as well, if you're interested. http://www.flickr.com/photos/marcbots/sets/72157631912836115/detail/?page=2

Thanks for any help.
-Marc

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2013-05-26 19:37
    mhamen3 wrote: »
    For some reason, I don't think the Gait method is starting even though I believe the Startup method is only trying to call 8 cogs.
    You could always check the result of cognew, e.g.
    if cognew(Gait, @GaitStack) == -1
        waitpne(0, 0, 0)   ' stop, do some indication here
    
    Are your stacks big enough?
  • mhamen3mhamen3 Posts: 69
    edited 2013-05-26 19:46
    Thanks for the reply. I'll check that.

    I think the stacks are fine. If I run the Gait method or RotSumIK methods on their own they work without a hitch. And I use float32 and float32full because the Gait and RotSumIK methods run in parallel on separate cogs and both use floating point math. Things get a little wonky if 2 cogs try to call the same method at the same time. Float32Full is used in RotSumIK for the Acos, Atan and Asin functions and the gait engine only needs Sin, cos and tan so it uses Float32.
  • kuronekokuroneko Posts: 3,623
    edited 2013-05-26 19:53
    mhamen3 wrote: »
    And I use float32 and float32full because the Gait and RotSumIK methods run in parallel on separate cogs and both use floating point math.
    Yes, I figured as much ... As for stacks, make them really big initially (64+ longs). This can always be adjusted later. E.g. the stack usage of RotSumIK may be too big and said method may use the (head of) stack of Gait as well assuming they're defined next to each other.
  • mhamen3mhamen3 Posts: 69
    edited 2013-05-26 20:39
    Thanks a lot for the tips, kuroneko. I'll check that as well.
  • mhamen3mhamen3 Posts: 69
    edited 2013-05-28 18:53
    I got it working. The stacks were fine and I'm still not sure what was holding it back but using kuroneko's tip of having the cognew command in an IF statement worked.
    IF cognew(Gait,@gaitstack)  == -1
      Test   'some signifier it didn't work
    ELSE
      'carry on as usual
    

    Thanks, kuroneko. Any ideas why this caused the Gait method to launch and just using cognew didn't?
  • kuronekokuroneko Posts: 3,623
    edited 2013-05-28 19:04
    Just the fact that you check the result shouldn't affect whether the cog runs or not (as such). AFAICS only the timing changes in that the Gait method starts a bit later. Hard to suggest anything else without seeing the source.
  • mhamen3mhamen3 Posts: 69
    edited 2013-05-28 20:16
  • kuronekokuroneko Posts: 3,623
    edited 2013-05-28 20:29
    Why do you start Gait twice (StartUp & RotSumIK)? Having them both in there would explain a lot ...
  • mhamen3mhamen3 Posts: 69
    edited 2013-05-28 22:06
    Oops, left over artifact from experimentation. The code works as expected without the cognew for gait in RotSumIK, still wonky if I don't have the IF statement in StartUp.
Sign In or Register to comment.