机器人实验一.docx
《机器人实验一.docx》由会员分享,可在线阅读,更多相关《机器人实验一.docx(14页珍藏版)》请在冰豆网上搜索。
![机器人实验一.docx](https://file1.bdocx.com/fileroot1/2023-2/22/c487fc87-5ada-4618-aca5-e2a9f5b9d553/c487fc87-5ada-4618-aca5-e2a9f5b9d5531.gif)
机器人实验一
课程名称机器人技术及其应用
实验序号01
实验项目机器人仿真平台的应用
实验地点综B—910
实验学时6实验类型验证性
指导教师实验员
专业_计算机科学与技术(师范)班级09计本2班
学号姓名
2012年4月24日
实验报告要求
1、实验报告封面填表说明(每份实验报告必须附上封面)
(1)课程名称:
要求与实验大纲和实验指导书中的课程名称一致。
(2)实验序号:
指该课程的第几个实验。
(3)实验项目:
要求与实验大纲和实验指导书中的实验项目一致。
(4)实验地点:
填写完成该实验项目所在的实验室名称。
(5)实验学时:
要求与实验大纲和实验指导书中完成该实验项目所需学时一致。
(6)实验类型:
是指演示性、操作性、验证性、综合性、设计性。
演示性:
教师操作,学生观察,验证理论、说明原理和方法。
操作性:
学生按要求动手拆装、调试实验装置或上机操作,掌握其基本原理和方法。
验证性:
按实验指导书(教材)要求,由学生通过操作验证所学理论,加深对理论、知识的理解,掌握基本实验知识、方法、技能、数据处理等。
综合性:
实验内容涉及本课程的综合知识或相关课程的知识,运用多的知识、多种方法,按要求或自拟实验方案进行实验。
主要培养学生综合运用所学知识、实验方法和实验技能,以培养其分析、解决问题的能力。
设计性:
给定实验目的、要求和实验条件,学生自己设计实验方案并加以实现的实验。
学生独立完成从查阅资料、拟定实验方案、实验方法和步骤(或系统分析和设计)、选择仪器设备(或自行设计缺制作)进行实验并完成实验全过程,形成实验报告,培养学生自主实验的能力。
2、实验报告的格式
成绩:
教师评语
指导教师签名:
批阅日期:
一、实验目的及要求
实验目的:
1.熟悉机器人仿真平台AI-RCJ的安装、组成
2.掌握机器人仿真平台的系统参数设置。
3.学会简单的机器人程序的设计与调试方法。
二、实验原理与内容
实验内容:
1.机器人仿真平台AI-RCJ的安装
2.机器人仿真平台的系统参数设置。
3.简单的机器人程序的设计。
实验指导教材
《AI-RCJC语言教程教材》.中鸣公司.2008
《AI-RCJ图形化编程教材》.中鸣公司.2008
三、实验软硬件环境
实验设备:
安装AI-RCJ机器人仿真平台的PC机
四、实验过程(实验步骤、记录、数据、分析)
10、使用数组保存数据,编写简单行走的机器人。
机器人在点(50,100)(150,100)(400,150)(100,1500)(300,250)之间来回运动。
#include
voidrun()
{
while
(1){
doMoveTo(50,100);
doMoveTo(150,100);
doMoveTo(400,150);
doMoveTo(100,1500);
doMoveTo(300,250);
doMoveTo(50,100);
}
}
11、编写一个能够移动到球场中央位置的机器人。
#include
voidrun()
{
while
(1){
setMoveTo(getCourtCenterX(),getCourtCenterY());
execute();
}
}
12、编写一个能够不断移动到(x+200,y+300)位置的机器人,其中x、y是机器人的当前坐标。
#include
voidrun()
{
while
(1){
setMoveTo(getX()+200,getY()+300);
execute();
}
}
13、编写一个能够移动到进攻球门中心位置的机器人。
#include
voidrun()
{
while
(1){
getAttack();
doMoveTo(getCourtWidth(),getCourtCenterY());
}
}
14、编写一个能够在自己球门前来回移动的机器人。
#include
voidrun()
{
while
(1){
inti;
doublex,y,z;
i=getAttack();
y=getCourtCenterY();
z=getGoalWidth();
if(i=1)
x=0;
else
x=getCourtWidth();
doMoveTo(x,y+z/2);
doMoveTo(x,y-z/2);
}
}
15、编写一个能够进行简单进攻的机器人。
如图1所示,A点是机器人当前的位置,B点是足球当前的位置,P点是进攻球门中心。
要求机器人移动到C点后,一直往前推球以使其进入球门。
图1机器人的简单进攻图
#include
voidrun()
{
doMoveTo(0,0);
doublepx,py;
px=getOpponentGoalCenterX();
py=getOpponentGoalCenterY();
doublebx,by;
bx=getBallX();
by=getBallY();
doublebc=getBallRadius()+getRadius()+10;
doublepbheading=heading(px,py,bx,by);
doublecx=bx+cos(pbheading)*bc;
doublecy=by+sin(pbheading)*bc;
doMoveTo(cx,cy);
doTurnTo(toRadians(pbheading));
while
(1){
doMoveTo(getBallX(),getBallY());
}
}
16、编写一个能够进行简单防守的机器人。
要求:
(1)机器人站在球门前。
(2)机器人能实时的跟着足球作位置的调整。
当足球在球门范围时,机器人和足球处在一个水平线上,即Y坐标相等;当足球不在球门范围时,机器人处在球门对应的边角处。
#include
voidrun()
{
doublewidth,width1,ball_y,radius;
width=getCourtWidth();
width1=getGoalWidth();
doubley,y1,y2;
y=getCourtCenterY();
y1=y+width1/2;
y2=y-width1/2;
radius=getRadius();
doublerobotx,roboty;
if(getAttack()>0)
{
robotx=radius;
}
else
{
robotx=width-radius;
}
while
(1){
ball_y=getBallY();
if(ball_y>y1)
roboty=y1;
elseif(ball_yroboty=y2;
else
roboty=ball_y;
doMoveTo(robotx,roboty);
}
}
17、编写一个足球的运动预测程序,要求能够判断n个单位时间后足球所在的位置。
函数声明如下:
ntimepoint(inttimes,double*ballx,double*bally)。
#include
voidnext(inttimes,double*nextX,double*nextY)
{
doublevelocity=getBallVelocity();
doubleheading=getBallHeading();
doubleacc=-getBallNegativeAcceleration();
inti;
*nextX=getBallX();
*nextY=getBallY();
for(i=0;i{
if(velocity==0)break;
nextPoint(*nextX,*nextY,heading,velocity*1,nextX,nextY);
if(velocity>0)
{
velocity+=acc*1;
velocity=MAX(0,velocity);
}
elseif(velocity<0)
{
velocity-=acc*1;
velocity=MIN(0,velocity);
}
if((*nextX)<0||(*nextX)>getCourtWidth())
{
heading=PI-heading;
modifyInCourt(nextX,nextY,getBallRadius());
}
if((*nextY)<0||(*nextY)>getCourtHeight())
{
heading=-heading;
modifyInCourt(nextX,nextY,getBallRadius());
}
}
}
18、编写一个进攻机器人,在其中加入第7题编写的足球运动预测程序。
#include
voidrun()
{
doublehitedX,hitedY;
while
(1){
hitedX=getBallX();
hitedY=getBallY();
doMoveTo(hitedX,hitedY);
}
}
voidnext(inttimes,double*nextX,double*nextY);
voidrun()
{
while
(1){
doublehitedX=getBallX();
doublehitedY=getBallY();
for(inti=0;i<200;i++)
{
doublenextX,nextY;
next(i,&nextX,&nextY);
if(distance(nextX,nextY,getX(),getY())
{
hitedX=nextX;
hitedY=nextY;
break;
}
}
setMoveTo(hitedX,hitedY);
execute();
}
}
voidnext(inttimes,double*nextX,double*nextY)
{
doublevelocity=getBallVelocity();
doubleheading=getBallHeading();
doubleacc=-getBallNegativeAcceleration();
inti;
*nextX=getBallX();
*nextY=getBallY();
for(i=0;i{
if(velocity==0)break;
nextPoint(*nextX,*nextY,heading,velocity*1,nextX,nextY);
if(velocity>0)
{
velocity+=acc*1;
velocity=MAX(0,velocity);
}
elseif(velocity<0)
{
velocity-=acc*1;
velocity=MIN(0,velocity);
}
if((*nextX)<0||(*nextX)>getCourtWidth())
{
heading=PI-heading;
modifyInCourt(nextX,nextY,getBallRadius());
}
if((*nextY)<0||(*nextY)>getCourtHeight())
{
heading=-heading;
modifyInCourt(nextX,nextY,getBallRadius());
}
}
}
19、编写一个防守机器人,可用在第6题编写的程序中加入第7题编写的足球运动预测程序。
#include
voidnext(inttimes,double*nextX,double*nextY);
voidnext(inttimes,double*nextX,double*nextY)
{
doublevelocity=getBallVelocity();
doubleheading=getBallHeading();
doubleacc=-getBallNegativeAcceleration();
inti;
*nextX=getBallX();
*nextY=getBallY();
for(i=0;i{
if(velocity==0)break;
nextPoint(*nextX,*nextY,heading,velocity*1,nextX,nextY);
if(velocity>0)
{
velocity+=acc*1;
velocity=MAX(0,velocity);
}
elseif(velocity<0)
{
velocity-=acc*1;
velocity=MIN(0,velocity);
}
if((*nextX)<0||(*nextX)>getCourtWidth())
{
heading=PI-heading;
modifyInCourt(nextX,nextY,getBallRadius());
}
if((*nextY)<0||(*nextY)>getCourtHeight())
{
heading=-heading;
modifyInCourt(nextX,nextY,getBallRadius());
}
}
}
voidrun()
{
doublewidth=getCourtWidth();
doublewidth1=getGoalWidth();
doubley,y1,y2;
y=getCourtCenterY();
y1=y+width1/2;
y2=y-width1/2;
doubleradius=getRadius();
doublerobotx,roboty;
if(getAttack()>0)
{
robotx=radius;
}
else
{
robotx=width-radius;
}
doublenextX,nextY,ball_x,ball_y;
while
(1){
ball_y=getBallY();
if(ball_y>y1)
roboty=y1;
elseif(ball_yroboty=y2;
else
{
roboty=ball_y;
for(inti=0;i<50;i++)
{
next(i,&nextX,&nextY);
if((getAttack()>0&&nextX<=width)||(getAttack()<0&&nextX>=0))
{
roboty=nextY;
break;
}
}
}
setMoveTo(robotx,roboty);
execute();
}
}
五、测试/调试及实验结果分析
调试结果达到了预定的要求。
六、实验结论与体会
经过本次实验之后,我对机器人的程序设计有了一定的了解,并且对这门课程的兴趣越来越大。
希望以后有更多的机会加强机器人的程序设计的学习。
2012年4月24日