⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 app.c

📁 读取一个电机码盘信号
💻 C
字号:
#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <sys/time.h>#include <sys/types.h>#include <fcntl.h>#include <unistd.h>#include <sys/ioctl.h>#include "control.h"#define BUFSIZE 70int main(int argc,char *argv[]){	int CMD,CMD1,CMDPID;	int msg,choose,ready;	int Finish=30;	int Finish1;	int ch,letdo,checkall,a,b,c,save;	struct PID_struct PID;	letdo=1;	c=0;while(letdo){	ready=1;	// For the first time set all values	if(check){	PID.T=1.0;	PID.Ti=1.0;	PID.Kp=1.0;	PID.TD=1.0;	check=0;	/* Open fifo device */	if ((CMD = open("/dev/rtf0", O_WRONLY))<0) {	fprintf(stderr, "Error opening /dev/rtf0\n");	exit(1);}	if((CMD1=open("/dev/rtf2",O_RDONLY))<0){	fprintf(stderr,"Error opening /dev/rtf2\n");	exit(1);}		if((CMDPID=open("/dev/rtf5",O_WRONLY))<0){	fprintf(stderr,"Error opening /dev/rtf0\n");	exit(1);}	}	/*/ Set loop times	if(c){	Finish=save;}	fprintf(stderr,"\n Do you want set loop times? '1' for pass '2' for reset now is %d",Finish);	scanf("%d",&a);	if(a!=1){	fprintf(stderr,"\n input for loop times:\n");	scanf("%d",&b);	Finish=b;	save=b;	fprintf(stderr,"\n loop times is %d now\n")}*/	while(ready)	//set all values	{	fprintf(stderr,"now T=%f,Kp=%f,Ti=%f,TD=%f\n",PID.T,PID.Kp,PID.Ti,PID.TD);	fprintf(stderr,"do you want to reset the value?\n 1 for T, 2 for Kp, 3 for Ti, 4 for TD,5 for exit\n");	scanf("%d",&choose);//	getchar();	switch(choose)	{	case 1:		fprintf(stderr,"input for T\n");		scanf("%f",&PID.T);		fprintf(stderr,"the T is %f",PID.T);//		getchar();		break;		case 2:		fprintf(stderr,"input for Kp\n");		scanf("%f",&PID.Kp);//		getchar();		fprintf(stderr,"Kp is %fnow\n",PID.Kp);		break;		case 3:		fprintf(stderr,"input for Ti\n");		scanf("%f",&PID.Ti);		getchar();		fprintf(stderr,"Ti is %fnow\n",PID.Ti);		break;		case 4:		fprintf(stderr,"input for TD\n");		scanf("%f",&PID.TD);//		getchar();		fprintf(stderr,"TD is %fnow\n",PID.TD);		break;			case 5:		fprintf(stderr, "no value reset");		break;		default:		fprintf(stderr,"wrong input again!\n");		break;	}		fprintf(stderr, "\n Quit or set again? 1 for Quit 2 for set\n");		scanf("%d",&ch);	//	getchar();		fprintf(stderr," value set done!!\n");		if(ch==1)		{//	fprintf(stderr,"%d",ch);			ready=0;		}	}/* send the speed command to RT-task */	fprintf(stderr,"set the speed V=:\n");	scanf("%d",&PID.speed);	fprintf(stderr,"PID.speed set to be  %d \n ",PID.speed);// change all values and set to RT-task//	fprintf(stderr,"input for Ti= :\n");//	scanf("%d",&Ti);	if((write(CMDPID,&PID,sizeof(PID)))<0)	{	fprintf(stderr,"error when change the value of PID\n");	exit(1);	}		fprintf(stderr,"start the RT-task press 0 ,suspend it press 1");	while(1)	{		scanf("%d",&Finish1);	if((write(CMD, &Finish1, sizeof(Finish1))) < 0)		{       		 fprintf(stderr, "Can't send a command to RT-task\n");		 exit(1);		}		if(Finish1)	break;	}	c=1;	fprintf(stderr,"\n#######do you want set all value again?######\n 1 for yes 2 for no\n");	scanf("%d",&checkall);	if(checkall==2)	letdo=0;}	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -