RotateMotorEx
Brought to you by:
afanofosc,
afanofosc_99
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.
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.
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
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
*/
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]
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
How do I insert code tags here?
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.