项目作者: felixchenfy

项目描述 :
ROS services for controlling Turtlebot3 to target pose by `Move to Pose` algorithm.
高级语言: Python
项目地址: git://github.com/felixchenfy/ros_turtlebot_control.git
创建时间: 2019-12-01T23:48:39Z
项目社区:https://github.com/felixchenfy/ros_turtlebot_control

开源协议:MIT License

下载


ROS Turtlebot Control

Demo: Result of running these two commands:

  1. rosservice call /turtle/move_to_pose -- -1 -1 -1.57 # (x, y, theta)
  2. rosservice call /turtle/move_to_relative_point -- -1 1 # (x, y)
  3. # Coordinate: +x is front, +y is left; +theta is x to y.

Contents:

Introduction

Main services:

  1. # Control robot to pose.
  2. # The control algorithm will run in a new thread,
  3. # and the service call is immediately finished.
  4. # If a new command is sent, the old one stops immediatly.
  5. MoveToPose.srv
  6. MoveToRelativePose.srv
  7. MoveToPoint.srv
  8. MoveToRelativePoint.srv
  9. # Get/Set state.
  10. GetPose.srv
  11. StopMoving.srv
  12. IsMoving.srv
  13. ResetPose.srv
  14. SetPose.srv # Only for simulation.

Algorithm:
The Move to Pose algorithm is adopted, which uses PID control to reduce the distance between robot pose (x, y, theta) and target pose (x, y, theta*). The code is implemented in turtle_lib.py and def _control_robot_to_pose.

Reference:
For more details about the algorithm, please see Professor Peter Corke’s book Robotics, Vision and Control, Chapter 4.1.1.4—Moving to a Pose.

Main files:

System diagram:
doc/system_diagram.png

Example of usage

Installation

Download my project:

  1. cd ~/catkin_ws/src # Your catkin workspace
  2. git clone https://github.com/felixchenfy/ros_turtlebot_control

Install Gazebo and Turtlebot related packages. See this: doc/dependencies.md. Make sure the simulated Turtlebot can run in Gazebo.

Check configuration

Open config.yaml, check the section ROS topics/services name used by this package. Make sure the ROS topic/service/tf names are same as yours.

Especially these keywords:

  • model_name: It should be one of the turtlebot3_waffle_pi, turtlebot3_waffle, turtlebot3_burger.
  • base_frame: You can use $ rosrun tf view_frames to see the tf tree and know your base_frame name.

Start services’ server

Launch your real Turtlebot3. Or start a simulation like this:

  1. roscore
  2. roslaunch turtlebot3_gazebo turtlebot3_empty_world.launch

Start this turtlebot control server:

  1. rosrun ros_turtlebot_control turtlebot_server.py

Call services from command line

  • Move to (x=-1, y=-1, theta=1.57):

    1. rosservice call /turtle/move_to_pose -- -1 -1 1.57

    (Notes: -- is a ROS default argument. It’s used when the arguments have negative value.)

  • Move to (x=1, y=1):

    1. rosservice call /turtle/move_to_point 1 1
  • Move to relative (x=1, y=0, theta=1.57):

    1. rosservice call /turtle/move_to_relative_pose 1 0 1.57
  • Move to relative (x=0, y=-1):

    1. rosservice call /turtle/move_to_relative_point -- 0 -1
  • Reset:

    1. rosservice call /turtle/reset_pose

Call services from python functions

I wrote a class and some unittests in turtlebot_client.py:

  1. class TurtleClient(object):
  2. def move_to_point(self, x, y):
  3. def wait_until_stop(self):
  4. def is_at(self, x, y, theta=None,
  5. ...
  6. if __name__ == "__main__":
  7. rospy.init_node("turtlebot_client")
  8. test_set_pose_IN_SIMULATION_ONLY() # Not for real robot.
  9. test_get_and_reset_pose()
  10. test_move_to_poses()
  11. test_move_to_points()
  12. test_change_target_and_stop()

Run it to test the ROS services:

$ rosrun ros_turtlebot_control turtlebot_client.py

You may also copy the file to your own project repo, and then import class TurtleClient to use the python API functions.