科研向(仿真验证) ROS 学习笔记一:ROS 概述与环境搭建


# Edite configuration file: CamkeList.txt
catkin_install_python(PROGRAMS scripts/自定义文件名(hello_world).py
	DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

# Build 
# 1.command line method:
cd tutu_ws; catkin_make
# 2.vsc method: ctrl + shift + B
cd tutu_ws; code .

# Run
roscore; cd tutu_ws; source ./devel/setup.bash; rosrun helloworld hello_world.py

hello_world.py 的具体内容如下所示:

#! /usr/bin/env python
import rospy
# sys.path.insert(0,path + "/src/pkg/scripts")  # 如果需要导入自己的包
# import your_py

if __name__ == "__main__":
    rospy.init_node("Hello")
    '''
    在ROS msater中注册节点

    @param name: 节点名称(唯一),节点名称中不能使用命名空间(不能包含 '/')
    @type  name: str

	@param argv: 封装节点调用时传递的参数,存到参数服务器
	@type  argv: None
	
    @param anonymous: 取值为 true 时,为节点名称后缀随机编号可以解决重名
    @type  anonymous: bool
    '''
    rospy.loginfo("Hello World!!!!")  # 打印

也使用 launch 来实现 Run 步骤: 【可以摆脱需要多个 terminal 的问题】

cd tutu_ws; mkdir src/helloworld/launch; > new.launch
roslaunch helloworld new.launch

new.launch 的具体内容如下所示:

<launch>
    <node pkg="helloworld" type="hello_world.py" name="hello" output="screen" />
</launch>
For C++:
  • Modify Package Configuration File (package.xml)
    <build_depend>message_generation</build_depend>
    <build_export_depend>message_runtime</build_export_depend>
    
    <exec_depend>message_runtime</exec_depend>
    <exec_depend>roscpp</exec_depend>
    
    <depend>std_msgs</depend>
    
  • Modify Configuration File (CMakeLists.txt)
    find_package(roscpp, ...)
    add_message_files(xxx.msg, ...)  	
    add_service_files(xxx.srv, ...)    
    add_action_files(xxx.action, ...)		
    
    generate_messages(std_msgs, ...)
    
    add_executable(X__ xxx.cpp)  ## HELLOWORLD 基本步骤 1/2, rosrun helloworld X
    add_dependencies(xxx ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
    target_link_libraries(X__ ${catkin_LIBRARIES})  ## HELLOWORLD 基本步骤 2/2
    
3. ROS 计算图 rqt_graph

启动:rosrun rqt_graph rqt_graph


参考资料如下ROS理论与实践

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值