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; }