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

📄 m_menub.h

📁 scara机器人的一种简单的实现方法
💻 H
字号:
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include <dos.h>
#include <math.h>
#include <alloc.h>
#include "drawing.h"

/*Define the data getting in touch with "Mouse"*/

extern int Quit(void);

union REGS ireg,oreg;

int mouse_x=0,mouse_y=0;
int maxx,maxy;

FILE  *fp;

/*The following funtions is about the "mouse"*/
int Reset(void)
	{
	ireg.x.ax=0;
	int86(0x33,&ireg,&oreg);
	if(oreg.x.ax==0)
	   return (0);
	else
	   return (1);
	}

void Show_Mouse(void)
	{
	ireg.x.ax=1;
	int86(0x33,&ireg,&ireg);
	delay(100);
	}

void Hide_Mouse(void)
	{
	ireg.x.ax=2;
	int86(0x33,&ireg,&ireg);
	delay(100);
	}

char Left_Pressed(void)
	{
	ireg.x.ax=3;
	int86(0x33,&ireg,&oreg);
	return (oreg.x.bx & 1);
	}

char Right_Pressed(void)
	{
	ireg.x.ax=3;
	int86(0x33,&ireg,&oreg);
	return (oreg.x.bx & 2);
	}

void Get_XY(void)
	{
	ireg.x.ax=3;
	int86(0x33,&ireg,&oreg);
	mouse_x=oreg.x.cx;
	mouse_y=oreg.x.dx;
	}

void Set_XY(int x,int y)
	{
	ireg.x.ax=4;
	oreg.x.cx=x;
	oreg.x.dx=y;
	int86(0x33,&ireg,&ireg);
	}

void Set_X_Range(int min,int max)
	{
	ireg.x.ax=7;
	ireg.x.cx=min;
	ireg.x.dx=max;
	int86(0x33,&ireg,&ireg);
	}

void Set_Y_Range(int min,int max)
	{
	ireg.x.ax=8;
	ireg.x.cx=min;
	ireg.x.dx=max;
	int86(0x33,&ireg,&ireg);
	}

int Motion(int *x,int *y)
	{
	ireg.x.ax=11;
	int86(0x33,&ireg,&oreg);
	*x=oreg.x.cx;
	*y=oreg.x.dx;
	return (*x||*y);
	}

void RCCDsp(int x,int y,float xt,float yt,
	    int z,int A1,int A2,int Color,char *s)
	{
	unsigned Zcode,Bcode;
	int i,j,k,Rec,x4,y4;
	float x1,y1,x2,y2,x3,y3;
	float Alf,Bat,n=-1.0;
	long Len;
	char Buf[72];
	Alf=-A1*3.14/180;
	Bat=A2*3.14/180;

	while(*s)
	   {
	   if((*s & 0x80) && (*(s+1) & 0x80))
	      {
	      Zcode=(*s-0xa1)&0x07f;
	      Bcode=(*(s+1)-0xa1)&0x07f;
	      n++;
	      Rec=(Zcode-15)*94+Bcode;
	      Len=Rec*72L;
	      fseek(fp,Len,SEEK_SET);
	      fread(Buf,1,72,fp);
	      for(i=0;i<24;i++)
		 {
		 for(j=0;j<3;j++)
		     {
		     for(k=0;k<8;k++)
			 {
			 if(Buf[i*3+j]>>(7-k)&1)
			    {
			    x1=xt*(i+24*n);
			    y1=yt*(j*8+k);
			    y2=y1;
			    x2=x1+y1*tan(Bat);
			    x3=x2*cos(Alf)-y2*sin(Alf);
			    y3=x2*sin(Alf)+y2*cos(Alf);
			    x4=x3+x;
			    y4=y3+y;
			    putpixel(x4,y4,Color);
			    }
			 }
		     }
		 }
	      x=x+z;
	      s+=2;
	      }
	   }
	}

