ROS节点与OROCOS组件通信--构建组件
来源:互联网 发布:带着空间去民国淘宝 编辑:程序博客网 时间:2024/04/30 14:07
完成ROS、orocos_toolchain、rtt_ros_integration三个部分的安装后,开始构建orocos组件。
一、构建catkin编译包
使用ocl脚本构建orocos的catkin编译包:
cd ~/ws/underlay/srcrosrun ocl orocreate-catkin-pkg hello_world
orocos的catkin编译包结构如下:
my_orocos_pkg├── CMakeLists.txt├── package.xml├── include│ └── my_orocos_pkg└── src
此时直接编译不能通过,因为无法通过orocos_typegen_hearders()生成.so文件,因此需要修改CMakelist.txt文件如下:
...
#orocos_typegen_headers(include/hello_world/hello_world-types.hpp) # ...you may add multiple header files
...完成这个操作后,可以再~/ws/underlay/目录下执行catkin_make编译通过。
二、添加依赖项
1、修改CMakelist.txt文件如下:
...
find_package(OROCOS-RTT QUIET)if (NOT OROCOS-RTT_FOUND) message (FATAL_ERROR "\nCould not find Orocos. Please use the shell command\n 'source orocos_toolchain/env.sh' and then run cmake again.")endif()<span style="color:#ff6666;">find_package(catkin REQUIRED COMPONENTS rtt_ros )</span>
...
orocos_generate_pkg(
<span style="color:#ff6666;"> INCLUDE_DIRS include DEPENDS rtt_ros DEPENDS rtt_std_msgs</span>
)第一步是为catkin编译过程添加依赖组件rtt_ros,以便后续代码中顺利实现桥接功能。
第二步是在生成编译结果时添加依赖项。
2、修改package.xml文件如下:
...
<build_depend>rtt</build_depend> <build_depend>orogen</build_depend><span style="color:#ff6666;"> <build_depend>ocl</build_depend> <build_depend>rtt_ros</build_depend> <build_depend>rtt_roscomm</build_depend> <build_depend>rtt_std_msgs</build_depend></span><pre name="code" class="html">...<run_depend>rtt</run_depend>
<run_depend>ocl</run_depend>
<run_depend>rtt_ros</run_depend>
<run_depend>rtt_roscomm</run_depend>
<run_depend>rtt_std_msgs</run_depend>...
三、建立组件
修改hello_world-component.hpp文件如下:#ifndef OROCOS_HELLO_WORLD_COMPONENT_HPP#define OROCOS_HELLO_WORLD_COMPONENT_HPP
#include <rtt/RTT.hpp>#include <rtt/os/main.h>#include <rtt_roscomm/rtt_rostopic.h>#include <std_msgs/String.h>#include <ros/ros.h>class hello_world : public RTT::TaskContext{ public: hello_world(std::string const& name); bool configureHook(); bool startHook(); void updateHook(); void stopHook(); void cleanupHook(); private: RTT::OutputPort<std_msgs::String> outPort;};#endif修改hello_world-component.cpp文件如下:
#include "hello_world-component.hpp"#include <rtt/Component.hpp>#include <iostream>hello_world::hello_world(std::string const& name) : TaskContext(name){ //initialize ros before create output stream if(!ros::isInitialized()){ int argc = __os_main_argc(); char ** argv = __os_main_argv(); ros::init(argc,argv,"rtt",ros::init_options::AnonymousName); if(ros::master::check()) ros::start(); } //set the priority and period this->setActivity( new RTT::Activity(0, 0.001)); //add output port to hello_world component this->ports()->addPort("out_port", outPort); outPort.createStream(rtt_roscomm::topic("/chatter")); std::cout << "hello_world constructed !" <<std::endl;}bool hello_world::configureHook(){ std::cout << "hello_world configured !" <<std::endl; return true;}bool hello_world::startHook(){ std::cout << "Hello_world started !" <<std::endl; return true;}void hello_world::updateHook(){ //say hello world to ros node every period. std_msgs::String val; val.data = "hello World, orocos."; outPort.write( val ); std::cout << "hello_world executes updateHook !" <<std::endl;}void hello_world::stopHook() { std::cout << "hello_world executes stopping !" <<std::endl;}void hello_world::cleanupHook() { std::cout << "hello_world cleaning up !" <<std::endl;}/* * Using this macro, only one component may live * in one library *and* you may *not* link this library * with another component library. Use * ORO_CREATE_COMPONENT_TYPE() * ORO_LIST_COMPONENT_TYPE(Hello_world) * In case you want to link with another library that * already contains components. * * If you have put your component class * in a namespace, don't forget to add it here too: */ORO_CREATE_COMPONENT(hello_world)在hello_world/src/文件夹下添加orocos组件加载脚本文件hello_world.ops,内容如下:
require("print")import("rtt_std_msgs")import("hello_world")print.ln("Script imported hello_world package:")displayComponentTypes()loadComponent("hello_world_task", "hello_world")print.ln("Script created Hello Component with period: " + hello_world_task.getPeriod() )至此组件构建完毕。
0 0
- ROS节点与OROCOS组件通信--构建组件
- ROS节点与OROCOS组件通信--安装
- 父组件与子组件的通信
- ROS 节点通信
- vue组件与route通信
- vue.js组件与组件之间的通信
- Activity组件与Service组件通过BroadcastReceiver监听器通信
- Vuejs2.0 组件与组件之间的通信
- Vue 父组件与子组件之间的通信
- vue 父组件与子组件相互通信
- Angular4关于组件与组件之间的通信
- react父组件与子组件进行通信
- TinyOS节点间通信相关接口和组件介绍
- 组件通信与广播消息.note
- 多线程与界面组件的通信
- ROS节点与运行
- Vue基础:组件--组件及组件通信
- 构建web组件框架
- Matlab 画图修饰-随机线条和随机颜色
- 求3位数水仙花的2种解法
- 在云上搭建大规模实时数据流处理系统
- 文件下载
- printf 使用%f输出整形变量,为什么为0?
- ROS节点与OROCOS组件通信--构建组件
- 链接相关入门
- linux screen
- 工程指令
- 大小端模式详解
- 01 机器学习算法库Mahout mahout概念和支持的算法库
- linux 运行时找不到so文件
- 第288天(30W+4)(29W+6)
- 帆船驾驶技术的物理学原理