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

做网站的linux程序代码公司做网站推广

做网站的linux程序代码,公司做网站推广,链接点开网页表白的网站怎么做的,一级 爰做片免费网站【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing 163.com】 前面我们只是编写了一个publisher节点,以及一个subscribe节点。有了这两个节点,它们之间就可以通信了。在实际生产中&#…

【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】

        前面我们只是编写了一个publisher节点,以及一个subscribe节点。有了这两个节点,它们之间就可以通信了。在实际生产中,我们除了简单的通信之外,要传递的数据可能还有很多。这个时候,我们就要构建一个消息体。这个消息体可以是各种脚本,但需要同时能被publisher和subscribe访问到。幸好,ros给我们提供了这样的一种形式。

1、构建消息体

        在package下面创建一个msg文件夹。文件夹中保存一个Student.msg文件,它的内容如下所示,

string name
float64 height
float64 weight

        这个文件其实只是一个脚本。通过在workspace顶层输入catkin_make,就可以生成对应的头文件Student.h。注意,头文件保存的位置位于./devel/include/beginner_tutorials/Student.h。编译之前也要修改下CMakelists.txt文件,如下面2所示。

 2、修改CMakelists.txt文件


cmake_minimum_required(VERSION 2.8.3)
project(beginner_tutorials)## Find catkin and any catkin packages
find_package(catkin REQUIRED COMPONENTS message_generation roscpp rospy std_msgs genmsg)add_message_files(FILES Student.msg)## Declare ROS messages and services
#add_message_files(FILES Num.msg)
#add_service_files(FILES AddTwoInts.srv)## Generate added messages and services
generate_messages(DEPENDENCIES std_msgs)## Declare a catkin package
catkin_package()## Build talker and listener
include_directories(include ${catkin_INCLUDE_DIRS})add_executable(talker src/talker.cpp)
target_link_libraries(talker ${catkin_LIBRARIES})
add_dependencies(talker beginner_tutorials_generate_messages_cpp)add_executable(listener src/listener.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})
add_dependencies(listener beginner_tutorials_generate_messages_cpp)

3、重新构建talker.cpp文件


#include "ros/ros.h"
#include "beginner_tutorials/Student.h"
#include <cstdlib>using namespace std;int main(int argc, char* argv[])
{ros::init(argc, argv, "node_MyMsgPub");if(argc!=4){cout << "Error command parameter!\n" \"Please run command eg:\n" \"rosrun begin_tutorials talker LiLei 180 160" << endl;return 1;}ros::NodeHandle nh;ros::Publisher MyMsgPub = nh.advertise<beginner_tutorials::Student>("MyMsg", 100);beginner_tutorials::Student sdtMsg;sdtMsg.name = argv[1];sdtMsg.height = atof(argv[2]);sdtMsg.weight = atof(argv[3]);ros::Rate rate(10);while(ros::ok()){MyMsgPub.publish(sdtMsg);rate.sleep();}return 0;
}

        代码大部分和之前差不多,只要注意beginner_tutorials::Student这个结构体即可。

4、重新构建listener.cpp文件

#include "ros/ros.h"
#include "beginner_tutorials/Student.h"void MyMsgCallback(const beginner_tutorials::Student& sdtInfo)
{ROS_INFO("Thestudent information is:\n""name:%s--height:%f--weight:%f\n",sdtInfo.name.c_str(),sdtInfo.height,sdtInfo.weight);
}int main(int argc, char* argv[])
{ros::init(argc, argv, "node_MyMsgSub");ros::NodeHandle nh;ros::Subscriber MyMsgSub = nh.subscribe("MyMsg", 1000, &MyMsgCallback);ros::spin();return 0;
}

        和talker.cpp一样,代码中只需要关注下beginner_tutorials::Student这个结构体就行。

5、顶层编译

        cd到workspace的顶层,直接输入catkin_make即可。

6、准备运行talker和listener节点

        在运行talker和listener节点之前,有两件事情要做。第一步,打开roscore;第二步,source ./dev/setup.sh文件。最后,分别打开talker和listenner即可。

rosrun beginner_tutorials talker LiLei 180 160
rosrun beginner_tutorials listener

        没什么意外的化,你会看到这样的打印。如果能看到这些打印,基本上说明我们已经学会使用了ros的消息功能。

[ INFO] [1695351213.590856004]: Thestudent information is:
name:LiLei--height:180.000000--weight:160.000000[ INFO] [1695351213.692688848]: Thestudent information is:
name:LiLei--height:180.000000--weight:160.000000[ INFO] [1695351213.791460924]: Thestudent information is:
name:LiLei--height:180.000000--weight:160.000000[ INFO] [1695351213.891075380]: Thestudent information is:
name:LiLei--height:180.000000--weight:160.000000[ INFO] [1695351213.990753652]: Thestudent information is:
name:LiLei--height:180.000000--weight:160.000000[ INFO] [1695351214.090438037]: Thestudent information is:
name:LiLei--height:180.000000--weight:160.000000[ INFO] [1695351214.190497066]: Thestudent information is:
name:LiLei--height:180.000000--weight:160.000000[ INFO] [1695351214.291007141]: Thestudent information is:
name:LiLei--height:180.000000--weight:160.000000[ INFO] [1695351214.390375087]: Thestudent information is:
name:LiLei--height:180.000000--weight:160.000000[ INFO] [1695351214.490385779]: Thestudent information is:
name:LiLei--height:180.000000--weight:160.000000

http://www.sczhlp.com/news/20304/

相关文章:

  • 专业做轴承的网站网页设计论文
  • php语言的网站建设全网营销式网站
  • DW做的网站加载慢旅游最新资讯
  • 网站视频做参考文献东莞网站推广优化公司
  • 网站建设技术的发展平台推广策略都有哪些
  • phpcms 友情链接 网站名称字数百度sem竞价推广电子书
  • 个人网站备案需要什么资料网络推广怎么做
  • 网页设计好看的网站开发网站需要多少钱
  • 手机网站什么意思自助优化排名工具
  • 西安有哪些网站网络营销有什么特点
  • 做破解软件网站赚广告费东莞百度快速优化排名
  • 石岩做网站东莞寮步最新通知
  • 房地产公司网站建设报价方案百度广告联盟点击一次多少钱
  • 做网站买服务器百度指数在线查询小程序
  • 全域seo杭州seo托管公司推荐
  • 西安做网站建设百度关键词推广怎么收费
  • 做外贸独立网站怎么样在线看seo网站
  • wordpress step2 500seo排名优化的网站
  • 域名建议网站经典软文推广案例
  • 自己做的网站怎么排名百度收录技术
  • 张家港做网站的公司申泽seo
  • 环保网站建设说明seo网页优化平台
  • 网站内怎么做链接东莞快速优化排名
  • 做静态网站用什么软件品牌营销策划方案怎么做
  • 上海技术公司做网站百度搜索关键词
  • 深圳app客户端做网站免费网站安全软件大全
  • 政府网站改版建设汇报网络推广的方法你知道几个?
  • king cms网站建设宁波seo服务推广
  • 怎么给网站做短信百度如何推广网站
  • 付费wordpress上海seo推广公司