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.
main.cpp
- Committer:
- higepi
- Date:
- 2020-02-28
- Revision:
- 3:ac6eead48a9d
- Parent:
- 1:6554c60faa06
- Child:
- 4:4160376d7d69
File content as of revision 3:ac6eead48a9d:
#include "mbed.h" //AX12 myax12 (PC_4, PC_5, 1,115200); Serial myserial_ax12(PC_4,PC_5,115200); char tata[10]; int position; Ticker fonction_10ms; void Rx_Irq_fonction(void) { static int i_rx; tata[i_rx]=myserial_ax12.getc(); if (tata[0]!=0xFF) i_rx=0; else i_rx++; if ((tata[0]==0xFF) && (tata[1]==0xFF) && (tata[2]==0x01) && i_rx==7) { i_rx=0; if(tata[4]==00) //si erreur est nulle position = tata[5]+((uint16_t)tata[6]<<8); tata[0]=0; } if (i_rx>9) { for(int i=0;i<10;i++) tata[i]=0; i_rx=0; } } void fonction_10ms(void) { for(i=0;i<=7;i++) { myserial_ax12.putc(trame_demande_pos[i]); } } int main(){ //myax12.SetMode(1); //passage en Continuous rotation char trame_demande_pos[8]={0xFF,0xFF,0x01,0x4,0x2,0x24,2,0xD2}; char trame_cmd_speed[9]={0xFF,0xFF,0x01,0x5,0x3,0x20,0x10,0x0,0xC6}; float Angle; short speed; char data[10]; char s=0; float temp; int position_old=0,i,a; //myax12.SetCRSpeed(0.05); for(i=0;i<=8;i++) { myserial_ax12.putc(trame_cmd_speed[i]); } for(i=0;i<=7;i++) { myserial_ax12.putc(trame_demande_pos[i]); } myserial_ax12.attach(&Rx_Irq_fonction, Serial::RxIrq); while(1) { if (position != position_old) { printf("\n\rposition = %d\n\r mot recu :",position); for(i=0;i<=7;i++) { printf("%X ",tata[i]); } position_old=position; } wait(0.01); a++; if(!(a % 20)) } } void set_speed(ID,speed) void demande_lecture_pos(ID) /* #include "mbed.h" //AX12 myax12 (PC_4, PC_5, 1,115200); Serial myserial_ax12(PC_4,PC_5,115200); char tata[10]; int position; void Rx_Irq_fonction(void) { static int i_rx; tata[i_rx]=myserial_ax12.getc(); if (tata[0]!=0xFF) i_rx=0; else i_rx++; if ((tata[0]==0xFF) && (tata[1]==0xFF) && (tata[2]==0x01) && i_rx==7) { i_rx=0; if(tata[4]==00) //si erreur est nulle position = tata[5]+((uint16_t)tata[6]<<8); tata[0]=0; } if (i_rx>9) { for(int i=0;i<10;i++) tata[i]=0; i_rx=0; } } int main(){ //myax12.SetMode(1); //passage en Continuous rotation char trame_demande_pos[8]={0xFF,0xFF,0x01,0x4,0x2,0x24,2,0xD2}; char trame_cmd_speed[9]={0xFF,0xFF,0x01,0x5,0x3,0x20,0x10,0x0,0xC6}; float Angle; short speed; char data[10]; char s=0; float temp; int position_old=0,i,a; //myax12.SetCRSpeed(0.05); for(i=0;i<=8;i++) { myserial_ax12.putc(trame_cmd_speed[i]); } for(i=0;i<=7;i++) { myserial_ax12.putc(trame_demande_pos[i]); } myserial_ax12.attach(&Rx_Irq_fonction, Serial::RxIrq); while(1) { if (position != position_old) { printf("\n\rposition = %d\n\r mot recu :",position); for(i=0;i<=7;i++) { printf("%X ",tata[i]); } position_old=position; } wait(0.01); a++; if(!(a % 20)) for(i=0;i<=7;i++) { myserial_ax12.putc(trame_demande_pos[i]); } } } void set_speed(ID,speed)*/