我自己安装T265的ROS功能包

讲道理按照它的说法我这样应该直接同时装了SDK和ROS功能包。

https://github.com/IntelRealSense/realsense-ros

我直接运行上面命令会显示下面,这莫非就是他们没用采用二进制安装的原因么,因为实际装不成.....还是自己亲自试一下感受深刻。不然你确实不知道这么简单的方法为什么没看见有人用。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在同一个ROS2节点中含多个订阅者和发布者的多线程功能,可以使用ROS2提供的多线程库来实现。 具体步骤如下: 1. 创建一个ROS2节点,并在其中创建多个订阅者和发布者。 2. 使用C语言的多线程库,如pthread,创建多个线程。 3. 在每个线程中,分别订阅和发布相应的消息。 4. 在每个线程中,使用ROS2提供的rcl_wait函数来等待消息到达。 5. 在每个线程中,使用ROS2提供的rcl_take函数来获取消息并处理。 6. 在每个线程中,使用ROS2提供的rcl_publish函数来发布消息。 7. 确保在每个线程中使用适当的同步机制,以避免竞争条件和死锁等问题。 8. 在程序结束时,使用ROS2提供的rcl_shutdown函数来关闭节点并释放资源。 以下是一个简单的示例代码,演示了如何在同一个ROS2节点中使用多线程处理多个订阅者和发布者: ```c #include <stdio.h> #include <stdlib.h> #include <pthread.h> #include "rcl/rcl.h" #include "std_msgs/msg/int32.h" rcl_node_t node; rcl_subscription_t sub1, sub2; rcl_publisher_t pub1, pub2; void* thread1(void* arg) { rcl_wait_set_t wait_set; rcl_ret_t ret; std_msgs__msg__Int32 msg; rcl_wait_set_init(&wait_set, 2, 0, 0, 0, 0, rcl_get_default_allocator()); while(1) { rcl_wait(&wait_set, RCL_MS_TO_NS(10)); if(rcl_wait_set_is_ready(&wait_set, &sub1)) { ret = rcl_take(&sub1, &msg, NULL, NULL); if(ret == RCL_RET_OK) { printf("Thread 1 received message: %d\n", msg.data); msg.data *= 2; rcl_publish(&pub1, &msg, NULL); } } if(rcl_wait_set_is_ready(&wait_set, &sub2)) { ret = rcl_take(&sub2, &msg, NULL, NULL); if(ret == RCL_RET_OK) { printf("Thread 1 received message: %d\n", msg.data); msg.data *= 2; rcl_publish(&pub2, &msg, NULL); } } } rcl_wait_set_fini(&wait_set); return NULL; } void* thread2(void* arg) { rcl_wait_set_t wait_set; rcl_ret_t ret; std_msgs__msg__Int32 msg; rcl_wait_set_init(&wait_set, 2, 0, 0, 0, 0, rcl_get_default_allocator()); while(1) { rcl_wait(&wait_set, RCL_MS_TO_NS(10)); if(rcl_wait_set_is_ready(&wait_set, &sub1)) { ret = rcl_take(&sub1, &msg, NULL, NULL); if(ret == RCL_RET_OK) { printf("Thread 2 received message: %d\n", msg.data); msg.data *= 3; rcl_publish(&pub1, &msg, NULL); } } if(rcl_wait_set_is_ready(&wait_set, &sub2)) { ret = rcl_take(&sub2, &msg, NULL, NULL); if(ret == RCL_RET_OK) { printf("Thread 2 received message: %d\n", msg.data); msg.data *= 3; rcl_publish(&pub2, &msg, NULL); } } } rcl_wait_set_fini(&wait_set); return NULL; } int main(int argc, char** argv) { rcl_init_options_t options = rcl_get_zero_initialized_init_options(); rcl_init_options_init(&options, rcl_get_default_allocator()); rcl_init(argc, argv, &options, &node); rcl_subscription_init(&sub1, &node, ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32), "topic1", NULL); rcl_subscription_init(&sub2, &node, ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32), "topic2", NULL); rcl_publisher_init(&pub1, &node, ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32), "output1", NULL); rcl_publisher_init(&pub2, &node, ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32), "output2", NULL); pthread_t t1, t2; pthread_create(&t1, NULL, thread1, NULL); pthread_create(&t2, NULL, thread2, NULL); pthread_join(t1, NULL); pthread_join(t2, NULL); rcl_subscription_fini(&sub1, &node); rcl_subscription_fini(&sub2, &node); rcl_publisher_fini(&pub1, &node); rcl_publisher_fini(&pub2, &node); rcl_node_fini(&node); rcl_shutdown(); return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值