-
Notifications
You must be signed in to change notification settings - Fork 0
/
inductionMotor.c
129 lines (112 loc) · 3.22 KB
/
inductionMotor.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* Induction Motor Modeling
* To be used for sweeping parameter values and finding optimal
* design patterns
* gcc -lm -std=c99 -o inductionMotor inductionMotor.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define RESOLUTION 10
struct parameters{
int frequency;
double current;
};
struct motor{
int phases;
int poles;
int turns;
double surfaceAreaCoil;
double lengthCoil;
double resistance;
double u;//magnetic permeability of material
double airgap;
//add function pointer to motorString()?
struct parameters *p;
};
char* motorString(struct motor *m){
char *retval=(char*)malloc(sizeof(char)*256*sizeof(*m));
if(m==NULL)
return NULL;
sprintf(retval,"Phases: %d\r\nPoles: %d\r\nTurns: %d\r\nCoil Surface Area: %lf\r\nCoil Length: %lf\r\nCoil Resistance: %lf\r\nCore Magnetic Permeability: %lf\r\nAirGap: %lf\r\n",(*m).phases,(*m).poles,(*m).turns,(*m).surfaceAreaCoil,(*m).lengthCoil,(*m).resistance,(*m).u,m->airgap);
if(m->p!=NULL){
char *parameterString=(char*)malloc(sizeof(char)*64*sizeof((*m).p));
sprintf(parameterString,"Frequency: %d\r\nPhase Current:%lf\r\n",(*m).p->frequency,m->p->current);
strcat(retval,parameterString);
free(parameterString);
}
return retval;
}
double statorFlux(struct motor *m){
if(m==NULL)
return -1;
double flux=pow(m->turns,2);
flux*=m->u;
flux*=m->surfaceAreaCoil;
flux*=(m->p->current);
flux/=m->lengthCoil;
return flux;
}
/**
* Calculate the flux/current
*/
double inductance(struct motor *m){
double flux=statorFlux(m);
return flux/(m->p->current);
}
/**
* Generate Power & Torque curves
*/
double** power(struct motor *m){
int P=0,T=1;
double pi=3.14;//look up the math.h way...
double **curves=(double**)malloc(sizeof(double*)*2);
curves[P]=(double*)malloc(sizeof(double)*RESOLUTION);//power
curves[T]=(double*)malloc(sizeof(double)*RESOLUTION);//torque
//start with 100% slip
curves[P][0]=m->phases*pow(m->p->current,2)*m->resistance;
curves[T][0]=curves[P][0]*m->poles/(pi*4*m->p->frequency);
return curves;
}
int main(int argc,char *argv[]){
struct motor m;
m.p=(struct parameters *)malloc(sizeof(struct parameters));
(*m.p).current = 69.420;
m.p->frequency=120;
if(argc==9){
m.phases = atoi(argv[1]);
m.poles = atoi(argv[2]);
m.turns = atoi(argv[3]);
m.surfaceAreaCoil = atof(argv[4]);
m.lengthCoil = atof(argv[5]);
m.resistance = atof(argv[6]);
m.u = atof(argv[7]);
m.airgap=atof(argv[8]);
printf("%s\r\n",motorString(&m));
double **pt=power(&m);
for(int i=0;i<RESOLUTION;i++)
printf("power=%lf\ttorque=%lf\r\n",pt[0][i],pt[1][i]);
}else{
printf("inductionMotor phases poles turns surfaceArea Length resistance u airgap\r\n");
/*
printf("Phases: ");
scanf("%d",&m.phases);
printf("Poles: ");
scanf("%d",&m.poles);
printf("Turns: ");
scanf("%d",&m.turns);
printf("Surface Area of Coil: ");
scanf("%lf",&m.surfaceAreaCoil);
printf("Length of Coil: ");
scanf("%lf",&m.lengthCoil);
printf("Resistance of Coil: ");
scanf("%lf",&m.resistance);
printf("Permeability: ");
scanf("%lf",&m.u);
printf("AirGap: ");
scanf("%lf",&m.airgap);
*/
}
return 0;
}