Shop OBEX P1 Docs P2 Docs Learn Events
Wait for subfunction to end. — Parallax Forums

Wait for subfunction to end.

BotdocterBotdocter Posts: 271
edited 2010-05-13 00:53 in Propeller 1
Can anyone tell me how to disable 'certain' subfunctions while one of them is active?

I have some constants for driving my dc motors forward,reverse,turnleft and turnright.
But ever since i have my ping in a new cog (the ping sensor calls these functions), they start even when the last duty wasn't done yet and my motors make a noise. So that can't be right.

So how to do this?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 Parallax Propeller Robot Control Board
1 Memsic MX2125 accelerometer/ tilt
1 Parallax Ping))) ultrasonic sensor

a few motors and a whole lot of chaos!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-11 04:39
    First thing is to attach an archive with your source program in it. Your question doesn't provide enough information to understand it, let alone offer anything other than general advice.
  • BotdocterBotdocter Posts: 271
    edited 2010-05-11 14:09
    here is the archive....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-11 14:16
    There's no program in that program ... That archive has Debug_Lcd_Test, Debug_Lcd, Serial_Lcd, Simple_Numbers, and Simple_Serial and nothing else.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-05-11 15:06
    As Mike points out it's hard to assist without code, but I think your post indicates a logic flaw as well. On the surface, it doesn't make sense that your Ping (a sensor) driver would be allowed direct control over your motors. You really should let a higher level code deal with that. Start the Ping and Motor drivers as independent objects as you will, then manage them both with higher level code. That code, as suited best for your project, "asks" the Ping for its value and then passes this along to the motor control object. This will allow you to control the timing of things and prevent problems with the motor driver.

    If you've custom-coded the motor driver, then it might need an update so that it only changes at the end of the current PWM cycle.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • BotdocterBotdocter Posts: 271
    edited 2010-05-11 19:57
    Ofcourse i didn't attach the ping sensor to the motors in the hope they start spinning.

    Something went wrong with packaging the archive. I'm mobile at the moment but will post the main code when i come home.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • BotdocterBotdocter Posts: 271
    edited 2010-05-11 23:41
    here's the main code file.

    just so it's clear; i need the pub's forward,reverse,turnleft,turnright to be disabled when one of them is active. so the motor can't turn cw and ccw at the same time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • whickerwhicker Posts: 749
    edited 2010-05-12 01:14
    your issue has to do with program flow.

    from what I can gleam, you're trying to multitask what should probably be a single-threaded program.

    If your program was written to run in a single cog, with a pattern like:


    Repeat
        decide_what_to_do()
        do_it()
    
    



    then you wouldn't have such a problem. because it's either deciding what to do, or directly performing it. it doesn't decide the next thing until it actually is done doing it.



    The other way is, is that you're going to have to set a "busy flag" or a semiphore.

    At the start of each of the related PUB's, you'll need to check a certain flag variable that you create.
    if the flag is 0, then immediately set that same flag to something like 1.
    if the flag was not 0, return right away from the PUB with a return value that says the call failed (because something else is using your shared resource).
    now the PUB does its thing.
    then at the end of the PUB, sets the flag back to 0.
    finally it returns something that means success.


    there are obvious things like, whatever is calling the PUB, needs to check the return value to make sure the command worked or not. if it didn't work, all you're probably going to right now is spin lock, waiting for the command to succeed. You'll need to initialize the "busy flag" at program start to the value that says it isn't busy.
  • BotdocterBotdocter Posts: 271
    edited 2010-05-12 01:21
    Thank you so much!

    I think it's clear to me. i'm gonna try it out!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • BotdocterBotdocter Posts: 271
    edited 2010-05-12 17:21
    It worked perfectly! Thanx!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • whickerwhicker Posts: 749
    edited 2010-05-13 00:53
    cool. glad I could help.
Sign In or Register to comment.