seconda prova motore
Dependencies: X_NUCLEO_IHM12A1 X_NUCLEO_IKS01A2 mbed
Fork of prova_motore by
main.cpp
00001 00002 /* mbed specific header files. */ 00003 #include "mbed.h" 00004 00005 /* Component specific header files. */ 00006 #include "stspin240_250_class.h" 00007 00008 /* Variables -----------------------------------------------------------------*/ 00009 00010 /* Initialization parameters of the motor connected to the expansion board. */ 00011 Stspin240_250_Init_t initDeviceParameters = { 00012 20000, /* Frequency of PWM of Input Bridge A in Hz up to 100000Hz */ 00013 20000, /* Frequency of PWM of Input Bridge B in Hz up to 100000Hz */ 00014 20000, /* Frequency of PWM used for Ref pin in Hz up to 100000Hz */ 00015 50, /* Duty cycle of PWM used for Ref pin (from 0 to 100) */ 00016 TRUE /* Dual Bridge configuration (FALSE for mono, TRUE for dual brush dc) */ 00017 }; 00018 00019 /* Motor Control Component. */ 00020 STSPIN240_250 *motor; 00021 int s1; 00022 int s0; 00023 00024 00025 00026 00027 00028 /* Main ----------------------------------------------------------------------*/ 00029 00030 int main() 00031 { 00032 uint8_t demoStep = 0; 00033 // riv 00034 /* Initializing Motor Control Component. */ 00035 motor = new STSPIN240_250(D2, D9, D6, D7, D5, D4, A0 ); //Chiamo i l costruttore per inizializzare l'oggetto motor 00036 00037 /* Set dual bridge enabled as two motors are used*/ 00038 motor->SetDualFullBridgeConfig(1); 00039 00040 /* Set PWM Frequency of Ref to 15000 Hz */ 00041 motor->SetRefPwmFreq(0, 15000); //frequenza clock 00042 00043 /* Set PWM duty cycle of Ref to 60% */ 00044 motor->SetRefPwmDc(0, 60); 00045 motor->SetRefPwmDc(1, 60); 00046 00047 /* Set PWM Frequency of bridge A inputs to 10000 Hz */ 00048 motor->SetBridgeInputPwmFreq(0,70000); 00049 00050 /* Set PWM Frequency of bridge B inputs to 10000 Hz */ 00051 motor->SetBridgeInputPwmFreq(1,70000); 00052 00053 00054 00055 //INIZIALIZZAZIONI, s1 e s2 conterranno i valori di velocità da dare ai singoli motori 00056 00057 s0=50; 00058 s1=50; 00059 00060 //Definisco due oggetti della classe AnalogIn che chiamo ten1 e ten2, chiamo il costruttore per inizializzarli 00061 AnalogIn ten0(A1); //indico che vorrò leggere la tensione analogica su questi due pin, 00062 AnalogIn ten1(A2); //è la stessa di quella che ho sulle due ruote 00063 00064 /**** SETTO I DUE MOTORI ALLA STESSA VELOCITA, 50%, E ALLA STESSA DIREZIONE ****/ 00065 motor->SetSpeed(0,s0); //SETTO LA VELOCITà DEL MOTORE 0 AL 50% 00066 motor->SetSpeed(1,s1); //RIDUCO LA VELOCITA DEL MOTORE 0 00067 motor->Run(1, BDCMotor::FWD); //FACCIO ANDARE AVANTI IL MOTORE 1, per farlo andare indietro basta mettere BWD invece di FWD 00068 motor->Run(0, BDCMotor::FWD); //MOTORE 0 IN AVANTI 00069 00070 00071 00072 while (1) 00073 { 00074 00075 if(ten1.read()-ten0.read()>0.1) //la tensione sul motore 0 è 10 volte quella dell'altro motore 00076 { 00077 s1+=10; 00078 motor->SetSpeed(1,s1); //aumento la velocità del 5% 00079 // motor->Run(1, BDCMotor::FWD); 00080 00081 printf(" Velocita S1 %6ld\n", s1); 00082 } 00083 00084 else if (ten0.read() - ten1.read() >0.1) //la tensione sul motore 0 è 10 volte quella dell'altro motore 00085 { 00086 00087 s1-=10; 00088 motor->SetSpeed(1,s1); //aumento la velocità del 5% 00089 // motor->Run(0, BDCMotor::FWD); 00090 00091 printf(" Velocita S0 %6ld\n", s0); 00092 00093 00094 00095 00096 } 00097 00098 wait_ms(150); // 250 ms 00099 } 00100 00101 00102 }
Generated on Sat Jul 30 2022 00:34:49 by
1.7.2
