Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6.服务之RCLPY实现 (案例代码有误) #33

Open
ipc-robot opened this issue Aug 2, 2024 · 1 comment
Open

6.服务之RCLPY实现 (案例代码有误) #33

ipc-robot opened this issue Aug 2, 2024 · 1 comment

Comments

@ipc-robot
Copy link

ipc-robot@ipcrobot-Precision-Tower-3420:~/ros2_ws$ ros2 run example_service_rclpy service_client_02
[INFO] [1722589543.093786297] [service_client_02]: 节点已启动:service_client_02!
Traceback (most recent call last):
  File "/home/ipc-robot/ros2_ws/install/example_service_rclpy/lib/example_service_rclpy/service_client_02", line 33, in <module>
    sys.exit(load_entry_point('example-service-rclpy==0.0.0', 'console_scripts', 'service_client_02')())
  File "/home/ipc-robot/ros2_ws/install/example_service_rclpy/lib/python3.10/site-packages/example_service_rclpy/service_client_02.py", line 14, in main
    node.send_request(3,4)
AttributeError: 'ServiceClient02' object has no attribute 'send_request'
[ros2run]: Process exited with failure 1

以下是client_02的代码:

#!/usr/bin/env python3
import rclpy
from rclpy.node import Node
from example_interfaces.srv import AddTwoInts

class ServiceClient02(Node):
    def __init__(self,name):
        super().__init__(name)
        self.get_logger().info("节点已启动:%s!" % name)

def main(args=None):
    rclpy.init(args=args) # 初始化rclpy
    node = ServiceClient02("service_client_02")  # 新建一个节点
    node.send_request(3,4)
    rclpy.spin(node) # 保持节点运行,检测是否收到退出指令(Ctrl+C)
    rclpy.shutdown() # 关闭rclpy
@fishros
Copy link
Owner

fishros commented Aug 9, 2024

需要继续往下看,这里代码不完整。另外最近新书和新课程上线了,建议学习新版教程,更加详细,且代码经过反复验证:https://github.com/fishros/ros2bookcode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants