#96 RotateMotorEx

general
closed-works-for-me
John Hansen
NXC (53)
5
2011-06-22
2011-05-23
Anonymous
No

I have two tasks one which executes RotateMotorEx() function. The other reads the Servo Encoder Value. It seems that When ever the rotatemotorex() is runnig, the encoder values are changing ranodmly.
For example i have another task which displays the value of varibal on to which Motor encoder value is stored. The display changes b/w 0, 720, 1060 etc...
The display task is syncrinised with a mutex to prevent reading the variable when CountMotorTacho is assigned to the variable.

Discussion

  • John Hansen
    John Hansen
    2011-05-23

    I am sure this is a bug in your program code. I can't help you fix that bug if you do not send me your code. Also, there is no reason to use a mutex with variable access. All reads and writes to variables are atomic so you can't read in the middle of a write. Sometimes people get confused when drawing numeric values on the display if they do not clear the line or the entire screen before drawing the new value over the top of the old value. A value of 359 that is overwritten by a value of 9 will look like 959 unless you clear the previous value from the display.

     
  • John Hansen
    John Hansen
    2011-05-23

    • milestone: --> general
    • status: open --> closed-works-for-me
     

  • Anonymous
    2011-05-24

    I have attached a striped down version of the program that still gives the error.

    The firmware I have used are
    lms_arm_nbcnxc_107.rfw
    lms_arm_nbcnxc_131.rfw
    Both give the same problem

    While the RotateMotorEx is still turning the wheels, the tacho counts are correct.
    It seems that as the RotateMotorEx is about to finish, It sets the Tacho Count of one motor(which is running very slowly (OUT_C) in my example) to the same count as the other one.
    So during first function call,
    OUT_B tacho count = 0 to ~720
    OUT_C tacho count = 0 to ~ -14

    just before end of the function (or just after?)
    OUT_B tacho count = ~719
    OUT_C tacho count = ~720

    same thing happens for further rotations.
    P.S. I removed the mutex in the following prog and still the error happens.
    [code]============================================
    /*
    task main
    calls the other three tasks

    task Movebot
    issues RotateMotorEx commands
    
    task Display
    display all useful variables for debugging every 500ms
    
    task Navigate
    stores motor tach count every 50ms and does some claculations
    calculations removed for debugging.
    

    */
    long phi_l, phi_r;
    mutex mewtwo;
    bool not_finished;

    task Display()
    {
    while(not_finished)
    {
    ResetScreen();

    Acquire(mewtwo);
    TextOut(0, LCD_LINE1, "phi_l");
    NumOut(0, LCD_LINE2, phi_l);

    TextOut(0, LCD_LINE3, "Right Wheel ");
    NumOut(0, LCD_LINE4, phi_r);

    Release(mewtwo);
    Wait(500);
    }
    }

    task Navigate()
    {
    while(not_finished)
    {
    Acquire(mewtwo);
    phi_l = MotorTachoCount(OUT_C);
    phi_r = MotorTachoCount(OUT_B);
    Release(mewtwo);
    Wait(50);
    }
    }

    task MoveBot()
    {
    Float(OUT_BC);

    RotateMotorEx(OUT_BC, 50, 720, -50, true, true);
    Wait(1000);
    RotateMotorEx(OUT_BC, 50, 720, -50, true, false);
    Wait(1000);

    RotateMotorEx(OUT_BC, 50, 720, 100, true, true);
    Wait(1000);
    RotateMotorEx(OUT_BC, 50, 720, 100, true, false);
    Wait(1000);

    not_finished = 0;
    PlayTone(1000, 200);
    Wait(2000);
    }

    task main()
    {
    not_finished = 1;
    phi_l = 0;
    phi_r = 0;

    ResetTachoCount(OUT_BC);
    Precedes(Display, Navigate, MoveBot);
    }
    ============================================[/code]

     

  • Anonymous
    2011-05-24

    • status: closed-works-for-me --> open-works-for-me
     

  • Anonymous
    2011-05-24

    How do I insert code tags here?

     
  • John Hansen
    John Hansen
    2011-05-24

    The firmware "owns" the Tacho count and is free to change it willy nilly. The only motor counter that is owned by a user program is the Rotation count. I did not know which one you were using, sorry. In a user program you should use MotorRotationCount and ResetRotationCount rather than either the Tacho counter routines or the Block Tacho counter routines. Please let me know if you still have troubles after switching to the Rotation counter.

     
  • MotorRotationCount works well. Thank you.
    Sorry; could'nt post the code initially because the lab PCs were stand alone.

     
  • John Hansen
    John Hansen
    2011-06-22

    • status: open-works-for-me --> closed-works-for-me