dfhjk
Dependencies: X_NUCLEO_IHM12A1 X_NUCLEO_IKS01A2 mbed
Fork of HelloWorld_IHM12A1 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 00022 00023 /* Main ----------------------------------------------------------------------*/ 00024 00025 int main() 00026 { 00027 00028 uint8_t demoStep = 0; 00029 // riv 00030 /* Initializing Motor Control Component. */ 00031 motor = new STSPIN240_250(D2, D9, D6, D7, D5, D4, A0 ); //Chiamo i l costruttore per inizializzare l'oggetto motor 00032 00033 /* Set dual bridge enabled as two motors are used*/ 00034 motor->SetDualFullBridgeConfig(1); 00035 00036 /* Set PWM Frequency of Ref to 15000 Hz */ 00037 motor->SetRefPwmFreq(0, 15000); //frequenza clock 00038 00039 /* Set PWM duty cycle of Ref to 60% */ 00040 motor->SetRefPwmDc(0, 60); 00041 00042 /* Set PWM Frequency of bridge A inputs to 10000 Hz */ 00043 motor->SetBridgeInputPwmFreq(0,10000); 00044 00045 /* Set PWM Frequency of bridge B inputs to 10000 Hz */ 00046 motor->SetBridgeInputPwmFreq(1,10000); 00047 00048 00049 00050 //INIZIALIZZAZIONI, s1 e s2 conterranno i valori di velocità da dare ai singoli motori 00051 00052 int s0=50; 00053 int s1=50; 00054 00055 //Definisco due oggetti della classe AnalogIn che chiamo ten1 e ten2, chiamo il costruttore per inizializzarli 00056 AnalogIn ten0(A1); //indico che vorrò leggere la tensione analogica su questi due pin, 00057 AnalogIn ten1(A2); //è la stessa di quella che ho sulle due ruote 00058 00059 /**** SETTO I DUE MOTORI ALLA STESSA VELOCITA, 50%, E ALLA STESSA DIREZIONE ****/ 00060 00061 motor->SetSpeed(0,s0); //SETTO LA VELOCITà DEL MOTORE 0 AL 50% 00062 motor->SetSpeed(1,s1); //RIDUCO LA VELOCITA DEL MOTORE 0 00063 motor->Run(1, BDCMotor::FWD); //FACCIO ANDARE AVANTI IL MOTORE 1, per farlo andare indietro basta mettere BWD invece di FWD 00064 motor->Run(0, BDCMotor::FWD); //MOTORE 0 IN AVANTI 00065 00066 00067 while (1) 00068 { 00069 00070 if(ten1.read() - ten0.read() >0.1) //la tensione sul motore 0 è 10 volte quella dell'altro motore 00071 { 00072 s1+=10; 00073 motor->SetSpeed(1,s1); //aumento la velocità del 5% 00074 // motor->Run(1, BDCMotor::FWD); 00075 00076 printf(" Velocita S1 %6ld\n", s1); 00077 } 00078 00079 else if (ten0.read() - ten1.read() >0.1) //la tensione sul motore 0 è 10 volte quella dell'altro motore 00080 { 00081 00082 s0 +=10; 00083 motor->SetSpeed(0,s0); //aumento la velocità del 5% 00084 // motor->Run(0, BDCMotor::FWD); 00085 00086 printf(" Velocita S0 %6ld\n", s0); 00087 00088 00089 00090 00091 } 00092 00093 wait_ms(250); // 250 ms 00094 } 00095 00096 00097 }
Generated on Sun Jul 17 2022 08:15:21 by
1.7.2
