Shop OBEX P1 Docs P2 Docs Learn Events
PBasic Problems: Wheel_Motion.bs2 — Parallax Forums

PBasic Problems: Wheel_Motion.bs2

koolitudekoolitude Posts: 37
edited 2007-03-18 05:43 in BASIC Stamp
I've been trying to modified the Wheel_Motion.bs2 : http://www.parallax.com/dl/sw/Encoder.zip

Since I would like to use a digital compass (together with the encoders) to provide feedback signals to control my robot, I try to add a GetBearing subrountine (a subrountine to read the compass bearing using I2C) to the DoMove subrountine (the original subrountine to perform wheels coordination in Wheel_Motion.bs2).

The compass provides information which serves as the absolute reference for the robot.· The idea is to correct the error due to the·problem of relative referencing method·used by wheel coordination.·

So, I try to read the compass before every signal pulse to be generated by the DoMove subrountine to the servo motors.· However, whenever I add GetBearing into DoMove, the DoMove will be executed again and again.
In other words, originally without adding GetBearing, DoMove will be executed once; after adding GetBearing to the first line of DoMove, it·repeats itself a few seconds after finishing the previous DoMove.

It is quite abnormal as the GetBearing subrountine has nothing to do with the DoMove subrountine; the former one is just to read the compass using I2C protocol while the later one is just an algorithm to determine the value to pulse the servo motors.·

I am so confused.· I would be grateful if you could give me some advices.

Attached please also find the modifed .bs2 file·(Wheel_Motion_Compass) on which·I'm now working.

Thank you very much.

P.S. I'm using a CMPS03 compass module: http://www.robot-electronics.co.uk/htm/cmps3doc.shtml


Post Edited (koolitude) : 3/16/2007 7:29:56 AM GMT

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-03-16 07:42
    Your subroutines are nested too deeply:

    ··Main -> Move -> DoMove -> GetBearing -> I2CWordRead -> I2CStart

    The limit is four.

    -Phil
  • koolitudekoolitude Posts: 37
    edited 2007-03-17 17:01
    Thank you very much Phil! You're very helpful.

    So... in order to solve this, I gotta combine some subrountines into one, right?

    or... there is another smarter way to fix this problem?

    Thank you very much! =)
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-03-17 18:16
    Calling GetBearing from Main, rather than from DoMove, would do the job.

    -Phil
  • koolitudekoolitude Posts: 37
    edited 2007-03-18 05:43
    yea... that would be a good idea if GetBearing is the only thing I would like to do...

    cuz I would like to check the compass bearing just before any single pulse to be generated by DoMove...

    If I call GetBearing from Main, then I just check the compass bearing once for every Move I called...

    Anyway, thank you very much for your suggestion.. =)

    Post Edited (koolitude) : 4/10/2007 10:06:41 AM GMT
Sign In or Register to comment.