Go Task 直线行走
来源:互联网 发布:浪潮java 编辑:程序博客网 时间:2024/05/22 07:05
首发原创,LEEMANCAFFE
直线往前行走
# include "Aria.h"# include <iostream>using namespace std;ArRobot* robot;int Go(double Speed,double Dist){ cout << "Go Forward :"<< Dist<< " mm at speed "<<Speed <<"mm/s "<< endl; double Dist0 = 0; double dt = 200; while(Dist0 < Dist) { robot->lock(); robot->enableMotors(); if((Dist-Dist0) < 300) { robot->setVel((Dist-Dist0)/300*Speed+5); } else if(Dist0 <300 && !((Dist-Dist0)<300)) { robot->setVel(Dist0/300*Speed + 5); } else { robot->setVel(Speed); } Dist0+=robot->getVel()*dt/1000; cout << "D=\t"<<Dist0 <<"S=\t"<<robot->getVel()<<endl; robot->unlock(); ArUtil::sleep(dt); } robot->lock(); robot->setVel(0); robot->unlock(); return 1;}double sp=200,ds=1000;int main(int argc, char **argv){ int ret; string str; // the connection for Remote Host and Simulator ArTcpConnection con; // the connection through Serial Link to the robot //ArSerialConnection con; //ArGlobalFunctor updateCB(&update); robot = new ArRobot; // mandatory init Aria::init(); // open the connection, if this fails exit if (( ret = con.open()) != 0) { str = con.getOpenMessage(ret); printf("Open failed: %s\n", str.c_str()); Aria::shutdown(); return 1; } // set the device connection on the robot robot->setDeviceConnection(&con); // try to connect, if we fail exit if (!robot->blockingConnect()) { printf("Could not connect to robot... exiting\n"); Aria::shutdown(); return 1; }// add the sonar to the robot ArSonarDevice sonar; robot->addRangeDevice(&sonar); robot->comInt(ArCommands::SONAR, 1); robot->comInt(ArCommands::ENABLE, 1); robot->comInt(ArCommands::SOUNDTOG, 0); // start the robot running, true so that if we lose connection the run stops robot->runAsync(true); Go(sp,ds); robot->lock(); robot->disconnect(); robot->unlock(); // now exit Aria::shutdown(); return 0;}
非指针写法:
# include "Aria.h"# include <iostream>using namespace std;int Go(ArRobot* robot,double Speed,double Dist){ cout << "Go Forward :"<< Dist<< " mm at speed "<<Speed <<"mm/s "<< endl; double Dist0 = 0; double dt = 200; while(Dist0 < Dist) { robot->lock(); robot->enableMotors(); if((Dist-Dist0) < 300) { robot->setVel((Dist-Dist0)/300*Speed+5); } else if(Dist0 <300 && !((Dist-Dist0)<300)) { robot->setVel(Dist0/300*Speed + 5); } else { robot->setVel(Speed); } Dist0+=robot->getVel()*dt/1000; cout << "D=\t"<<Dist0 <<"S=\t"<<robot->getVel()<<endl; robot->unlock(); ArUtil::sleep(dt); } robot->lock(); robot->setVel(0); robot->unlock(); return 1;}double sp=200,ds=1000;int main(int argc, char **argv){ int ret; string str; // the connection for Remote Host and Simulator ArTcpConnection con; // the connection through Serial Link to the robot //ArSerialConnection con; //ArGlobalFunctor updateCB(&update); ArRobot robot; // mandatory init Aria::init(); // open the connection, if this fails exit if (( ret = con.open()) != 0) { str = con.getOpenMessage(ret); printf("Open failed: %s\n", str.c_str()); Aria::shutdown(); return 1; } // set the device connection on the robot robot.setDeviceConnection(&con); // try to connect, if we fail exit if (!robot.blockingConnect()) { printf("Could not connect to robot... exiting\n"); Aria::shutdown(); return 1; }// add the sonar to the robot ArSonarDevice sonar; robot.addRangeDevice(&sonar); robot.comInt(ArCommands::SONAR, 1); robot.comInt(ArCommands::ENABLE, 1); robot.comInt(ArCommands::SOUNDTOG, 0); // start the robot running, true so that if we lose connection the run stops robot.runAsync(true); Go(&robot,sp,ds); robot.lock(); robot.disconnect(); robot.unlock(); // now exit Aria::shutdown(); return 0;}
阅读全文
0 0
- Go Task 直线行走
- Go task
- 【行走】
- 行走
- 行走
- 行走
- 行走
- 谷歌的alpha go 战胜李世石与谷歌双足行走机器人
- TASK
- Task
- Task
- TASK
- task
- Task
- task
- Task,
- task
- Task
- 简单 12 步理解 Python 装饰器
- java 实现文件复制,二种方法.
- 在这家不加班的 IT 公司里,我们是这样加班的
- cmd下常用指令
- 数据库概述以及基本概念
- Go Task 直线行走
- 卡尔曼滤波的一些想法
- * 先往文件保存10个花类(包括花编号,花名称,花龄)对象,再取出来 * 去掉花名重复的花对象,再按照花龄升序排列
- import static和import的区别
- 【noip2013】花匠
- hdu 2643 Rank(第二类斯特林数)
- Downloader Middlewares
- ubuntu安装(win10双系统)+cuda+cudnn+tensorflow安装
- DrawerLayout的使用