Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chongqinghuang committed Jul 25, 2022
1 parent d8e04d5 commit 308ffbf
Show file tree
Hide file tree
Showing 33 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ros2_21_tutorials

ros2_21_ws/install

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@
* @Company(School): UCAS
* @Email: 1756260160@qq.com
* @Date: 2022-07-25 11:32:57
* @LastEditTime: 2022-07-25 14:39:57
* @LastEditTime: 2022-07-25 15:37:41
* @FilePath: /ros2_python/README.md
-->
# ros2_python
Python implementation of ROS2 | python实现ros2

@[双愚](https://github.com/HuangCongQing) , 若fork或star请注明来源

```
# 新的优化后的编译器
sudo apt install python3-colcon-ros
colcon build
source install/local_setup.sh
```

## Tutorials
* [订阅发布](tutorials_ws/src/01_publisher_and_subscriber.py)

Expand All @@ -23,4 +31,5 @@ video: https://www.bilibili.com/video/BV16B4y1Q7jQ
code: https://github.com/guyuehome/ros2_21_tutorials


1. [learning_topic](ros2_21_ws/learning_topic)
1. [learning_tf](ros2_21_ws/learning_tf)
File renamed without changes.
1 change: 1 addition & 0 deletions ros2_21_ws/log/latest
1 change: 1 addition & 0 deletions ros2_21_ws/log/latest_build
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ class PublisherNode(Node):

def __init__(self, name):
super().__init__(name) # ROS2节点父类初始化
self.pub = self.create_publisher(String, "chatter", 10) # 创建发布者对象(消息类型、话题名、队列长度)
self.timer = self.create_timer(0.5, self.timer_callback) # 创建一个定时器(单位为秒的周期,定时执行的回调函数)

self.pub = self.create_publisher(String, "chatter", 10) # 创建发布者对象(消息类型、话题名、队列长度)self.create_publish()==========================================
self.timer = self.create_timer(0.5, self.timer_callback) # 创建一个定时器(单位为秒的周期,定时执行的回调函数) 0.5 相当于1s两次

# 被上面的self.create_timer调用
def timer_callback(self): # 创建定时器周期执行的回调函数
msg = String() # 创建一个String类型的消息对象
msg.data = 'Hello World' # 填充消息对象中的消息数据
self.pub.publish(msg) # 发布话题消息
self.pub.publish(msg) # 发布话题消息self.pub.publish(msg)========================================================================
self.get_logger().info('Publishing: "%s"' % msg.data) # 输出日志信息,提示已经完成话题发布

def main(args=None): # ROS2节点主入口main函数
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ class SubscriberNode(Node):
def __init__(self, name):
super().__init__(name) # ROS2节点父类初始化
self.sub = self.create_subscription(\
String, "chatter", self.listener_callback, 10) # 创建订阅者对象(消息类型、话题名、订阅者回调函数、队列长度)
String, "chatter", self.listener_callback, 10) # 创建订阅者对象(消息类型、话题名、订阅者回调函数、队列长度)=注意节点名字要对应

# 被上面调用 回调函数
def listener_callback(self, msg): # 创建回调函数,执行收到话题消息后对数据的处理
# 得到数据进行处理操纵
self.get_logger().info('I heard: "%s"' % msg.data) # 输出日志信息,提示订阅收到的话题消息

def main(args=None): # ROS2节点主入口main函数
Expand Down
File renamed without changes.
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
'''
Description:
Author: HCQ
Company(School): UCAS
Email: 1756260160@qq.com
Date: 2022-07-25 14:41:52
LastEditTime: 2022-07-25 14:59:54
FilePath: /ros2_python/ros2_21_ws/learning_topic/setup.py
'''
from setuptools import setup

package_name = 'learning_topic'
Expand All @@ -20,7 +29,7 @@
tests_require=['pytest'],
entry_points={
'console_scripts': [
'topic_helloworld_pub = learning_topic.topic_helloworld_pub:main',
'topic_helloworld_pub = learning_topic.topic_helloworld_pub:main', # 配置路径才能rosrun
'topic_helloworld_sub = learning_topic.topic_helloworld_sub:main',
'topic_webcam_pub = learning_topic.topic_webcam_pub:main',
'topic_webcam_sub = learning_topic.topic_webcam_sub:main',
Expand Down

0 comments on commit 308ffbf

Please sign in to comment.