void OpenLib(void)
	{
	if((fp=fopen("c:\\lin\\hzk24s","rb"))==NULL)
	   {
	   printf("Open Chinese Lib File Error! ");
	   printf("Press any key to quit the prosedure.\n");
	   getch();
	   Quit();
	   }
	}

/*Draw a button*/
void drawbutton(int left_x,int top_y,int right_x,int bottom_y,int flag,int col)
	{
	int svcolor=getcolor();
	struct fillsettingstype save;

	setfillstyle(SOLID_FILL,col);
	bar(left_x+1,top_y+1,right_x-1,bottom_y-1);

	if(flag)
	   {
	   setcolor(WHITE);
	   line(left_x,bottom_y,left_x,top_y);
	   line(left_x,top_y,right_x,top_y);

	   setcolor(0);
	   line(left_x,bottom_y,right_x,bottom_y);
	   line(right_x,bottom_y,right_x,top_y);
	   }
	else
	   {
	   setcolor(WHITE);
	   line(left_x,bottom_y,right_x,bottom_y);
	   line(right_x,bottom_y,right_x,top_y);

	   setcolor(0);
	   line(left_x,bottom_y,left_x,top_y);
	   line(left_x,top_y,right_x,top_y);

	   }
	setcolor(svcolor);
	setfillstyle(save.pattern,save.color);
	}

void graph_ini(void)
	{
	int GraphDriver;
	int GraphMode;

	GraphDriver=DETECT;
	GraphMode=0;
	initgraph(&GraphDriver,&GraphMode,"c:\\tc\\bgi\\");
	maxx=getmaxx();
	maxy=getmaxy();
	}

int Quit(void)
	{
	closegraph();
	fcloseall();
	exit(0);
	return;
	}

void Ini_menu(void)
	{
	graph_ini();
	OpenLib();
	Reset();
	Set_X_Range(0,maxx-2);
	Set_Y_Range(0,maxy-2);

	drawbutton(0,0,maxx,maxy,1,LIGHTGRAY);
	drawbutton(1,1,maxx-1,maxy-1,1,LIGHTGRAY);
	drawbutton(9,9,maxx-9,58,1,LIGHTGRAY);
	drawbutton(10,10,maxx-10,57,1,LIGHTGRAY);

	drawbutton(9,64,630,470,1,LIGHTGRAY);
	drawbutton(10,65,629,469,1,LIGHTGRAY);

	drawbutton(15,70,115,464,0,GREEN);
	drawbutton(125,70,624,464,0,CYAN);


	RCCDsp(160,22,1,1,17,0,0,BLUE,"机器人螺钉柔性装配演示");
	RCCDsp(160,92,1.3,1.3,9,0,0,RED,"华南理工大学机电工程系");
	RCCDsp(260,137,1,1,17,0,0,RED,"机器人实验室");
	RCCDsp(160,400,0.6,0.6,10,0,0,YELLOW,"指导老师");
	RCCDsp(280,400,0.6,0.6,10,0,0,YELLOW,"谢存禧");
	RCCDsp(360,400,0.6,0.6,10,0,0,YELLOW,"刘桂雄");
	RCCDsp(160,425,0.6,0.6,58,0,0,YELLOW,"设计");//李绣峰、林一松");
	RCCDsp(280,425,0.6,0.6,10,0,0,YELLOW,"李绣峰");
	RCCDsp(360,425,0.6,0.6,10,0,0,YELLOW,"林一松");


	/*---------------------------------------------------------*/

	drawbutton(55,80,105,105,1,7);
	RCCDsp(58,87,0.4,0.4,2,0,0,BLUE,"单步运行");
	drawbutton(55,125,105,150,1,7);
	RCCDsp(58,132,0.4,0.4,2,0,0,BLUE,"连续运行");
	drawbutton(55,170,105,195,1,7);
	RCCDsp(58,177,0.4,0.4,24,0,0,BLUE,"暂停");
	drawbutton(55,215,105,240,1,7);
	RCCDsp(58,222,0.4,0.4,2,0,0,BLUE,"紧急停止");
	drawbutton(55,260,105,285,1,7);
	RCCDsp(58,267,0.4,0.4,24,0,0,BLUE,"退出");

	Show_Mouse();
	}


