Electric motor

Hi folks,
I am writing a program to calculate and output Torque and power using, a multitude of values, which I can post what exactly they are if you would like me to. But I digress, my problem is with my for loop, I am trying to reference my calcTor function in the conditions for the for loop and I haven't had much luck finding out what I am doing wrong, it won't even make it to the functions from the for loop.
Any help would be appreciated.

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
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
//defining constants
const double D = .004; // N/rad/s
const double C = .003; // N * m
double calcTor (double& V, double& omega, double& K, double& R, double D, double C);
double calcPow( double& calcTor, double& omega);

int main(){
	//defining variables
	double V = 0;//volts
	double omega = 0;//rad/s
	double K = 0;//N*m /Amp
	double R = 0; //Ohms
	double RPM = 0;

	//input values
	cout << "Input applied voltage(V) \n";
	cin >> V;
	cout << "Input Motor Constant \n" ;
	cin >> K;
	cout << "Input Resistance(Ohms) \n";
	cin >> R;
	cout <<"Cody Brown \n" <<"Applied Voltage (Volts): " << V << endl << "Motor Constant(N*m/Amp or Volts/rad/s): " << K << endl;
	cout << "Motor Resistance(Ohms); " << R << endl;
	cout << "RPM  Torque(Nm)  Power(W) \n";
	
	//for loop to output values for the motor
	for(RPM = 0; calcTor < 0; RPM = (RPM + 100)){
		cout << RPM << "    " << calcTor << "   " << calcPow << endl;
	}
	system ("Pause");
	return 0;
}

//Calculating Torque
double calcTor (double& V, double& omega, double& K, double& R, double D, double C) {
	double calcTor = 0;
	calcTor = (((V - omega * K)/R) * K - (D * omega) - C);
	return calcTor;
}

//Calculating Power
double calcPow( double& calcTor, double& omega){
	double calcPow = 0;
	calcPow = calcTor * omega;
	return calcPow;
}
Line 31: You don't want to use the address of the function (because you have no ()), as your termination condition. Not sure what you want here instead.

Line 32: You're not calling the functions. You're going to be outputting a pointer to the functions. To call a function, you need the (). Without the (), the name of a function becomes a function pointer.

