当前位置: 首页 > news >正文

专业网站开发技术中国做国外的网站

专业网站开发技术,中国做国外的网站,网站建设网站制作有限,有没有免费建站文章目录 一、话题编程二、服务编程三、动作编程 接上篇#xff0c;继续学习ROS通信编程基础 一、话题编程 步骤#xff1a; 创建发布者 初始化ROS节点向ROS Master注册节点信息#xff0c;包括发布的话题名和话题中的消息类型按照一定频率循环发布消息 创建订阅者 初始化… 文章目录 一、话题编程二、服务编程三、动作编程 接上篇继续学习ROS通信编程基础 一、话题编程 步骤 创建发布者 初始化ROS节点向ROS Master注册节点信息包括发布的话题名和话题中的消息类型按照一定频率循环发布消息 创建订阅者 初始化ROS节点订阅需要的话题循环等待话题消息接受到消息后进行回调函数回调函数中完成消息处理 添加编译选项 设置需要编译的代码和生成的可执行文件设置链接库设置依赖 运行可执行程序 talker.cpp #includesstream #includeros/ros.h #includestd_msgs/String.h int main(int argc,char **argv) {//ROS节点初始化ros::init(argc,argv,talker);//创建节点句柄ros::NodeHandle n;//创建一个Publisher发布名为chatter的topic消息类型为std_msgs::Stringros::Publisher chatter_pubn.advertisestd_msgs::String(chatter,1000);//设置循环的频率ros::Rate loop_rate(10);int count0;while(ros::ok()){//初始化std_msgs::String类型的消息std_msgs::String msg;std::stringstream ss;sshello worldcount;msg.datass.str();//发布消息ROS_INFO(%s,msg.data.c_str());chatter_pub.publish(msg);//循环等待回调函数ros::spinOnce();//接受循环频率延时loop_rate.sleep();count;}return 0; } listener.cpp #includeros/ros.h #includestd_msgs/String.h //接收到订阅的消息会进入消息的回调函数 void chatterCallback(const std_msgs::String::ConstPtr msg) {//将接收到的消息打印处理ROS_INFO(I heard:{%s},msg-data.c_str()); } int main(int argc,char **argv) {//初始化ROS节点ros::init(argc,argv,listener);//创建节点句柄ros::NodeHandle n;//创建一个Subscriber订阅名为chatter的topic注册回调函数chatterCallbackros::Subscriber subn.subscribe(chatter,1000,chatterCallback);//循环等待回调函数ros::spin();return 0; } 在CMakeLists.txt末尾添加编译选项 add_executable(talker src/talker.cpp) target_link_libraries(talker ${catkin_LIBRARIES})add_executable(listener src/listener.cpp) target_link_libraries(listener ${catkin_LIBRARIES}) 编译 cd catkin_ws catkin_make运行程序 # 以下是对于Ubantu 16.04的操作其他版本的也许操作会简洁很多 roscore #打开新终端 cd ~/catkin_ws #下面这一步是为了保证rosrun命令能够找到相应的功能包有可以省去这一步骤的方法各位可以自行查找 source ~/catkin_ws/devel/setup.bash rosrun learning_communication talker #打开新终端 cd ~/catkin_ws source ~/catkin_ws/devel/setup.bash rosrun learning_communication listener如图发送了hello world的同时接收了hello world。 二、服务编程 定义服务请求与应答的方式 定义srv文件 mkdir ~/catkin_ws/src/learning_communication/srvsudo nano AddTwoInts.srvAddTwoInts.srvint64 a int64 b --- int64 sum用gedit打开package.xml在里面添加功能包依赖build_dependmessage_generation/build_depend exec_dependmessage_runtime/exec_depend在CMakeLists.txt添加编译选项 步骤 创建服务器 初始化ROS节点创建Serve实例循环等待服务请求进入回调函数在回调函数中完成服务功能的处理并反馈应答数据 创建客户端 初始化ROS节点创建一个Client实例发布服务请求数据等待Serve处理之后的应答结果 添加编译选项 设置需要编译的代码和生成的可执行文件设置链接库设置依赖 运行可执行程序 server.cpp #includeros/ros.h #includelearning_communication/AddTwoInts.h //service回调函数输入参数req输出参数res bool add(learning_communication::AddTwoInts::Request req,learning_communication::AddTwoInts::Response res) {//将输入的参数中的请求数据相加结果放到应答变量中res.sumreq.areq.b;ROS_INFO(request: x%1d,y%1d,(long int)req.a,(long int)req.b);ROS_INFO(sending back response:[%1d],(long int)res.sum);return true; } int main(int argc,char **argv) {//ROS节点初始化ros::init(argc,argv,add_two_ints_server);//创建节点句柄ros::NodeHandle n;//创建一个名为add_two_ints的server,注册回调函数add()ros::ServiceServer servicen.advertiseService(add_two_ints,add);//循环等待回调函数ROS_INFO(Ready to add two ints.);ros::spin();return 0; } client.cpp #includecstdlib #includeros/ros.h #includelearning_communication/AddTwoInts.h int main(int argc,char **argv) {//ROS节点初始化ros::init(argc,argv,add_two_ints_client);//从终端命令行获取两个加数if(argc!3){ROS_INFO(usage:add_two_ints_client X Y);return 1;}//创建节点句柄ros::NodeHandle n;//创建一个client请求add_two_ints_service//service消息类型是learning_communication::AddTwoIntsros::ServiceClient clientn.serviceClientlearning_communication::AddTwoInts(add_two_ints);//创建learning_communication::AddTwoInts类型的service消息learning_communication::AddTwoInts srv;srv.request.aatoll(argv[1]);srv.request.batoll(argv[2]);//发布service请求等待加法运算的应答请求if(client.call(srv)){ROS_INFO(sum: %1d,(long int)srv.response.sum);}else{ROS_INFO(Failed to call service add_two_ints);return 1;}return 0; } 关于编译时一直出现这样的报错注意看是不是有些比如这个符号“_”没打。 添加编译设置 编译通过 输入指令 roscore #打开新终端 source ~/catkin_ws/devel/setup.bash rosrun learning_communication server #打开新终端 source ~/catkin_ws/devel/setup.bash rosrun learning_communication client 11 12 三、动作编程 动作是一种基于ROS消息实现的问答通信机制它包含连续反馈可以在任务过程中止运行。 动作Action的接口 练习ROS动作编程 客户端发送一个运动坐标模拟机器人运动到目标位置的过程。包括服务端和客户端的代码实现要求带有实时位置反馈。 创建工作区间 #创建功能包 cd catkin_ws/src/ catkin_create_pkg learn_action std_msgs rospy roscpp #编译功能包 cd ~/catkin_ws catkin_make source ~/catkin_ws/devel/setup.bash 创建action文件夹并在里面创建TurtleMove.action文件 # Define the goal float64 turtle_target_x # Specify Turtles target position float64 turtle_target_y float64 turtle_target_theta --- # Define the result float64 turtle_final_x float64 turtle_final_y float64 turtle_final_theta --- # Define a feedback message float64 present_turtle_x float64 present_turtle_y float64 present_turtle_theta 在learn_action的src文件夹下创建TurtleMove_server.cpp文件和TurtleMove_client.cpp文件 TurtleMove_server.cpp /*    此程序通过通过动作编程实现由client发布一个目标位置    然后控制Turtle运动到目标位置的过程 */ #include ros/ros.h #include actionlib/server/simple_action_server.h #include learn_action/TurtleMoveAction.h #include turtlesim/Pose.h #include turtlesim/Spawn.h #include geometry_msgs/Twist.h typedef actionlib::SimpleActionServerlearn_action::TurtleMoveAction Server; struct Myturtle { float x; float y; float theta; }turtle_original_pose,turtle_target_pose; ros::Publisher turtle_vel; void posecallback(const turtlesim::PoseConstPtr msg) { ROS_INFO(Turtle1_position:(%f,%f,%f),msg-x,msg-y,msg-theta); turtle_original_pose.xmsg-x; turtle_original_pose.ymsg-y; turtle_original_pose.thetamsg-theta; } // 收到action的goal后调用该回调函数 void execute(const learn_action::TurtleMoveGoalConstPtr goal, Server* as) { learn_action::TurtleMoveFeedback feedback; ROS_INFO(TurtleMove is working.); turtle_target_pose.xgoal-turtle_target_x; turtle_target_pose.ygoal-turtle_target_y; turtle_target_pose.thetagoal-turtle_target_theta; geometry_msgs::Twist vel_msgs; float break_flag; while(1) { ros::Rate r(10); vel_msgs.angular.z 4.0 * (atan2(turtle_target_pose.y-turtle_original_pose.y, turtle_target_pose.x-turtle_original_pose.x)-turtle_original_pose.theta); vel_msgs.linear.x 0.5 * sqrt(pow(turtle_target_pose.x-turtle_original_pose.x, 2) pow(turtle_target_pose.y-turtle_original_pose.y, 2)); break_flagsqrt(pow(turtle_target_pose.x-turtle_original_pose.x, 2) pow(turtle_target_pose.y-turtle_original_pose.y, 2)); turtle_vel.publish(vel_msgs);feedback.present_turtle_xturtle_original_pose.x; feedback.present_turtle_yturtle_original_pose.y; feedback.present_turtle_thetaturtle_original_pose.theta; as-publishFeedback(feedback); ROS_INFO(break_flag%f,break_flag); if(break_flag0.1) break; r.sleep(); } // 当action完成后向客户端返回结果 ROS_INFO(TurtleMove is finished.); as-setSucceeded(); } int main(int argc, char** argv) { ros::init(argc, argv, TurtleMove_server); ros::NodeHandle n,turtle_node; ros::Subscriber sub turtle_node.subscribe(turtle1/pose,10,posecallback);//订阅小乌龟的位置信息 turtle_vel turtle_node.advertisegeometry_msgs::Twist(turtle1/cmd_vel,10);//发布控制小乌龟运动的速度 // 定义一个服务器 Server server(n, TurtleMove, boost::bind(execute, _1, server), false); // 服务器开始运行 server.start(); ROS_INFO(server has started.); ros::spin(); return 0; } TurtleMove_client.cpp #include actionlib/client/simple_action_client.h #include learn_action/TurtleMoveAction.h #include turtlesim/Pose.h #include turtlesim/Spawn.h #include geometry_msgs/Twist.h typedef actionlib::SimpleActionClientlearn_action::TurtleMoveAction Client; struct Myturtle { float x; float y; float theta; }turtle_present_pose; // 当action完成后会调用该回调函数一次 void doneCb(const actionlib::SimpleClientGoalState state, const learn_action::TurtleMoveResultConstPtr result) { ROS_INFO(Yay! The TurtleMove is finished!); ros::shutdown(); } // 当action激活后会调用该回调函数一次 void activeCb() { ROS_INFO(Goal just went active); } // 收到feedback后调用该回调函数 void feedbackCb(const learn_action::TurtleMoveFeedbackConstPtr feedback) { ROS_INFO( present_pose : %f %f %f, feedback-present_turtle_x, feedback-present_turtle_y,feedback-present_turtle_theta); } int main(int argc, char** argv) { ros::init(argc, argv, TurtleMove_client); // 定义一个客户端 Client client(TurtleMove, true); // 等待服务器端 ROS_INFO(Waiting for action server to start.); client.waitForServer(); ROS_INFO(Action server started, sending goal.); // 创建一个action的goal learn_action::TurtleMoveGoal goal; goal.turtle_target_x 1; goal.turtle_target_y 1; goal.turtle_target_theta 0; // 发送action的goal给服务器端并且设置回调函数 client.sendGoal(goal, doneCb, activeCb, feedbackCb); ros::spin(); return 0; } 在package.xml里面添加依赖 build_dependmessage_generation/build_depend build_dependactionlib/build_depend build_dependactionlib_msgs/build_depend exec_dependmessage_runtime/exec_depend exec_dependactionlib/exec_depend exec_dependactionlib_msgs/exec_depend 添加完就是这样 修改learn_action里面的CMakeLists.txt添加代码 添加编译选项 add_executable(TurtleMove_client src/TurtleMove_client.cpp) target_link_libraries(TurtleMove_client ${catkin_LIBRARIES}) add_dependencies(TurtleMove_client ${PROJECT_NAME}_gencpp) add_executable(TurtleMove_server src/TurtleMove_server.cpp) target_link_libraries(TurtleMove_server ${catkin_LIBRARIES}) add_dependencies(TurtleMove_server ${PROJECT_NAME}_gencpp) 编译 roscore 开一个新终端窗口 source ./devel/setup.bash rosrun turtlesim turtlesim.node 新终端 source ./devel/setup.bash rosrun learn_action TurtleMove_server 新终端 source ./devel/setup.bash rosrun learn_action TurtleMove_client 运行结果如下
文章转载自:
http://www.morning.rfljb.cn.gov.cn.rfljb.cn
http://www.morning.qmncj.cn.gov.cn.qmncj.cn
http://www.morning.wplbs.cn.gov.cn.wplbs.cn
http://www.morning.zfgh.cn.gov.cn.zfgh.cn
http://www.morning.wjqbr.cn.gov.cn.wjqbr.cn
http://www.morning.tymwx.cn.gov.cn.tymwx.cn
http://www.morning.bhrbr.cn.gov.cn.bhrbr.cn
http://www.morning.dsmwy.cn.gov.cn.dsmwy.cn
http://www.morning.kwwkm.cn.gov.cn.kwwkm.cn
http://www.morning.mkfr.cn.gov.cn.mkfr.cn
http://www.morning.lgznf.cn.gov.cn.lgznf.cn
http://www.morning.bfrsr.cn.gov.cn.bfrsr.cn
http://www.morning.yjtnc.cn.gov.cn.yjtnc.cn
http://www.morning.wwjft.cn.gov.cn.wwjft.cn
http://www.morning.pqnps.cn.gov.cn.pqnps.cn
http://www.morning.sgjw.cn.gov.cn.sgjw.cn
http://www.morning.ddxjr.cn.gov.cn.ddxjr.cn
http://www.morning.nfqyk.cn.gov.cn.nfqyk.cn
http://www.morning.phxdc.cn.gov.cn.phxdc.cn
http://www.morning.xtrnx.cn.gov.cn.xtrnx.cn
http://www.morning.wfhnz.cn.gov.cn.wfhnz.cn
http://www.morning.xqnzn.cn.gov.cn.xqnzn.cn
http://www.morning.cpgdy.cn.gov.cn.cpgdy.cn
http://www.morning.knpmj.cn.gov.cn.knpmj.cn
http://www.morning.rbhcx.cn.gov.cn.rbhcx.cn
http://www.morning.mbdbe.cn.gov.cn.mbdbe.cn
http://www.morning.sqnrz.cn.gov.cn.sqnrz.cn
http://www.morning.ggrzk.cn.gov.cn.ggrzk.cn
http://www.morning.yfmlj.cn.gov.cn.yfmlj.cn
http://www.morning.xtdtt.cn.gov.cn.xtdtt.cn
http://www.morning.heleyo.com.gov.cn.heleyo.com
http://www.morning.qhrlb.cn.gov.cn.qhrlb.cn
http://www.morning.dyfmh.cn.gov.cn.dyfmh.cn
http://www.morning.gzzncl.cn.gov.cn.gzzncl.cn
http://www.morning.drgmr.cn.gov.cn.drgmr.cn
http://www.morning.yfmlj.cn.gov.cn.yfmlj.cn
http://www.morning.mdtfh.cn.gov.cn.mdtfh.cn
http://www.morning.lbpqk.cn.gov.cn.lbpqk.cn
http://www.morning.mnsts.cn.gov.cn.mnsts.cn
http://www.morning.fmjzl.cn.gov.cn.fmjzl.cn
http://www.morning.sfnjr.cn.gov.cn.sfnjr.cn
http://www.morning.qfbzj.cn.gov.cn.qfbzj.cn
http://www.morning.rnribht.cn.gov.cn.rnribht.cn
http://www.morning.qphgp.cn.gov.cn.qphgp.cn
http://www.morning.fxzw.cn.gov.cn.fxzw.cn
http://www.morning.xmjzn.cn.gov.cn.xmjzn.cn
http://www.morning.nmnhs.cn.gov.cn.nmnhs.cn
http://www.morning.bftqc.cn.gov.cn.bftqc.cn
http://www.morning.ggcjf.cn.gov.cn.ggcjf.cn
http://www.morning.ntzfj.cn.gov.cn.ntzfj.cn
http://www.morning.khfk.cn.gov.cn.khfk.cn
http://www.morning.mxtjl.cn.gov.cn.mxtjl.cn
http://www.morning.mrbmc.cn.gov.cn.mrbmc.cn
http://www.morning.qgfkn.cn.gov.cn.qgfkn.cn
http://www.morning.hqxyt.cn.gov.cn.hqxyt.cn
http://www.morning.wrtpk.cn.gov.cn.wrtpk.cn
http://www.morning.tbzcl.cn.gov.cn.tbzcl.cn
http://www.morning.chrbp.cn.gov.cn.chrbp.cn
http://www.morning.nllst.cn.gov.cn.nllst.cn
http://www.morning.cpqqf.cn.gov.cn.cpqqf.cn
http://www.morning.kmqjx.cn.gov.cn.kmqjx.cn
http://www.morning.zffps.cn.gov.cn.zffps.cn
http://www.morning.dbcw.cn.gov.cn.dbcw.cn
http://www.morning.tlrxp.cn.gov.cn.tlrxp.cn
http://www.morning.nlkm.cn.gov.cn.nlkm.cn
http://www.morning.dddcfr.cn.gov.cn.dddcfr.cn
http://www.morning.klyyd.cn.gov.cn.klyyd.cn
http://www.morning.sgbsr.cn.gov.cn.sgbsr.cn
http://www.morning.rlksq.cn.gov.cn.rlksq.cn
http://www.morning.jbkcs.cn.gov.cn.jbkcs.cn
http://www.morning.xbptx.cn.gov.cn.xbptx.cn
http://www.morning.zwfgh.cn.gov.cn.zwfgh.cn
http://www.morning.qrwjb.cn.gov.cn.qrwjb.cn
http://www.morning.xbkcr.cn.gov.cn.xbkcr.cn
http://www.morning.nrjr.cn.gov.cn.nrjr.cn
http://www.morning.knpbr.cn.gov.cn.knpbr.cn
http://www.morning.tjndb.cn.gov.cn.tjndb.cn
http://www.morning.mtjwp.cn.gov.cn.mtjwp.cn
http://www.morning.lddpj.cn.gov.cn.lddpj.cn
http://www.morning.wddmr.cn.gov.cn.wddmr.cn
http://www.tj-hxxt.cn/news/269719.html

