思维导图
机械臂实现
#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;}char red[5]={0xff,0x02,0x00,0x00,0xff};unsigned char blue[5]={0xff,0x02,0x01,0x8a,0xff};while(1){char cmd;printf("请输入命令:");scanf("%c",&cmd);getchar();switch(cmd){case 'w':{red[3]+=10;send(cfd,red,sizeof(red),0);break;}case 's':{red[3]-=10;send(cfd,red,sizeof(red),0);break;}case 'a':{blue[3]-=10;send(cfd,blue,sizeof(blue),0);break;}case 'd':{blue[3]+=10;send(cfd,blue,sizeof(blue),0);break;}default:{printf("输入有误\n");}}}return 0;
}
按下后机械臂反应