好文档 - 专业文书写作范文服务资料分享网站

C++AGV路径规划与运行仿真程序 

天下 分享 时间: 加入收藏 我要投稿 点赞

程序代码

#include<> #include<>

#include<> #include<> #include<> #include<> #include<>

#define MAX 100 #define maxD 99999 class CFixedMap {

struct Coordinate {

int x; int y; int num; };um)

x=mVexs[i].x; return x; }

int CFixedMap::gety(int n2) {

int y=0;

for(int i=0;i

void CFixedMap::Input() {

int panju;

char fname[10]={\

cout<<\是否载入默认地图?(1:是,2:否)\ cin>>panju; if(panju==2) {

cout<<\请输入地图信息文件名:\ cin>>fname; }

ifstream file(fname); char use1[100]; char use2[100];

char use3[100];

char use4[100]; um>>mVexs[i].x>>mVexs[i].y; }

file>>use4;

for(i=0;i>comb[i].num2; } (); }

,mVexs[i].y,5);

settextcolor(BLACK); char s[MAX];

sprintf(s, \

outtextxy(mVexs[i].x-10,mVexs[i].y-20,s); }

1=getx(comb[i].num1);

cp[i].y1=gety(comb[i].num1); cp[i].x2=getx(comb[i].num2); cp[i].y2=gety(comb[i].num2);

line(cp[i].x1,cp[i].y1,cp[i].x2,cp[i].y2); } }

class CPathPlan:public CFixedMap {

public:

int path[MAX]; um1) {

a=comb[i].num1-1; b=comb[i].num2-1;

x=mVexs[a].x-mVexs[b].x; y=mVexs[a].y-mVexs[b].y; mMatrix[a][b]=sqrt(x*x+y*y); mMatrix[b][a]=sqrt(x*x+y*y); } } }

void CPathPlan::Dijstra() {

cout<<\输入起点:\ cin>>v0; v0--;

int s[MAX]; int v; int i; int j;

int w;

double min;

for(v=0;v

file2<<\路径长度为:\path\

for(int j=0;j

file2<

file2<

for(i=0;i

rpoints[i].x=getx(route[i]); rpoints[i].y=gety(route[i]); rpoints[i].num=route[i]; } }

class CAGV {

int speed; ; x2=rpoints[o+1].x; y1=rpoints[o].y; y2=rpoints[o+1].y; if(y1!=y2&&x1!=x2) {

if(x2>x1&&y2>y1){

for(j=1;j

a=x1+j-l; b=y1+j*k+w; c=x1+j+l; d=y1+j*k-w;

setfillcolor(RGB(0,0,0)); rectangle(a,b,c,d);

clearrectangle(a-1,b-k,c,d-k); setlinecolor(RED);

line(x1+j,y1+j*k,x2,y2); setlinecolor(GREEN); line(x1,y1,x1+j,y1+j*k); if(j%2==0)

{

setfillcolor(RGB(255,255,0)); circle(x2,y2,5); }

Sleep(s); } }

if(x2

for(j=1;j

a=x1-j-l; b=y1-j*k+w; c=x1-j+l; d=y1-j*k-w;

setfillcolor(RGB(0,0,0)); rectangle(a,b,c,d);

clearrectangle(a-1,b-k,c,d-k); setlinecolor(RED);

line(x1-j,y1-j*k,x2,y2); setlinecolor(GREEN); line(x1,y1,x1-j,y1-j*k); if(j%2==0) {

setfillcolor(RGB(255,255,0)); circle(x2,y2,5); }

Sleep(s); } }

if(x2y1) {

for(j=1;j

a=x1-j-l; b=y1+j*k+w; c=x1-j+l; d=y1+j*k-w;

setfillcolor(RGB(0,0,0)); rectangle(a,b,c,d);

clearrectangle(a-1,b-k,c,d-k); setlinecolor(RED);

line(x1-j,y1+j*k,x2,y2); setlinecolor(GREEN);

line(x1,y1,x1-j,y1+j*k); if(j%2==0) {

setfillcolor(RGB(255,255,0)); circle(x2,y2,5); }

Sleep(s); } }

if(x2>x1&&y2

for(j=1;j

a=x1+j-l; b=y1-j*k+w; c=x1+j+l; d=y1-j*k-w;

setfillcolor(RGB(0,0,0)); rectangle(a,b,c,d);

clearrectangle(a-1,b-k,c,d-k); setlinecolor(RED);

line(x1+j,y1-j*k,x2,y2); setlinecolor(GREEN); line(x1,y1,x1+j,y1-j*k); if(j%2==0) {

setfillcolor(RGB(255,255,0)); circle(x2,y2,5); }

Sleep(s); } } }

else if(y1==y2) {

if(x2>x1) {

for(j=1;j<(x2-x1);j++) {

setfillcolor(RGB(0,0,0));

rectangle(x1+j-l,y1+w,x1+j+l,y1-w);

clearrectangle(x1+j-l-1,y1+w,x1+j+l-1,y1-w); setlinecolor(RED); line(x1+j,y1,x2,y2);

37dhh7bvt88iiwn479cv9uewu2s0h401e2y
领取福利

微信扫码领取福利

微信扫码分享