mirror of
https://github.com/AntoineHX/LivingMachine.git
synced 2025-05-04 13:50:46 +02:00
test moteurs ok
This commit is contained in:
parent
746a5227b5
commit
4bf5661a84
8 changed files with 187 additions and 38 deletions
17
Test moteurs/Makefile
Normal file
17
Test moteurs/Makefile
Normal file
|
@ -0,0 +1,17 @@
|
|||
CC=gcc
|
||||
CFLAGS=-Wall -g
|
||||
LDFLAGS=
|
||||
EXEC=moteur
|
||||
|
||||
all: $(EXEC)
|
||||
|
||||
moteur : moteur.c
|
||||
gcc -o $@ $^
|
||||
|
||||
.PHONY: clean mrproper
|
||||
|
||||
clean:
|
||||
rm -rf *.o
|
||||
|
||||
mrproper: clean
|
||||
rm -rf $(EXEC)
|
17
Test moteurs/Makefile~
Normal file
17
Test moteurs/Makefile~
Normal file
|
@ -0,0 +1,17 @@
|
|||
CC=gcc
|
||||
CFLAGS=-Wall
|
||||
LDFLAGS=
|
||||
EXEC=moteur
|
||||
|
||||
all: $(EXEC)
|
||||
|
||||
moteur : moteur.c
|
||||
gcc -o $@ $^
|
||||
|
||||
.PHONY: clean mrproper
|
||||
|
||||
clean:
|
||||
rm -rf *.o
|
||||
|
||||
mrproper: clean
|
||||
rm -rf $(EXEC)
|
Binary file not shown.
|
@ -1,58 +1,86 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
//screen /dev/ttyACM0
|
||||
|
||||
int main(){
|
||||
|
||||
FILE* fichier;
|
||||
|
||||
char* port_serie = "/dev/ttyACM0";
|
||||
char buffer[30];
|
||||
char q;
|
||||
int angle[2] = {0,0};
|
||||
int coeff = 1;
|
||||
|
||||
char c = '1';
|
||||
double angle[2];
|
||||
while(getchar() != 'q'){
|
||||
|
||||
fichier = fopen(port_serie,"r+");
|
||||
//Ouverture tty
|
||||
fichier = fopen(port_serie,"w");
|
||||
if(fichier==NULL){
|
||||
printf("Impossible d'ouvrir %s\n",port_serie);
|
||||
return 0;
|
||||
perror("fopen failed for /dev/ttyACM0" );
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
while(c != 'q'){
|
||||
|
||||
/* //Lecture tty
|
||||
printf("Valeurs moteurs xxx et yyy actuelles :\n");
|
||||
|
||||
|
||||
read(angle,sizeof(double),1,fichier);
|
||||
read(angle+1,sizeof(double),1,fichier);
|
||||
//fscanf(fichier,"%d %d",angle,angle+1);
|
||||
|
||||
printf("\nxxx=%lf; yyy=%lf\n",angle[0]*0.001,angle[1]*0.001);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
fichier = fopen(port_serie,"w+");
|
||||
if(fichier==NULL){
|
||||
printf("Impossible d'ouvrir %s\n",port_serie);
|
||||
return 0;
|
||||
}*/
|
||||
printf("\n Valeurs moteurs xxx,yyy ?\n");
|
||||
scanf("%lf %lf",angle,angle+1);
|
||||
|
||||
fprintf(fichier,"%lf %lf",angle[0]*0.001,angle[1]*0.001);
|
||||
/*
|
||||
fwrite(angle,1,sizeof(int),fichier);
|
||||
fwrite(angle+1,1,sizeof(int),fichier);*/
|
||||
|
||||
printf("\nq pour quitter\n");
|
||||
|
||||
c = getchar();
|
||||
c = getchar();
|
||||
|
||||
fscanf(fichier,"%d %d",angle,angle+1);
|
||||
printf("\nxxx=%d; yyy=%d\n",angle[0]*coeff,angle[1]*coeff);
|
||||
*/
|
||||
//Ecriture tty
|
||||
printf("\n Valeurs moteurs xxx,yyy ? ");
|
||||
|
||||
while(scanf(" %d %d", angle,angle+1) != 2){
|
||||
printf("Angles incorrects, mets les bonnes valeurs cette fois...\n");
|
||||
getchar();
|
||||
}
|
||||
|
||||
fprintf(fichier,"%d\n",angle[0]*coeff);
|
||||
fprintf(fichier,"%d\n",angle[1]*coeff);
|
||||
printf("Valeur actuelles : xxx=%d yyy=%d\n", angle[0],angle[1]);
|
||||
|
||||
|
||||
|
||||
//Quitter
|
||||
fclose(fichier);
|
||||
printf("\nq pour quitter\n");
|
||||
scanf(" %c",&q);
|
||||
if(q == 'q') break;
|
||||
}
|
||||
fclose(fichier);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*fwrite et fread
|
||||
|
||||
read(angle,sizeof(int),1,fichier);
|
||||
read(angle+1,sizeof(int),1,fichier);
|
||||
|
||||
fwrite(angle,1,sizeof(int),fichier);
|
||||
fwrite(angle+1,1,sizeof(int),fichier);
|
||||
*/
|
||||
|
||||
/*putc()
|
||||
char buffer[255];
|
||||
char* c;
|
||||
char* c0;
|
||||
int num;
|
||||
c=buffer;
|
||||
c0=buffer;
|
||||
for(num=0;num<2;){
|
||||
printf("a\n");
|
||||
*c=getc(stdin); // echo input back to terminal
|
||||
fputc(*c,fichier);
|
||||
if(*c == 'q')
|
||||
break ;
|
||||
if((*c == '\n') || (*c == '\r') || (*c == '\0') || (*c == ' ') || (*c == ','))
|
||||
{
|
||||
//
|
||||
*c='\0';
|
||||
angle[num]=atoi(c0);
|
||||
c0=c+1;
|
||||
num++;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
*/
|
||||
|
|
86
Test moteurs/moteur.c~
Normal file
86
Test moteurs/moteur.c~
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
//screen /dev/ttyACM0
|
||||
|
||||
int main(){
|
||||
|
||||
FILE* fichier;
|
||||
|
||||
char* port_serie = "/dev/ttyACM0";
|
||||
char q;
|
||||
int angle[2] = {0,0};
|
||||
int coeff = 1;
|
||||
|
||||
while(getchar() != 'q'){
|
||||
|
||||
//Ouverture tty
|
||||
fichier = fopen(port_serie,"w");
|
||||
if(fichier==NULL){
|
||||
printf("Impossible d'ouvrir %s\n",port_serie);
|
||||
perror("fopen failed for /dev/ttyACM0" );
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
|
||||
/* //Lecture tty
|
||||
printf("Valeurs moteurs xxx et yyy actuelles :\n");
|
||||
fscanf(fichier,"%d %d",angle,angle+1);
|
||||
printf("\nxxx=%d; yyy=%d\n",angle[0]*coeff,angle[1]*coeff);
|
||||
*/
|
||||
//Ecriture tty
|
||||
printf("\n Valeurs moteurs xxx,yyy ? ");
|
||||
|
||||
while(scanf(" %d %d", angle,angle+1) != 2){
|
||||
printf("Angles incorrects, mets les bonnes valeurs cette fois...\n");
|
||||
getchar();
|
||||
}
|
||||
|
||||
fprintf(fichier,"%d\n",angle[0]*coeff);
|
||||
fprintf(fichier,"%d\n",angle[1]*coeff);
|
||||
printf("Valeur actuelles : xxx=%d yyy=%d\n", angle[0],angle[1]);
|
||||
|
||||
|
||||
//Quitter
|
||||
fclose(fichier);
|
||||
printf("\nq pour quitter\n");
|
||||
scanf(" %c",&q);
|
||||
if(q == 'q') break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*fwrite et fread
|
||||
|
||||
read(angle,sizeof(int),1,fichier);
|
||||
read(angle+1,sizeof(int),1,fichier);
|
||||
|
||||
fwrite(angle,1,sizeof(int),fichier);
|
||||
fwrite(angle+1,1,sizeof(int),fichier);
|
||||
*/
|
||||
|
||||
/*putc()
|
||||
char buffer[255];
|
||||
char* c;
|
||||
char* c0;
|
||||
int num;
|
||||
c=buffer;
|
||||
c0=buffer;
|
||||
for(num=0;num<2;){
|
||||
printf("a\n");
|
||||
*c=getc(stdin); // echo input back to terminal
|
||||
fputc(*c,fichier);
|
||||
if(*c == 'q')
|
||||
break ;
|
||||
if((*c == '\n') || (*c == '\r') || (*c == '\0') || (*c == ' ') || (*c == ','))
|
||||
{
|
||||
//
|
||||
*c='\0';
|
||||
angle[num]=atoi(c0);
|
||||
c0=c+1;
|
||||
num++;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
*/
|
|
@ -1 +0,0 @@
|
|||
1 1
|
Binary file not shown.
|
@ -0,0 +1,2 @@
|
|||
1
|
||||
1
|
Loading…
Add table
Add a link
Reference in a new issue