int Menu(void)
	{
	int Flag=1;
	int chosed_button=0;


//	while(!(Right_Pressed()))
//	   {
	   Get_XY();
/*1*/	   if((Left_Pressed())&&
	   (mouse_x>55)&&(mouse_x<105)&&
	   (mouse_y>80)&&(mouse_y<105))
	      {
	      Flag=(~Flag)&1;
	      Hide_Mouse();
	      drawbutton(55,80,105,105,0,7);
	      Show_Mouse();

	      while(Left_Pressed())
		 {
		 Flag|=Flag;
		 }
	      Hide_Mouse();
	      drawbutton(55,80,105,105,1,7);
	      RCCDsp(58,87,0.4,0.4,2,0,0,BLUE,"单步运行");
	      chosed_button = STEP_MOVEMENT;
	      Show_Mouse();
	      }

/*2*/	   else if((Left_Pressed())&&
	   (mouse_x>55)&&(mouse_x<105)&&
	   (mouse_y>125)&&(mouse_y<150))
	      {
	      Flag=(~Flag)&1;
	      Hide_Mouse();
	      drawbutton(55,125,105,150,0,7);
	      Show_Mouse();

	      while(Left_Pressed())
		 {
		 Flag|=Flag;
		 }
	      Hide_Mouse();
	      drawbutton(55,125,105,150,1,7);
	      RCCDsp(58,132,0.4,0.4,2,0,0,BLUE,"连续运行");
	      chosed_button = CONTINUOUS_MOVEMENT;
	      Show_Mouse();
	      }

/*3*/	   if((Left_Pressed())&&
	   (mouse_x>55)&&(mouse_x<105)&&
	   (mouse_y>170)&&(mouse_y<195))
	      {
	      Flag=(~Flag)&1;
	      Hide_Mouse();
	      drawbutton(55,170,105,195,0,7);
	      Show_Mouse();

	      while(Left_Pressed())
		 {
		 Flag|=Flag;
		 }
	      Hide_Mouse();
	      drawbutton(55,170,105,195,1,7);
	      RCCDsp(58,177,0.4,0.4,24,0,0,BLUE,"暂停");
	      chosed_button = PAUSE;
	      Show_Mouse();
	      }
/*4*/	   if((Left_Pressed())&&
	   (mouse_x>55)&&(mouse_x<105)&&
	   (mouse_y>215)&&(mouse_y<240))
	      {
	      Flag=(~Flag)&1;
	      Hide_Mouse();
	      drawbutton(55,215,105,240,0,7);
	      Show_Mouse();

	      while(Left_Pressed())
		 {
		 Flag|=Flag;
		 }
	      Hide_Mouse();
	      drawbutton(55,215,105,240,1,7);
	      RCCDsp(58,222,0.4,0.4,2,0,0,BLUE,"紧急停止");
	      chosed_button = STOP;
	      Show_Mouse();
	      }

/*5*/	   if((Left_Pressed())&&
	   (mouse_x>55)&&(mouse_x<105)&&
	   (mouse_y>260)&&(mouse_y<285))
	      {
	      Flag=(~Flag)&1;
	      Hide_Mouse();
	      drawbutton(55,260,105,285,0,7);
	      Show_Mouse();

	      while(Left_Pressed())
		 {
		 Flag|=Flag;
		 }
	      Hide_Mouse();
	      drawbutton(55,260,105,285,1,7);
	      RCCDsp(58,267,0.4,0.4,24,0,0,BLUE,"退出");
	      chosed_button = QUIT;
	      Show_Mouse();
	      }

//	   }
	return chosed_button;
	}

void step_display(int i)
{

     RCCDsp(160,400,0.6,0.6,10,0,0,YELLOW,"指导老师");

   return;
}

⌨️ 快捷键说明

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