1
2
cout << RPM << "    " << calcTor(V,omega,K,R,D,C)  
    << "   " << calcPow(calcTor(V,omega,K,R,D,C, omega) << endl;  // Not sure where D comes from 
Last edited on
the letter D is a globally defined constant at the top of the code,
now i'm getting Error 'calcPow' : cannot convert parameter 1 from 'double' to 'double &'
I am not sure what to do with that

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
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
//defining constants
const double D = .004; // N/rad/s vicous friction
const double C = .003; // N * m coulombic friction
double calcTor (double& V, double& omega, double& K, double& R, double D, double C);
double calcPow( double& calcTor, double& omega);

int main(){
	//defining variables
	double V = 0;//volts
	double omega = 0;//rad/s
	double K = 0;//N*m /Amp motor constant
	double R = 0; //Ohms resistance
	double RPM = 0;

	//input values
	cout << "Input applied voltage(V) \n";
	cin >> V;
	cout << "Input Motor Constant \n" ;
	cin >> K;
	cout << "Input Resistance(Ohms) \n";
	cin >> R;
	cout <<"Cody Brown \n" <<"Applied Voltage (Volts): " << V << endl << "Motor Constant(N*m/Amp or Volts/rad/s): " << K << endl;
	cout << "Motor Resistance(Ohms); " << R << endl;
	cout << "RPM  Torque(Nm)  Power(W) \n";
	
	//for loop to output values for the motor
	for(RPM = 0; calcTor (V, omega, K, R, D, C) < 0; RPM = (RPM + 100)){
		cout << RPM << "    " << calcTor(V ,omega ,K ,R ,D ,C)  << "   " << calcPow( calcTor(V ,omega , K ,R ,D , C), omega) << endl;
	}
	system ("Pause");
	return 0;
}

//Calculating Torque
double calcTor (double& V, double& omega, double& K, double& R, double D, double C) {
	double calcTor = 0;
	calcTor = (((V - omega * K)/R) * K - (D * omega) - C);
	return calcTor;
}

//Calculating Power
double calcPow( double calcTor, double& omega){
	double calcPow = 0;
	calcPow = calcTor * omega;
	return calcPow;
}
Sorry about D. I missed line 6.

Your function prototype at line 9 and your implementation at line 46 do not agree. The prototype specifies passing calcTor by reference, which you can not do with a function call (unless the function call returned a reference).
Now I am getting the same error for it, it references line 34 but if I take the &'s out I get a different error

Error 1 error LNK2019: unresolved external symbol "double __cdecl calcTor(double &,double &,double &,double &,double,double)"

stating no line or column

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
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
//defining constants
const double D = .004; // N/rad/s vicous friction
const double C = .003; // N * m coulombic friction
double calcTor (double& V, double& omega, double& K, double& R, double D, double C);
double calcPow( double& calcTor, double& omega);

int main(){
	//defining variables
	double V = 0;//volts
	double omega = 0;//rad/s
	double K = 0;//N*m /Amp motor constant
	double R = 0; //Ohms resistance
	double RPM = 0;

	//input values
	cout << "Input applied voltage(V) \n";
	cin >> V;
	cout << "Input Motor Constant \n" ;
	cin >> K;
	cout << "Input Resistance(Ohms) \n";
	cin >> R;
	cout <<"Cody Brown \n" <<"Applied Voltage (Volts): " << V << endl << "Motor Constant(N*m/Amp or Volts/rad/s): " << K << endl;
	cout << "Motor Resistance(Ohms); " << R << endl;
	cout << "RPM  Torque(Nm)  Power(W) \n";
	
	//for loop to output values for the motor
	for(RPM = 0; calcTor (V, omega, K, R, D, C) < 0; RPM = (RPM+100)){
		cout << RPM << "    " << calcTor(V ,omega ,K ,R ,D ,C)  << "   " << calcPow( calcTor(V ,omega ,K ,R ,D ,C), omega) << endl;
	}
	system ("Pause");
	return 0;
}

//Calculating Torque
double calcTor (double V, double& omega, double& K, double& R, double D, double C) {
	double calcTor = 0;
	calcTor = (((V - omega * K)/R) * K - (D * omega) - C);
	return calcTor;
}

//Calculating Power
double calcPow( double& calcTor, double& omega){
	double calcPow = 0;
	calcPow = calcTor * omega;
	return calcPow;
}
so my problem was i was missing an & on the double V down on line 39 in the last code, but I still can't get it to run the for loop

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
//joe

#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
//defining constants
const double D = .004; // N/rad/s vicous friction
const double C = .003; // N * m coulombic friction
double calcTor (double& V, double& omega, double& K, double& R, double D, double C);
double calcPow( double calcTor, double& omega);

int main(){
	//defining variables
	double V = 0;//volts
	double omega = 0;//rad/s
	double K = 0;//N*m /Amp motor constant
	double R = 0; //Ohms resistance
	double RPM = 0;

	//input values
	cout << "Input applied voltage(V) \n";
	cin >> V;
	cout << "Input Motor Constant \n" ;
	cin >> K;
	cout << "Input Resistance(Ohms) \n";
	cin >> R;
	cout <<"Cody Brown \n" <<"Applied Voltage (Volts): " << V << endl << "Motor Constant(N*m/Amp or Volts/rad/s): " << K << endl;
	cout << "Motor Resistance(Ohms); " << R << endl;
	cout << "RPM  Torque(Nm)  Power(W) \n";
	
	//for loop to output values for the motor
	for(RPM = 0; calcTor (V, omega, K, R, D, C) < 0; RPM = (RPM+100)){
		cout << RPM << "    " << calcTor(V ,omega ,K ,R ,D ,C)  << "   " << calcPow( calcTor(V ,omega ,K ,R ,D ,C), omega) << endl;
	}
	system ("Pause");
	return 0;
}

//Calculating Torque
double calcTor (double& V, double& omega, double& K, double& R, double D, double C) {
	double calcTor = 0;
	calcTor = (((V - omega * K)/R) * K - (D * omega) - C);
	return calcTor;
}

//Calculating Power
double calcPow( double calcTor, double& omega){
	double calcPow = 0;
	calcPow = calcTor * omega;
	return calcPow;
}
Now I have figured out most of my problems, I can't get omega to calculate as anything other than 0
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
//joe

#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
//defining constants
const double D = .004; // N/rad/s vicous friction
const double C = .003; // N * m coulombic friction
double calcTor (double& V, double& omega, double& K, double& R, double D, double C);
double calcPow( double calcTor, double& omega);
double const PI = acos(-1);

int main(){
	//defining variables
	double V = 0;//volts
	double K = 0;//N*m /Amp motor constant
	double R = 0; //Ohms resistance
	double RPM = 0;
	double omega = (RPM * PI)/30;//rad/s

	//input values
	cout << "Input applied voltage(V) \n";
	cin >> V;
	cout << "Input Motor Constant \n" ;
	cin >> K;
	cout << "Input Resistance(Ohms) \n";
	cin >> R;
	cout <<"Cody Brown \n" <<"Applied Voltage (Volts): " << V << endl << "Motor Constant(N*m/Amp or Volts/rad/s): " << K << endl;
	cout << "Motor Resistance(Ohms); " << R << endl;
	cout << "RPM  Torque(Nm)  Power(W) \n";
	
	//for loop to output values for the motor
	for(RPM = 0; calcTor (V, omega, K, R, D, C) < 0; RPM = (RPM+100)){
		cout << RPM << "    " << calcTor(V ,omega ,K ,R ,D ,C)  << "   " << calcPow( calcTor(V ,omega ,K ,R ,D ,C), omega) << endl;
	}
	system ("Pause");
	return 0;
}

//Calculating Torque
double calcTor (double& V, double& omega, double& K, double& R, double D, double C) {
	double calcTor = 0;
	calcTor = (((V - omega * K)/R) * K - (D * omega) - C);
	return calcTor;
}

//Calculating Power
double calcPow( double calcTor, double& omega){
	double calcPow = 0;
	calcPow = calcTor * omega;
	return calcPow;
}
I meant to put I can't get calcTor to equal anything but zero or an extremely negative number
I have found it is not making it back to the for loop despite meeting the conditions
closed account (j3Rz8vqX)
Line 20 set omega equal to (0 * 3.14159)/30, which is 0.

Maybe call process line 20 after line 34, since that is when RPM is first reassigned.

Example:
1
2
3
4
5
6
7
8
9
10
	double omega = 0;//(RPM * PI)/30;//rad/s

	//input values
        //...

	//for loop to output values for the motor
	for(RPM = 0; calcTor (V, omega, K, R, D, C) < 0; RPM = (RPM+100)){//An issue here!!!
                omega = (RPM * PI)/30;//rad/s
		cout << RPM << "    " << calcTor(V ,omega ,K ,R ,D ,C)  << "   " << calcPow( calcTor(V ,omega ,K ,R ,D ,C), omega) << endl;
	}


The for loop may never run, so ensure that calcTor (V, omega, K, R, D, C) < 0; is true.
Calc tor using 36, .13, .1 as inputs returns 46, and I need omega for the calcTor function,
Your for loop will since you calctor return value is > 0. I assume that is not what you after.
Last edited on
Topic archived. No new replies allowed.