Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <math.h>
- #include <vector>
- #include <algorithm>
- using namespace std;
- // Auxiliary Functions
- // 1. askForZero
- double askForZero(int n){
- cout << "Give me zero" << n+1 << ": \n";
- double zero;
- cin >> zero;
- while(zero < 0){
- cout << "Give me zero" << n+1 << ": \n";
- cin >> zero;
- }
- return zero;
- }
- // 1. askForPole
- double askForPole(int n){
- cout << "Give me pole" << n+1 << ": \n";
- double pole;
- cin >> pole;
- while(pole < 0){
- cout << "Give me pole" << n+1 << ": \n";
- cin >> pole;
- }
- return pole;
- }
- int main()
- {
- cout << "****************************************************************************\n";
- cout << "Let's create a PI controller given some specifications. You will give me the \n";
- cout << "the plant function Hp(s) and then the set of specifications.\n";
- cout << "****************************************************************************\n\n";
- // 1. Create the Hp(s) function
- cout << "**** 1. CREATING THE PLANT FUNCTION ****\n\n";
- cout << "a)\n";
- cout << "First, give me the DC gain of Hp(s): \n";
- double G;
- cin >> G;
- while(G <= 0){
- cout << "Give me a positive G: ";
- cin >> G;
- }
- cout << "\nb)\n";
- cout << "Now give me the numbers of 'zeros': ";
- int numOfZeros;
- cin >> numOfZeros;
- while(numOfZeros < 0){
- cout << "Give me the number of zeros: ";
- cin >> numOfZeros;
- }
- vector <double> zeros = vector <double> ();
- if(numOfZeros > 0){
- cout << "\nNow, write down the zeros: Be careful. You have to insert positive values\n";
- cout << "symbolizing the opposite number of zeros in reality!\n";
- for(int i=0; i<numOfZeros; i++){
- zeros.push_back(askForZero(i));
- }
- }
- cout << "\nc)\n";
- cout << "Now give me the numbers of 'poles': ";
- int numOfPoles;
- cin >> numOfPoles;
- while(numOfPoles < numOfZeros){
- cout << "Give me the number of poles: ";
- cin >> numOfPoles;
- }
- vector <double> poles = vector <double> ();
- if(numOfPoles > 0){
- cout << "\nNow, write down the poles: Be careful. You have to insert positive values\n";
- cout << "symbolizing the opposite number of poles in reality!\n";
- for(int i=0; i<numOfPoles; i++){
- poles.push_back(askForPole(i));
- }
- }
- // Showing the Hp(s) function, that user created
- cout << endl << endl;
- cout << "G = " << G << ", ";
- for(unsigned int i=0; i<zeros.size(); i++){
- cout << "z" << i << " = " << zeros[i] << ", ";
- }
- for(unsigned int i=0; i<poles.size(); i++){
- cout << "p" << i << " = " << poles[i] << ", ";
- }
- cout << " ----> \n\n";
- if(numOfZeros != 0){
- cout << " Hp(s) = " << G << "*";
- }
- else{
- cout << " Hp(s) = " << G << " / [ ";
- }
- for(unsigned int i=0; i<zeros.size(); i++){
- if(i != zeros.size()-1){
- cout << "(s+" << zeros[i] << ")*" ;
- }
- else{
- cout << "(s+" << zeros[i] << ") / [ ";
- }
- }
- for(unsigned int i=0; i<poles.size(); i++){
- if(i != poles.size()-1){
- cout << "(s+" << poles[i] << ")*" ;
- }
- else{
- cout << "(s+" << poles[i] << ") ] \n";
- }
- }
- cout << "\nPI controller = G(s) = k*(s+c)/s\n\n";
- cout << "So, A(s) = Hp(s) * G(s) = ";
- if(numOfZeros != 0){
- cout << G << "*k*(s+c)*";
- }
- else{
- cout << G << "*k*(s+c) / [ ";
- }
- for(unsigned int i=0; i<zeros.size(); i++){
- if(i != zeros.size()-1){
- cout << "(s+" << zeros[i] << ")*" ;
- }
- else{
- cout << "(s+" << zeros[i] << ") / [ ";
- }
- }
- cout << "s*";
- for(unsigned int i=0; i<poles.size(); i++){
- if(i != poles.size()-1){
- cout << "(s+" << poles[i] << ")*" ;
- }
- else{
- cout << "(s+" << poles[i] << ") ] \n";
- }
- }
- // 2. Set the specifications
- cout << "\n\n\nPerfect! Now it is time to select the set of specifications. Press one number\n";
- cout << "as shown underneath this message, to choose the appropriate set for you!\n";
- cout << "1. 1) essv, 2) Bandwidth fb, 3) Disturbs rejection in a low frequency (<=1 rad/s),\n";
- cout << "4) Noise depreciation and 5) Phase margin Ph,m\n";
- cout << "2. 1) essa, 2) Bandwidth fb, 3) Disturbs rejection in a low frequency (<=1 rad/s),\n";
- cout << "4) Noise depreciation and 5) Phase margin Ph,m\n";
- int choice;
- cin >> choice;
- switch(choice){
- case 1:
- cout << "1. essv <= ?\n";
- double essv;
- cin >> essv;
- while(essv < 0){
- cout << " essv <= ?\n";
- cin >> essv;
- }
- // First, I check if there is
- break;
- case 2:
- break;
- default:
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement