Using my "homebrewed tasks" it works, but if I try RotateMotorPID instead it fails.
Code: Select all
#define TT 0
#define A1 1
#define A2 2
long TTtarget;
char TTrdy;
task RotateToTargetTT() {
char port=TT, pwr=-80;
TTrdy=0; Wait(1);
RotateMotorPID(port, pwr, MEnc(port)-TTtarget, 20, 40, 100);
Off(port);
Wait(50);
TTrdy= true;
}
long A1target;
char A1rdy;
task RotateToTargetA1() {
char port=A1, pwr=-100;
A1rdy=0; Wait(1);
RotateMotorPID(port, pwr, MEnc(port)-A1target, 20, 40, 100);
Off(port);
Wait(50);
A1rdy= true;
}
long A2target;
char A2rdy;
task RotateToTargetA2() {
char port=A2, pwr=-100;
A2rdy=0; Wait(1);
RotateMotorPID(port, pwr, MEnc(port)-A2target, 20, 40, 100);
Off(port);
Wait(50);
A2rdy= true;
}
task main() {
TTtarget= -500; start RotateToTargetTT;
A1target=-2500; start RotateToTargetA1;
A2target=+1500; start RotateToTargetA2;
while (!TTrdy); while (!A1rdy); while (!A2rdy); // wait until all motors are finished
TTtarget=+1200; start RotateToTargetTT;
A1target=+1000; start RotateToTargetA1;
A2target=-3000; start RotateToTargetA2;
while (!TTrdy); while (!A1rdy); while (!A2rdy); // wait until all motors are finished
//...
while(1);
}
Does RotateMotorPID aquire a mutex so that all other motors can't be started at the same moment?
How can I break this behaviour to make all motors run multithreaded simultaneously ?
edit:
e.g., a homebrewed function which is working also multithreaded (but not exactly enough) looks like this:
Code: Select all
long TTtarget;
char TTrdy;
task RotateToTargetTT() {
char port=TT, pwr=-100;
long dabs, oldabs;
TTrdy=0; Wait(1);
while (!(inArea(MEnc(port),TTtarget,5))) {
dabs=abs(MEnc(port)-TTtarget);
if (dabs>80) pwr=-100;
else if (dabs<80) pwr=-70;
else if (dabs<=60) pwr=-60;
if ((oldabs<=dabs)&&(dabs<50)) pwr=-100;
if ((inArea(MEnc(port),TTtarget,5))) { Off(port); Wait(10);}
else {
if (MEnc(port)<TTtarget) { OnFwd(port,-pwr); Wait(10);}
if (MEnc(port)>TTtarget) { OnFwd(port,pwr); Wait(10);}
}
oldabs=dabs;
Wait(1);
}
Off(port);
Wait(50);
TTrdy= true;
}