PSL_2021 / Moteur_FCfurious
Committer:
lorenzodunau
Date:
Fri Oct 29 06:56:54 2021 +0000
Revision:
1:a0502fd47e2a
Parent:
0:7bc294a0862d
Child:
2:eb529b2bf093
modification par Lorenzo

Who changed what in which revision?

UserRevisionLine numberNew 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);
lorenzodunau 1:a0502fd47e2a 4
margaux_lht 0:7bc294a0862d 5 void cmd_moteur(float Vtm_s, float Vnm_s, float Wcrd_s){
margaux_lht 0:7bc294a0862d 6 float coeff=578.7/1023;
margaux_lht 0:7bc294a0862d 7 float W1;
margaux_lht 0:7bc294a0862d 8 float W2;
margaux_lht 0:7bc294a0862d 9 float W3;
margaux_lht 0:7bc294a0862d 10 float Rc;
margaux_lht 0:7bc294a0862d 11 float R;
margaux_lht 0:7bc294a0862d 12 float Vtc;
margaux_lht 0:7bc294a0862d 13 float Vnc;
margaux_lht 0:7bc294a0862d 14 float Wcc;
margaux_lht 0:7bc294a0862d 15 float Vtm_smax;
margaux_lht 0:7bc294a0862d 16 float Vnm_smax;
margaux_lht 0:7bc294a0862d 17 float Wcrd_smax;
margaux_lht 0:7bc294a0862d 18 Rc=0.08; // rayon du chassis*10
margaux_lht 0:7bc294a0862d 19 R=0.019; // rayon de la roue*10
margaux_lht 0:7bc294a0862d 20 W1=0;
margaux_lht 0:7bc294a0862d 21 W2=0;
margaux_lht 0:7bc294a0862d 22 W3=0;
margaux_lht 0:7bc294a0862d 23 //Vtm_smax=0.8; //sert pour calculer valeurs -999->999
margaux_lht 0:7bc294a0862d 24 //Vnm_smax=0.9;
margaux_lht 0:7bc294a0862d 25 //Wcrd_smax=2.9;
margaux_lht 0:7bc294a0862d 26 //if (Vtm_s>Vtm_smax)
margaux_lht 0:7bc294a0862d 27 // {Vtm_s=Vtm_smax;}
margaux_lht 0:7bc294a0862d 28 //if (Vnm_s>Vnm_smax)
margaux_lht 0:7bc294a0862d 29 // {Vnm_s=Vnm_smax;}
margaux_lht 0:7bc294a0862d 30 //if (Wcrd_s>Wcrd_smax)
margaux_lht 0:7bc294a0862d 31 // {Wcrd_s=Wcrd_smax;}
margaux_lht 0:7bc294a0862d 32 //if (Wcrd_s<-Wcrd_smax)
margaux_lht 0:7bc294a0862d 33 // {Wcrd_s=-Wcrd_smax;}
margaux_lht 0:7bc294a0862d 34
margaux_lht 0:7bc294a0862d 35 W1=(Wcrd_s*Rc-0.5*Vnm_s+0.866*Vtm_s)*coeff; //loi de commande moteur 1
margaux_lht 0:7bc294a0862d 36 W2=(Wcrd_s*Rc-0.5*Vnm_s-0.866*Vtm_s)*coeff;
margaux_lht 0:7bc294a0862d 37 W3=(Wcrd_s*Rc+Vnm_s)*coeff;
margaux_lht 0:7bc294a0862d 38 printf("%d %d %dn\r",(int)(1000*W1),(int)(1000*W2),(int)(1000*W3));
margaux_lht 0:7bc294a0862d 39
margaux_lht 0:7bc294a0862d 40
margaux_lht 0:7bc294a0862d 41 servo.SetSpeed(1,W1); // impose la vitesse au moteur 1
margaux_lht 0:7bc294a0862d 42 servo.SetSpeed(2,W2);
margaux_lht 0:7bc294a0862d 43 servo.SetSpeed(3,W3);
margaux_lht 0:7bc294a0862d 44
margaux_lht 0:7bc294a0862d 45
margaux_lht 0:7bc294a0862d 46
margaux_lht 0:7bc294a0862d 47 }