相关文章:

  • 深圳品牌网站制作平台书画网站的建设目标
  • 建站系统哪个比较好最近韩国电影片在线观看
  • win2012 iis添加网站寻找网站开发
  • 厦门做医院网站设计的公司网站开发思路怎么写
  • 网站建设广告素材wordpress最炫主题
  • 网站的安全性建设温州谷歌seo
  • 网站开发前期准备工作英文公司网站模板
  • 有做美食的视频网站么七牛 wordpress 节省空间
  • 女装商城网站建设制作游戏需要多少钱
  • 河南做网站高手排名邮箱注册163免费注册入口
  • 自己网站做电子签章有效么东莞seo网络优化
  • 网站推广全过程wordpress 网站统计插件
  • 织梦网站怎么上传建设机械网站平台
  • WordPress搭建流媒体网站邢台市第三医院
  • 网站建设发展网络公司名
  • 服务好的公司网站建设与维护数字化平台建设
  • 保定网站制作企业广告推广费用
  • 怎么自己开网站江门免费网站建站模板
  • 如何网站建设网页网站企业备案需要哪些
  • 襄州区住房和城乡建设局网站房地产开发网站建设
  • 锡林浩特网站建设微信开发阿里云如何安装wordpress
  • 科技加盟网站建设昆明北京网站建设
  • 如何查询网站的建设商网上注册商标如何注册
  • 免费网站访客qq统计系统网站设计原则的第三要素
  • 有网站建设费科目吗重庆梁平网站建设哪家好
  • 做海鲜代理在什么网站北京建站模板企业
  • 网站做推广赚钱项目南宁网站建设哪家
  • 资源网站推荐WordPress文章里图片打水印
  • 北京网站建设 时创设计网络营销十大成功案例
  • 网站添加文章微信赚钱小程序有哪些