-
Notifications
You must be signed in to change notification settings - Fork 0
/
pid_c.c
35 lines (29 loc) · 901 Bytes
/
pid_c.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include "warmer.h"
#include "pid.h"
void * pid_c ( mt_ctrl_t * c )
{
PidType * myPID = ( PidType * ) malloc ( sizeof ( PidType ) );
PID_init ( myPID, 10, 3, 5, PID_Direction_Direct );
PID_SetMode ( myPID, PID_Mode_Automatic );
PID_SetSampleTime ( myPID, 500 );
pthread_mutex_lock ( &c->m );
PID_SetOutputLimits ( myPID, 0, c->procs * 100 );
pthread_mutex_unlock ( &c->m );
while ( 1 )
{
pthread_mutex_lock ( &c->m );
pthread_cond_wait ( &c->cv, &c->m );
myPID->mySetpoint = c->set_temp;
myPID->myInput = c->current_temp;
pthread_mutex_unlock ( &c->m );
PID_Compute ( myPID );
pthread_mutex_lock ( &c->m );
c->cpu_usage_percentage = myPID->myOutput;
pthread_mutex_unlock ( &c->m );
}
return NULL;
}