Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed 7366_lib TLE5206_lib
main.cpp@2:486bb9b6bd78, 2019-02-12 (annotated)
- Committer:
- natienza
- Date:
- Tue Feb 12 10:52:27 2019 +0000
- Revision:
- 2:486bb9b6bd78
- Parent:
- 0:509b29d50fcb
- Child:
- 3:737ac9c24ca5
test asserv position correcteur prop
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gpongnot | 0:509b29d50fcb | 1 | //Includes |
gpongnot | 0:509b29d50fcb | 2 | #include "mbed.h" |
gpongnot | 0:509b29d50fcb | 3 | #include "7366_lib.h" |
gpongnot | 0:509b29d50fcb | 4 | #include "TLE5206_lib.h" |
gpongnot | 0:509b29d50fcb | 5 | |
gpongnot | 0:509b29d50fcb | 6 | // Liaison SPI avec les compteurs |
gpongnot | 0:509b29d50fcb | 7 | #define SPI_SCLK PA_5 //A4 |
gpongnot | 0:509b29d50fcb | 8 | #define SPI_MISO PA_6 //A5 |
gpongnot | 0:509b29d50fcb | 9 | #define SPI_MOSI PA_7 //A6 |
gpongnot | 0:509b29d50fcb | 10 | #define SPI_CS3 PA_0//A0 |
gpongnot | 0:509b29d50fcb | 11 | #define SPI_CS2 PA_1 |
gpongnot | 0:509b29d50fcb | 12 | #define SPI_CS1 PA_3 |
gpongnot | 0:509b29d50fcb | 13 | |
gpongnot | 0:509b29d50fcb | 14 | // Vers le pont en H |
gpongnot | 0:509b29d50fcb | 15 | #define H1_IN1 PA_9 //D1 - PWM1/2 |
gpongnot | 0:509b29d50fcb | 16 | #define H1_IN2 PA_10 //D0 - PWM1/3 |
gpongnot | 0:509b29d50fcb | 17 | #define H2_IN1 PA_8 //D9 - PWM1/1 |
gpongnot | 0:509b29d50fcb | 18 | #define H2_IN2 PB_7 //D4 - PWM17/1 |
gpongnot | 0:509b29d50fcb | 19 | #define H3_IN1 PB_6 //D5 - PWM16/1 |
gpongnot | 0:509b29d50fcb | 20 | #define H3_IN2 PA_4 //A3 - PWM3/2 |
gpongnot | 0:509b29d50fcb | 21 | |
gpongnot | 0:509b29d50fcb | 22 | #define DECOUP_HACH 50 //us - 20 000 kHz pour les oreilles |
natienza | 2:486bb9b6bd78 | 23 | #define PERIODE_AFF 500 //ms |
natienza | 2:486bb9b6bd78 | 24 | #define PERIODE_ASSERV 50 //ms |
gpongnot | 0:509b29d50fcb | 25 | |
natienza | 2:486bb9b6bd78 | 26 | Serial pc(USBTX,USBRX); |
natienza | 2:486bb9b6bd78 | 27 | Timer timer; |
gpongnot | 0:509b29d50fcb | 28 | DigitalOut myled(LED3); |
gpongnot | 0:509b29d50fcb | 29 | |
gpongnot | 0:509b29d50fcb | 30 | SPI_7366 compt1(SPI_MOSI, SPI_MISO, SPI_SCLK,SPI_CS1); |
gpongnot | 0:509b29d50fcb | 31 | SPI_7366 compt2(SPI_MOSI, SPI_MISO, SPI_SCLK,SPI_CS2); |
gpongnot | 0:509b29d50fcb | 32 | SPI_7366 compt3(SPI_MOSI, SPI_MISO, SPI_SCLK,SPI_CS3); |
gpongnot | 0:509b29d50fcb | 33 | |
gpongnot | 0:509b29d50fcb | 34 | TLE5206 moteur1(H1_IN1,H1_IN2); |
gpongnot | 0:509b29d50fcb | 35 | TLE5206 moteur2(H2_IN1,H2_IN2); |
gpongnot | 0:509b29d50fcb | 36 | TLE5206 moteur3(H3_IN1,H3_IN2); |
gpongnot | 0:509b29d50fcb | 37 | |
gpongnot | 0:509b29d50fcb | 38 | int main() { |
natienza | 2:486bb9b6bd78 | 39 | |
natienza | 2:486bb9b6bd78 | 40 | //setup |
gpongnot | 0:509b29d50fcb | 41 | compt1.setup(); |
gpongnot | 0:509b29d50fcb | 42 | compt2.setup(); |
gpongnot | 0:509b29d50fcb | 43 | compt3.setup(); |
gpongnot | 0:509b29d50fcb | 44 | |
gpongnot | 0:509b29d50fcb | 45 | moteur1.setup(DECOUP_HACH); |
gpongnot | 0:509b29d50fcb | 46 | moteur2.setup(DECOUP_HACH); |
gpongnot | 0:509b29d50fcb | 47 | moteur3.setup(DECOUP_HACH); |
gpongnot | 0:509b29d50fcb | 48 | |
gpongnot | 0:509b29d50fcb | 49 | moteur1.write(-0.4); |
gpongnot | 0:509b29d50fcb | 50 | moteur2.write(-0.7); |
gpongnot | 0:509b29d50fcb | 51 | moteur3.write(0.7); |
gpongnot | 0:509b29d50fcb | 52 | |
natienza | 2:486bb9b6bd78 | 53 | timer.start(); |
natienza | 2:486bb9b6bd78 | 54 | |
natienza | 2:486bb9b6bd78 | 55 | //variables |
natienza | 2:486bb9b6bd78 | 56 | int32_t position = 0; |
natienza | 2:486bb9b6bd78 | 57 | int32_t consigne = (1<<15); |
natienza | 2:486bb9b6bd78 | 58 | int32_t erreur = 0; |
natienza | 2:486bb9b6bd78 | 59 | float gain = 0.0001; |
natienza | 2:486bb9b6bd78 | 60 | uint32_t seuilAffichage = PERIODE_AFF; |
natienza | 2:486bb9b6bd78 | 61 | uint32_t seuilAsserv = PERIODE_ASSERV; |
natienza | 2:486bb9b6bd78 | 62 | |
gpongnot | 0:509b29d50fcb | 63 | // Loop |
gpongnot | 0:509b29d50fcb | 64 | while(1) { |
natienza | 2:486bb9b6bd78 | 65 | |
natienza | 2:486bb9b6bd78 | 66 | if (timer.read_ms() > seuilAffichage){ |
natienza | 2:486bb9b6bd78 | 67 | position = compt2.read_value(); |
natienza | 2:486bb9b6bd78 | 68 | seuilAffichage += PERIODE_AFF; |
natienza | 2:486bb9b6bd78 | 69 | pc.printf("valeur lue : %d \n\r", position); |
natienza | 2:486bb9b6bd78 | 70 | myled = !myled; |
natienza | 2:486bb9b6bd78 | 71 | } |
natienza | 2:486bb9b6bd78 | 72 | if (timer.read_ms() > seuilAsserv){ |
natienza | 2:486bb9b6bd78 | 73 | seuilAsserv += PERIODE_ASSERV; |
natienza | 2:486bb9b6bd78 | 74 | erreur = compt2.read_value() - consigne; |
natienza | 2:486bb9b6bd78 | 75 | moteur2.write(gain * erreur); |
natienza | 2:486bb9b6bd78 | 76 | } |
gpongnot | 0:509b29d50fcb | 77 | } |
gpongnot | 0:509b29d50fcb | 78 | } |