jap, mach ich!
Code:
void RotatePID(uint8_t port, long Target, float RotatSpeed, int8_t cont) {
if( !motor[port].tid && motor[port].runstate) motor[port].runstate=0; // repair
if( motor[port].runstate ) return;
if( motor[port].tid ) return;
motor[port].runstate=1; // set runstate: PID active
// custom init PID [port]
motor[port].target =Target; // assign target
motor[port].tarpwm =RotatSpeed; // assign rotation speed
motor[port].cont=cont; // cont vs. hit once
// Reset PID control defaults
motor[port].outp =0; // PID control output value
motor[port].maxout =100; // absolute max possible output (max pwr)
motor[port].read =0; // current reading
motor[port].err =0; // current error
motor[port].integr =0; // integral of errors
motor[port].speed =0; // current speed
motor[port].stopPIDcontrol =0; // flag for external termination
pthread_create( & motor[port].tid, // id speichern in dem dazugehörigen Array-Element
0, // Default Attribute (threads cancelbar)
PID_calc, // Name der PID-Kalkulationsroutinge
(void*)port); // der Index des Array-Elements für eine PID Struktur,
// die mit dem Motorindex gleich ist.
pthread_detach(motor[port].tid);
}
Lesezeichen