Bologna

Dependencies:   TCS3200 X_NUCLEO_IHM12A1 mbed-rtos mbed

Fork of SchedamotoriIHM12A1_copy by Duckiebot

Committer:
gandhi1
Date:
Fri Feb 24 16:13:24 2017 +0000
Revision:
6:b5d006c1eb59
Parent:
5:21a4085d2057
Child:
7:e14976007f66
Scheda motori funzionante (demostep)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Manu_L 0:773e2a2be16f 1 #include "mbed.h"
Manu_L 0:773e2a2be16f 2 #include "stspin240_250_class.h"
gandhi1 6:b5d006c1eb59 3 Serial pc(USBTX, USBRX);
Manu_L 0:773e2a2be16f 4 Stspin240_250_Init_t initDeviceParameters =
Manu_L 0:773e2a2be16f 5 {
gandhi1 6:b5d006c1eb59 6 20000,
gandhi1 6:b5d006c1eb59 7 20000,
gandhi1 6:b5d006c1eb59 8 20000,
gandhi1 6:b5d006c1eb59 9 50,
gandhi1 6:b5d006c1eb59 10 TRUE
Manu_L 0:773e2a2be16f 11 };
Manu_L 0:773e2a2be16f 12 STSPIN240_250 *motor;
Manu_L 0:773e2a2be16f 13
Manu_L 0:773e2a2be16f 14 int main()
Manu_L 0:773e2a2be16f 15 {
Manu_L 0:773e2a2be16f 16 uint8_t demoStep = 0;
Manu_L 0:773e2a2be16f 17 #if (defined TARGET_NUCLEO_F030R8)||(defined TARGET_NUCLEO_F334R8)
Manu_L 0:773e2a2be16f 18 motor = new STSPIN240_250(D2, D9, D6, D7, D5, D4, A2);
Manu_L 0:773e2a2be16f 19 #elif (defined TARGET_NUCLEO_L152RE)
Manu_L 0:773e2a2be16f 20 motor = new STSPIN240_250(D2, D9, D6, D7, D5, D4, A3);
Manu_L 0:773e2a2be16f 21 #else
Manu_L 0:773e2a2be16f 22 motor = new STSPIN240_250(D2, D9, D6, D7, D5, D4, A0);
Manu_L 0:773e2a2be16f 23 #endif
Manu_L 0:773e2a2be16f 24 if (motor->Init(&initDeviceParameters) != COMPONENT_OK) exit(EXIT_FAILURE);
Manu_L 2:1e4061cedf1d 25 motor->SetDualFullBridgeConfig(1);
gandhi1 6:b5d006c1eb59 26 motor->SetRefPwmFreq(0, 15000);
gandhi1 6:b5d006c1eb59 27 motor->SetRefPwmDc(0, 60);
Manu_L 0:773e2a2be16f 28 motor->SetBridgeInputPwmFreq(0,10000);
Manu_L 0:773e2a2be16f 29 motor->SetBridgeInputPwmFreq(1,10000);
Manu_L 0:773e2a2be16f 30
Manu_L 0:773e2a2be16f 31 while (1)
Manu_L 0:773e2a2be16f 32 {
Manu_L 0:773e2a2be16f 33 switch (demoStep)
Manu_L 0:773e2a2be16f 34 {
Manu_L 0:773e2a2be16f 35 case 0:
gandhi1 6:b5d006c1eb59 36 /* Va avanti */
gandhi1 6:b5d006c1eb59 37 motor->SetSpeed(0,50);
gandhi1 6:b5d006c1eb59 38 motor->SetSpeed(1,50);
gandhi1 6:b5d006c1eb59 39 motor->Run(0, BDCMotor::FWD);
gandhi1 6:b5d006c1eb59 40 motor->Run(1, BDCMotor::FWD);
gandhi1 6:b5d006c1eb59 41 break;
gandhi1 6:b5d006c1eb59 42 case 1:
gandhi1 6:b5d006c1eb59 43 /* Va a destra */
gandhi1 6:b5d006c1eb59 44 motor->SetSpeed(0,47);
gandhi1 6:b5d006c1eb59 45 motor->SetSpeed(1,23);
gandhi1 6:b5d006c1eb59 46 motor->Run(0, BDCMotor::FWD);
gandhi1 6:b5d006c1eb59 47 motor->Run(1, BDCMotor::FWD);
gandhi1 6:b5d006c1eb59 48
gandhi1 6:b5d006c1eb59 49 break;
gandhi1 6:b5d006c1eb59 50 case 2:
gandhi1 6:b5d006c1eb59 51 /* Va indietro */
gandhi1 6:b5d006c1eb59 52 motor->SetSpeed(0,50);
gandhi1 6:b5d006c1eb59 53 motor->SetSpeed(1,50);
gandhi1 6:b5d006c1eb59 54 motor->Run(0, BDCMotor::BWD);
gandhi1 6:b5d006c1eb59 55 motor->Run(1, BDCMotor::BWD);
gandhi1 6:b5d006c1eb59 56 break;
gandhi1 6:b5d006c1eb59 57 case 3:
gandhi1 6:b5d006c1eb59 58 /* Va a sinistra */
gandhi1 6:b5d006c1eb59 59 motor->SetSpeed(0,25);
gandhi1 6:b5d006c1eb59 60 motor->SetSpeed(1,30);
gandhi1 6:b5d006c1eb59 61 motor->Run(0, BDCMotor::FWD);
gandhi1 6:b5d006c1eb59 62 motor->Run(1, BDCMotor::FWD);
gandhi1 6:b5d006c1eb59 63 break;
gandhi1 6:b5d006c1eb59 64 }
gandhi1 6:b5d006c1eb59 65 wait_ms(4500);
Manu_L 0:773e2a2be16f 66 demoStep++;
gandhi1 6:b5d006c1eb59 67 if (demoStep > 3)
Manu_L 0:773e2a2be16f 68 {
Manu_L 0:773e2a2be16f 69 demoStep = 0;
Manu_L 0:773e2a2be16f 70 }
Manu_L 0:773e2a2be16f 71 }
Manu_L 0:773e2a2be16f 72 }
DonatoSt 5:21a4085d2057 73