(1) Control Turtlebot 1-generation Walk

Source: Internet
Author: User

In order to control Turtlebot's walk autonomously, we need to implement it in code. I. Preparation


In this process, we need to know which topic to send a message to. The internet says it's cmd_vel, but I didn't try. We can use the Rostopic list to see a listing of the current output activity topics. We can see that/cmd_vel_mux/input/teleop is what we need, the code is as follows:

young@young-lenovo:~$ rostopic List
/capability_server/bonds
/capability_server/events
/cmd_vel_mux/active
/cmd_vel_mux/input/navi
/cmd_vel_mux/input/safety_controller
/cmd_vel_mux/input/teleop
/cmd_vel_mux/parameter_descriptions
/cmd_vel_mux/parameter_updates
/diagnostics
/diagnostics_agg
/diagnostics_toplevel_state
/gateway/force_update
/gateway/gateway_info
/info
/interactions/interactive_clients
/interactions/pairing
/joint_states
/mobile_base/commands/velocity
/mobile_base/sensors/core
/mobile_base/sensors/imu_data
/mobile_base/sensors/imu_data_raw
/mobile_base_nodelet_manager/bond
/odom
/robot_pose_ekf/odom_combined
/rosout
/rosout_agg
/tf
/tf_static
/turtlebot/incompatible_rapp_list
/turtlebot/rapp_list
/turtlebot/status
/turtlebot_node/parameter_descriptions
/turtlebot_node/parameter_updates
/zeroconf/lost_connections
/zeroconf/new_connectionsCode

#include <ros/ros.h> #include <signal.h> #include <geometry_msgs/Twist.h> ros::P ublisher cmdvelpub;
    int main (int argc, char **argv) {ros::init (argc, argv, "Exbotxi_example_move");

    std::string topic = "Cmd_vel_mux/input/teleop";
    Ros::nodehandle node;
    Cmdvelpub = node.advertise<geometry_msgs::twist> ("Cmd_vel", 1);
    Ros::rate Looprate (50);
    Signal (SIGINT, shutdown);

    Ros_info ("Exbot_example_move cpp start ...");
    int rate = 50;
    Double linear_speed = 0.2;
    Double goal_distance = 1.0;

    Double linear_duration = goal_distance/linear_speed;

    Geometry_msgs::twist speed;  for (int i=0, i<1; i++) {speed = Geometry_msgs::twist ();//stop car int ticks = Int (linear_duration
        * rate);
        speed.linear.x = Linear_speed;
            for (int. t=0; t<ticks; t++) {cmdvelpub.publish (speed);
        Looprate.sleep ();
    } speed = Geometry_msgs::twist (); } return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.