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.
moteur.cpp@2:eb529b2bf093, 2021-10-29 (annotated)
- Committer:
- mdalal
- Date:
- Fri Oct 29 10:48:51 2021 +0000
- Revision:
- 2:eb529b2bf093
- Parent:
- 1:a0502fd47e2a
;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| margaux_lht | 0:7bc294a0862d | 1 | #include "MX12.h" |
| margaux_lht | 0:7bc294a0862d | 2 | //extern UnbufferedSerial pc_serie(USBTX,USBRX,115200); |
| lorenzodunau | 1:a0502fd47e2a | 3 | MX12 servo(PC_4,PC_5,115200); |
| mdalal | 2:eb529b2bf093 | 4 | const |
| lorenzodunau | 1:a0502fd47e2a | 5 | |
| margaux_lht | 0:7bc294a0862d | 6 | void cmd_moteur(float Vtm_s, float Vnm_s, float Wcrd_s){ |
| margaux_lht | 0:7bc294a0862d | 7 | float coeff=578.7/1023; |
| margaux_lht | 0:7bc294a0862d | 8 | float W1; |
| margaux_lht | 0:7bc294a0862d | 9 | float W2; |
| margaux_lht | 0:7bc294a0862d | 10 | float W3; |
| margaux_lht | 0:7bc294a0862d | 11 | float Rc; |
| margaux_lht | 0:7bc294a0862d | 12 | float R; |
| margaux_lht | 0:7bc294a0862d | 13 | float Vtc; |
| margaux_lht | 0:7bc294a0862d | 14 | float Vnc; |
| margaux_lht | 0:7bc294a0862d | 15 | float Wcc; |
| margaux_lht | 0:7bc294a0862d | 16 | float Vtm_smax; |
| margaux_lht | 0:7bc294a0862d | 17 | float Vnm_smax; |
| margaux_lht | 0:7bc294a0862d | 18 | float Wcrd_smax; |
| margaux_lht | 0:7bc294a0862d | 19 | Rc=0.08; // rayon du chassis*10 |
| margaux_lht | 0:7bc294a0862d | 20 | R=0.019; // rayon de la roue*10 |
| margaux_lht | 0:7bc294a0862d | 21 | W1=0; |
| margaux_lht | 0:7bc294a0862d | 22 | W2=0; |
| margaux_lht | 0:7bc294a0862d | 23 | W3=0; |
| margaux_lht | 0:7bc294a0862d | 24 | //Vtm_smax=0.8; //sert pour calculer valeurs -999->999 |
| margaux_lht | 0:7bc294a0862d | 25 | //Vnm_smax=0.9; |
| margaux_lht | 0:7bc294a0862d | 26 | //Wcrd_smax=2.9; |
| margaux_lht | 0:7bc294a0862d | 27 | //if (Vtm_s>Vtm_smax) |
| margaux_lht | 0:7bc294a0862d | 28 | // {Vtm_s=Vtm_smax;} |
| margaux_lht | 0:7bc294a0862d | 29 | //if (Vnm_s>Vnm_smax) |
| margaux_lht | 0:7bc294a0862d | 30 | // {Vnm_s=Vnm_smax;} |
| margaux_lht | 0:7bc294a0862d | 31 | //if (Wcrd_s>Wcrd_smax) |
| margaux_lht | 0:7bc294a0862d | 32 | // {Wcrd_s=Wcrd_smax;} |
| margaux_lht | 0:7bc294a0862d | 33 | //if (Wcrd_s<-Wcrd_smax) |
| margaux_lht | 0:7bc294a0862d | 34 | // {Wcrd_s=-Wcrd_smax;} |
| margaux_lht | 0:7bc294a0862d | 35 | |
| mdalal | 2:eb529b2bf093 | 36 | W2=(Wcrd_s*Rc-0.5*Vnm_s+0.866*Vtm_s)*coeff; //loi de commande moteur 1 |
| mdalal | 2:eb529b2bf093 | 37 | W3=(Wcrd_s*Rc-0.5*Vnm_s-0.866*Vtm_s)*coeff; |
| mdalal | 2:eb529b2bf093 | 38 | W1=(Wcrd_s*Rc+Vnm_s)*coeff; |
| margaux_lht | 0:7bc294a0862d | 39 | printf("%d %d %dn\r",(int)(1000*W1),(int)(1000*W2),(int)(1000*W3)); |
| margaux_lht | 0:7bc294a0862d | 40 | |
| margaux_lht | 0:7bc294a0862d | 41 | |
| margaux_lht | 0:7bc294a0862d | 42 | servo.SetSpeed(1,W1); // impose la vitesse au moteur 1 |
| margaux_lht | 0:7bc294a0862d | 43 | servo.SetSpeed(2,W2); |
| margaux_lht | 0:7bc294a0862d | 44 | servo.SetSpeed(3,W3); |
| margaux_lht | 0:7bc294a0862d | 45 | |
| margaux_lht | 0:7bc294a0862d | 46 | |
| margaux_lht | 0:7bc294a0862d | 47 | |
| margaux_lht | 0:7bc294a0862d | 48 | } |