思维导图
机械臂实现
#include <head.h>
#define SER_POTR 8899
#define SER_IP "192.168.125.223"
int main(int argc, const char *argv[])
{//创建套接字int cfd=socket(AF_INET,SOCK_STREAM,0);if(cfd==-1){perror("");return -1;}//链接struct sockaddr_in sin;sin.sin_family=AF_INET;sin.sin_port=htons(SER_POTR);sin.sin_addr.s_addr=inet_addr(SER_IP);if(connect(cfd,(struct sockaddr*)&sin,sizeof(sin))==-1){perror("connect error:");return -1;}int buf[5];buf[0]=0xff;buf[1]=0x02;buf[2]=0x00;buf[3]=0x5a;buf[4]=0xff;char cbuf[128]="";sprintf(cbuf,"%x %x %x %x %x",buf[0],buf[1],buf[2],buf[3],buf[4]);send(cfd,cbuf,sizeof(cbuf),0);while(1){char cmd;printf("请输入命令:");scanf("%c",&cmd);getchar();switch(cmd){case 'w':{buf[2]=0;buf[3]++;break;}case 's':{buf[2]=0;buf[3]--;break;}case 'a':{buf[2]=1;buf[3]--;break;}case 'd':{buf[2]=1;buf[3]++;break;}default:{printf("输入有误\n");}}sprintf(cbuf,"%x %x %x %x %x",buf[0],buf[1],buf[2],buf[3],buf[4]);printf("%s\n",cbuf);send(cfd,cbuf,sizeof(cbuf),0);}return 0;
}
按下后机械臂反应