zoukankan      html  css  js  c++  java
  • ROS入门:小海龟实验

    1.初试小海龟

    
      1.roscore
    
      2.rosrun turtlesim turtlesim_node
    
      3.rosrun turtlesim turtle_teleop_key
    
    

    2.发布话题控制小海龟

    1.创建功能包

    catkin_create_pkg turtle_control geometry_msgs rospy roscpp
    
    

    2.编写turtle_control.cpp

    
    #include "ros/ros.h"
    #include "geometry_msgs/Twist.h"
    int main(int argc, char** argv)
    {
    ros::init(argc,argv,"turtle_control_node");
    ros::NodeHandle nh;
    ros::Publisher pub = nh.advertise<geometry_msgs::Twist>("/turtle1/cmd_vel",1000);
    ros::Rate loop_rate(10);
    geometry_msgs::Twist pub_date;
    while( ros::ok() )
    {
    pub_date.linear.x = 0.5;
    pub_date.linear.y = 0.0;
    pub_date.linear.z = 0.0;
    pub_date.angular.x = 0;
    pub_date.angular.y = 0;
    pub_date.angular.z = 0;
    pub.publish(pub_date);
    ros::spinOnce();
    loop_rate.sleep();
    
    }
    return 0;
    }
    
    

    3.package.xml主要依赖

    
    <buildtool_depend>catkin</buildtool_depend>
    <build_depend>roscpp</build_depend>
    <build_depend>rospy</build_depend>
    <build_depend>geometry_msg</build_depend>
    <build_export_depend>roscpp</build_export_depend>
    <build_export_depend>rospy</build_export_depend>
    <build_export_depend>geometry_msg</build_export_depend>
    <exec_depend>roscpp</exec_depend>
    <exec_depend>rospy</exec_depend>
    <exec_depend>geometry_msg</exec_depend>
    

    4.修改CMakeLists.txt

    
    find_package(catkin REQUIRED COMPONENTS
      roscpp
      rospy
      geometry_msgs
    )
    include_directories(
      ${catkin_INCLUDE_DIRS}
    )
    
    add_executable(${PROJECT_NAME}_node
        ${PROJECT_NAME}_node.cpp
    )
    
    target_link_libraries(${PROJECT_NAME}_node
       ${catkin_LIBRARIES}
     )
    
  • 相关阅读:
    Pandas
    多进程编程
    python的多线程编程
    Scrapy中集成selenium
    生成器函数yield和使用yield模拟协程
    迭代器和可迭代对象
    HDU5988 Coding Contest(浮点费用流)
    codeforces Technocup 2017
    codeforces724E Goods transportation(欧拉回路)
    UVAlive4097 Yungom(思路)
  • 原文地址:https://www.cnblogs.com/penuel/p/13168016.html
Copyright © 2011-2022 走看看