机器人避障.pdf
《机器人避障.pdf》由会员分享,可在线阅读,更多相关《机器人避障.pdf(10页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、机器人避障1/10 源程序如下:/*Template to access ARIA(ActivMedia Robotics Interface for Applications)using Microsoft Visual C+,console Projects.*/#include Aria.h#include#include#include#include#include#include#include usingnamespace std;/the robot ArRobot*robot;ArSonarDevice sonar;/sonar,must be added to the ro
2、bot ArSick sick;/the laser int step=0;double d0,d1,d3,d2,d4,d15;double th,r,PI=3.1415926;double minimum=0;/sonar sensor offset positions with respect to robot local coordinate frame double robotSonarX8=69,114,148,166,166,148,114,69;double robotSonarY8=136,119,78,27,-27,-78,-119,-136;double robotSona
3、rTh8=90.0,50.0,30.0,10.0,-10.0,-30.0,-50.0,-90.0;double laserData2180;double sonarData516;/last 5 sets of sonar readings double posData5;/odometry readings long frameCount=-1;/how many iterations of the sensor grabbing functions have been run/*Files for logging position and sensor data*/ofstream pos
4、itionData(positionvals.txt);ofstream sonarVals(sonarvals.txt);ofstream globalFrame(globalFrame.txt);机器人避障2/10/*Function Definitions*/void grabNewPositionData(void);void logPositionData(void);void grabNewSonarData(void);void logRawSonarData(void);void MapToGlobalFrame(void);bool flag=true;bool weWant
5、ToTurnTheRobot=true;bool decideWhichDirectionToTurn=true;bool turnRobotRight=false;bool turnRobotLeft=false;void update(void)/Your Code Here grabNewSonarData();grabNewPositionData();logPositionData();logRawSonarData();/grabNewLaserData();MapToGlobalFrame();int sequence=0,1,2,3,4,5,6,7;int leftValue=
6、200,200,200,200,-50,0,40,150;int rightValue=150,40,0,-50,200,200,200,200;int minVal=9999;/int intriger=0,0,0,0,0,0;int minSonar=0;for(int i=0;i8;i+)if(sonarData0sequencei300)&(sonarData04300)&(sonarData02250)&(sonarData05250)&(sonarData01200)&(sonarData06200)&(sonarData00150)&(sonarData07150)&(flag)
7、robot-setVel2(leftValueminSonar,rightValueminSonar);/reset which direction to turn(turn either left or right)decideWhichDirectionToTurn=true;/we do not know which direction to turn yet turnRobotRight=false;turnRobotLeft=false;else/some obstacles are very close to the robot /-2-/decide which directio
8、n to turn the robot if(decideWhichDirectionToTurn)if(sonarData02250)|(sonarData01200)|(sonarData00150)/is the nearest obstacle on the left of the robot turnRobotRight=true;/yes the nearest obstable is on the left of the robot(turn right)elseif(sonarData04300)|(sonarData03stop();/first stop the robot
9、 if(turnRobotRight)/we turn right robot-setDeltaHeading(-20);if(turnRobotLeft)/or we turn left robot-setDeltaHeading(20);flag=false;weWantToTurnTheRobot=false;/-/-4-elseif(robot-isHeadingDone()/check to see if the robot has finished turning flag=true;weWantToTurnTheRobot=true;/-/end update void MapT
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 机器人
限制150内