c程序编译运行
// 编译,gcc是编译的命令,-o表示编译后生成的可执行二进制文件
gcc cfile.c -o cfile
// 运行
./cfile
为什么输入“./”:当您键入命令名称(a.out与此方面的任何其他命令名称没有区别)时,shell将搜索具有该名称的可执行文件。它使用存储在$PATH环境变量中的目录名列表执行此搜索。./告诉bash在当前目录中查找文件cfile
main(int argc, char *argv[]) 中argc表示程序输入参数个数,argv表示参数列表
rosrun topic_pkg publisher// 注意publisher是节点不是文件
rostopic echo topicname // print messages to screen打印话题信 如下图rostopic echo /turtle1/cmdele
ros节点通信
注意图片中的c++标准和includePath。(generate_messages的作用是自动创建我们自定义的消息类型*.msg与服务类型*.srv相对应的*.h)生成的.h文件放在devel目录下,如果引用头文件报错,在includePath中添加路径
source devel/setup.bash作用: 设置环境变量。设置环境变量目的是为了让系统找到工作空间中对应的功能包,路径设置。
ros参数设置
roscore在启动时会输出。可以通过 nh.setParam(“nh_int”,10000); ros::param::set(“param_int”,20);两种方法实现。可以在控制台输入下图中的命令查看。
自定义源文件调用
第一步
###########
## Build ##
###########
## Specify additional locations of header files 指定头文件的其他位置
## Your package locations should be listed before other locations # 向工程添加多个特定的头文件搜索路径
include_directories(
include
${catkin_INCLUDE_DIRS}
)
## Declare a C++ library #自定义库文件名字
add_library(a
src/headFileSrc.cpp
)
## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
add_dependencies(a ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
第二步,
## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
add_executable(hello src/hello.cpp)
## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")
## Add cmake target dependencies of the executable
## same as for the library above
add_dependencies(hello ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
## Specify libraries to link a library or executable target against
target_link_libraries(hello
a ##第二步,可执行文件里面添加自定义库文件
${catkin_LIBRARIES}
)