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
Revision 5:3e44d8755e88, committed 2020-06-16
- Comitter:
- jdeschamps
- Date:
- Tue Jun 16 07:24:14 2020 +0000
- Parent:
- 4:1d58769720c6
- Commit message:
- oui
Changed in this revision
--- a/CONTRIBUTING.md Fri Jun 05 06:33:21 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -# Contributing to Mbed OS - -Mbed OS is an open-source, device software platform for the Internet of Things. Contributions are an important part of the platform, and our goal is to make it as simple as possible to become a contributor. - -To encourage productive collaboration, as well as robust, consistent and maintainable code, we have a set of guidelines for [contributing to Mbed OS](https://os.mbed.com/docs/mbed-os/latest/contributing/index.html).
--- a/README.md Fri Jun 05 06:33:21 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ - -# Blinky Mbed OS example - -The example project is part of the [Arm Mbed OS Official Examples](https://os.mbed.com/code/) and is the [getting started example for Mbed OS](https://os.mbed.com/docs/mbed-os/v5.14/quick-start/index.html). It contains an application that repeatedly blinks an LED on supported [Mbed boards](https://os.mbed.com/platforms/). - -You can build the project with all supported [Mbed OS build tools](https://os.mbed.com/docs/mbed-os/latest/tools/index.html). However, this example project specifically refers to the command-line interface tool [Arm Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). -(Note: To see a rendered example you can import into the Arm Online Compiler, please see our [import quick start](https://os.mbed.com/docs/mbed-os/latest/quick-start/online-with-the-online-compiler.html#importing-the-code).) - -1. [Install Mbed CLI](https://os.mbed.com/docs/mbed-os/latest/quick-start/offline-with-mbed-cli.html). - -1. Clone this repository on your system, and change the current directory to where the project was cloned: - - ```bash - $ git clone git@github.com:armmbed/mbed-os-example-blinky && cd mbed-os-example-blinky - ``` - - Alternatively, you can download the example project with Arm Mbed CLI using the `import` subcommand: - - ```bash - $ mbed import mbed-os-example-blinky && cd mbed-os-example-blinky - ``` - - -## Application functionality - -The `main()` function is the single thread in the application. It toggles the state of a digital output connected to an LED on the board. - -## Building and running - -1. Connect a USB cable between the USB port on the board and the host computer. -2. <a name="build_cmd"></a> Run the following command to build the example project and program the microcontroller flash memory: - ```bash - $ mbed compile -m <TARGET> -t <TOOLCHAIN> --flash - ``` -The binary is located at `./BUILD/<TARGET>/<TOOLCHAIN>/mbed-os-example-blinky.bin`. - -Alternatively, you can manually copy the binary to the board, which you mount on the host computer over USB. - -Depending on the target, you can build the example project with the `GCC_ARM`, `ARM` or `IAR` toolchain. After installing Arm Mbed CLI, run the command below to determine which toolchain supports your target: - -```bash -$ mbed compile -S -``` - -## Expected output -The LED on your target turns on and off every 500 milliseconds. - - -## Troubleshooting -If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it. - -## Related Links - -* [Mbed OS Stats API](https://os.mbed.com/docs/latest/apis/mbed-statistics.html). -* [Mbed OS Configuration](https://os.mbed.com/docs/latest/reference/configuration.html). -* [Mbed OS Serial Communication](https://os.mbed.com/docs/latest/tutorials/serial-communication.html). -* [Mbed OS bare metal](https://os.mbed.com/docs/mbed-os/latest/reference/mbed-os-bare-metal.html). -* [Mbed boards](https://os.mbed.com/platforms/). - -### License and contributions - -The software is provided under Apache-2.0 license. Contributions to this project are accepted under the same license. Please see contributing.md for more info. - -This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide.
--- a/main.cpp Fri Jun 05 06:33:21 2020 +0000
+++ b/main.cpp Tue Jun 16 07:24:14 2020 +0000
@@ -6,20 +6,29 @@
volatile int flag_fc_haut=0; //interruption sur SW2
volatile int flag_contact=0; //interruption sur SW3
volatile int flag_retour=0;
+volatile int flag_monte=0;
+volatile int flag_descend=0;
+volatile int flag_stop=0;
+volatile int flag_position=0;
/*************** Interfaces utilisés *************************/
Serial pc(USBTX, USBRX,9600); // liaison USB
Ticker timer_etat; // Interruptions temporelles (timout)
Ticker timer_reglage_vitesse;
-DigitalOut IN1(PTD3); // sorties logiques
-DigitalOut IN2(PTC4);
-DigitalOut IN3(PTD1);
-DigitalOut IN4(PTC12);
+DigitalOut DIRA(PTD3); // sorties logiques
+DigitalOut BRKA(PTC4);
+DigitalOut DIRB(PTD1);
+DigitalOut BRKB(PTC12);
DigitalOut ENA(PTA1);
DigitalOut ENB(PTD2);
AnalogIn ain0(A0); //(lecture potentiometre vitesse) // entrées analogiques
AnalogIn ain1(A1); // (lecture potentiometre lecture position)
-InterruptIn fc_haut(SW2); // SW2 est associé à une interruption kbi s'appelant fc_haut
-InterruptIn contact(SW3); // SW3 est associé à une interruption kbi s'appelant contact
+InterruptIn fc_haut(SW2); // SW2 est associé à une interruption kbi s'appelant fc_haut
+InterruptIn contact(SW3); // SW3 est associé à une interruption kbi s'appelant contact
+InterruptIn monte (D4); // D4 est associé à une interruption kbi s'appelant monte
+InterruptIn descend (D8); // D3 est associé à une interruption kbi s'appelant descend
+InterruptIn retour (D7); // D7 est associé à une interruption kbi s'appelant retour
+InterruptIn stop (D6); // D6 est associé à une interruption kbi s'appelant stop
+//InterruptIn position;
/*************** Programmes d'interruption *******************/
void IT_timer_etat() { // sequencement phases moteur dont la fréquence est réglable potentiomètre/trame
flag_timer_etat=1;
@@ -36,6 +45,18 @@
void IT_retour(){
flag_retour=1;
}
+
+void IT_monte(){
+ flag_monte=1;
+ }
+
+void IT_descend(){
+ flag_descend=1;
+ }
+
+void IT_stop(){
+ flag_stop=1;
+ }
/*************** Programme Principal *************************/
int main() {
// declaration des variables
@@ -48,29 +69,41 @@
// frequence : frequence de l'IT etat (pilotage moteur)
char command[30]; // buffer de réception du message
int Nb_pas =0; // comptage du nombre de 1/2 pas
- int consigne_position =0;
+// int consigne_position =0;
+ // int position_demandee=10;
// dans le cas du firgelli :
- float a=127.47; // coefficient etalonnage capteur de position
- float b=-6.23; // coefficient etalonnage capteur de position
+ // float a=127.47; // coefficient etalonnage capteur de position
+ // float b=-6.23; // coefficient etalonnage capteur de position
// Initialisations
- IN1=0; // moteur non alimenté
- IN2=0;
- IN3=0;
- IN4=0;
+ printf("Demarrage1...\n");
+ DIRA=0; // moteur non alimenté
+ BRKA=0;
+ DIRB=0;
+ BRKB=0;
timer_etat.attach(&IT_timer_etat, 0.01); // mise à jour de la commande moteur toutes les 10ms (100Hz)
timer_reglage_vitesse.attach(&IT_timer_reglage_vitesse, 0.1); // mise à jour de la vitesse moteur par potentiomètre toutes les 0,1s
fc_haut.fall(&IT_fc_haut); // declaration des programmes kbi (SW2)
contact.fall(&IT_contact); // declaration des programmes kbi (SW3)
+ monte.fall(&IT_monte); // declaration des programmes kbi (D4)
+ descend.fall(&IT_descend); // declaration des programmes kbi (D8)
+ retour.fall(&IT_retour); // declaration des programmes kbi (D7)
+ stop.fall(&IT_stop); // declaration des programmes kbi (D6)
+ printf("Demarrage...\n");
// boucle programme principal
while(1) {
// on traite la liaison serie
if (pc.readable()){ // test liaison serie
pc.scanf("%s",command); // ecrit dans "command" la chaine reçue
+ /* if(strcmp(command,"position")==0){
+ position_demandee=Nb_pas*0.0000125;
+ sens=1;
+ ENA=1;
+ ENB=1;*/
if(strcmp(command,"stop")==0) {
sens=0; // si j'ai reçu "stop" désactivation du L298 et sens = 0
ENA=0;
ENB=0;
- }
+ }// fin stop
else if (strcmp(command,"avant")==0){
sens=1; // si j'ai reçu "avant" activation du L298 et sens = 1
ENA=1;
@@ -91,8 +124,6 @@
sens=-1;
ENA=1;
ENB=1;
- Nb_pas--;
- Nb_pas=0;
}
else if (strcmp(command,"contact")==0){
sens=0; // si j'ai reçu "contact" désactivation du L298 et position = 0
@@ -115,10 +146,11 @@
position_mesuree=Nb_pas*0.0125;
printf("Npas : %d , Vpos : %f , Position mesuree : %f \n", Nb_pas,Vpos,position_mesuree);
}
- else if(strcmp(command,"vitesse")==0) { // trame vitesse : "vitesse<CR>XXXX<CR>" où XXXX représente la frequence de pilotage du moteur
+ /* else if(strcmp(command,"vitesse")==0) { // trame vitesse : "vitesse<CR>XXXX<CR>" où XXXX représente la frequence de pilotage du moteur
pc.scanf("%s",command); // lecture de XXXX la frequence de pilotage
frequence=atoi(command); // change la chaine de caractères en entier
periode=1/float(frequence);
+ printf("frequence : %f, periode : %f \n", frequence,periode);
timer_etat.attach(&IT_timer_etat, periode); //on fixe la periode de pilotage du moteur
}
else if(strcmp(command,"position")==0) {
@@ -136,10 +168,12 @@
ENA=0;
ENB=0;
}
- }
- // on traite la commande du moteur
+ } */
+ // on traite la commande du moteur
+ } // fin if readable
if (flag_timer_etat==1)
{
+ //printf("etat=%d\n",etat);
if (sens ==1) {
etat++;
Nb_pas++;
@@ -148,63 +182,68 @@
else if (sens==-1){
etat--;
Nb_pas--;
+ if (Nb_pas<=0){ //quand Nb_pas arrive à 0, le moteur s'arrête
+ sens=0;
+ ENA=0;
+ ENB=0;
+ }
if (etat<0) etat=7;
- }
+ } // fin sens = -1
switch (etat) {
case 0 :
- IN1=1;
- IN2=0;
- IN3=0;
- IN4=0;
+ DIRA=1;
+ BRKA=0;
+ DIRB=0;
+ BRKB=1;
break;
case 1 :
- IN1=1;
- IN2=0;
- IN3=1;
- IN4=0;
+ DIRA=1;
+ BRKA=0;
+ DIRB=1;
+ BRKB=0;
break;
case 2 :
- IN1=0;
- IN2=0;
- IN3=1;
- IN4=0;
+ DIRA=0;
+ BRKA=1;
+ DIRB=1;
+ BRKB=0;
break;
case 3 :
- IN1=0;
- IN2=1;
- IN3=1;
- IN4=0;
+ DIRA=0;
+ BRKA=0;
+ DIRB=1;
+ BRKB=0;
break;
case 4 :
- IN1=0;
- IN2=1;
- IN3=0;
- IN4=0;
+ DIRA=0;
+ BRKA=0;
+ DIRB=0;
+ BRKB=1;
break;
case 5 :
- IN1=0;
- IN2=1;
- IN3=0;
- IN4=1;
+ DIRA=0;
+ BRKA=0;
+ DIRB=0;
+ BRKB=0;
break;
case 6 :
- IN1=0;
- IN2=0;
- IN3=0;
- IN4=1;
+ DIRA=0;
+ BRKA=1;
+ DIRB=0;
+ BRKB=0;
break;
case 7 :
- IN1=1;
- IN2=0;
- IN3=0;
- IN4=1;
+ DIRA=1;
+ BRKA=0;
+ DIRB=0;
+ BRKB=0;
break;
default :
etat=0;
- }
+ } // fin switch
// printf ("etat = %d\n",etat);
flag_timer_etat=0;
- }
+ } // fin if timer
if (flag_fc_haut==1){ // si j'ai un appui sur BP fc_haut : désactivation du L298 et position = 0
Nb_pas=0;
sens=0;
@@ -216,8 +255,31 @@
sens=-1;
ENA=1;
ENB=1;
+ printf("retour a zero \n");
flag_retour=0;
}
+ if (flag_monte==1){
+ wait(0.05);
+ sens=1;
+ ENA=1;
+ ENB=1;
+ printf("appui sur monte \n");
+ flag_monte=0;
+ }
+ if (flag_descend==1){
+ wait(0.05);
+ sens=-1;
+ ENA=1;
+ ENB=1;
+ printf("appui sur descend \n");
+ flag_descend=0;
+ }
+ if (flag_stop==1){
+ sens=0;
+ ENA=0;
+ ENB=0;
+ flag_stop=0;
+ }
if (flag_contact==1){ // si j'ai un appui sur BP contact : désactivation du L298 et envoi de la position
sens=0; // si j'ai reçu "contact" désactivation du L298 et position = 0
ENA=0;
@@ -236,16 +298,18 @@
/******************** Traitement contact si moteur pas à pas ************************************************/
/***********************************************************************************************************/
// en mode test sur système avec capteur de position
- position_mesuree=Nb_pas*0.0125;
+ position_mesuree=Nb_pas*0.0000125;
printf("Npas : %d , Vpos : %f , Position mesuree : %f mm \n", Nb_pas,Vpos,position_mesuree);
flag_contact=0;
}
if (flag_timer_reglage_vitesse==1){
Vpot=ain0.read(); // Vpot varie de 0 à 100% (0 à 1) en fonction du réglage vitesse
- frequence= 700*(Vpot+1); // frequence varie de 700 Hz à 1400Hz)
+ frequence= 1500*(Vpot+1); // frequence varie de 700 Hz à 1400Hz)
periode=1/float(frequence);
timer_etat.attach(&IT_timer_etat, periode); // maj vitesse moteur par potentiomètre
+ //printf("frequence : %f, periode : %f \n", frequence,periode);
flag_timer_reglage_vitesse=0;
}
}
}
+
--- a/mbed-os.lib Fri Jun 05 06:33:21 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://github.com/ARMmbed/mbed-os/#cf4f12a123c05fcae83fc56d76442015cb8a39e9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Jun 16 07:24:14 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc \ No newline at end of file
Binary file resources/official_armmbed_example_badge.png has changed