GithubHelp home page GithubHelp logo

felixchenfy / ros_turtlebot_control Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 4.0 1.41 MB

ROS services for controlling Turtlebot3 to target pose by `Move to Pose` algorithm.

License: MIT License

CMake 13.91% Python 86.09%
ros turtlebot3 control ros-service mobile-robot

ros_turtlebot_control's Introduction

ROS Turtlebot Control

Demo: Result of running these two commands:

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

Contents:

Introduction

Main services:

# Control robot to pose.
#   The control algorithm will run in a new thread, 
#   and the service call is immediately finished.
#   If a new command is sent, the old one stops immediatly.
MoveToPose.srv   
MoveToRelativePose.srv   
MoveToPoint.srv  
MoveToRelativePoint.srv

# Get/Set state.
GetPose.srv
StopMoving.srv
IsMoving.srv
ResetPose.srv
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:

cd ~/catkin_ws/src # Your catkin workspace
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:

roscore
roslaunch turtlebot3_gazebo turtlebot3_empty_world.launch 

Start this turtlebot control server:

rosrun ros_turtlebot_control turtlebot_server.py   

Call services from command line

  • Move to (x=-1, y=-1, theta=1.57):
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):
rosservice call /turtle/move_to_point 1 1
  • Move to relative (x=1, y=0, theta=1.57):
rosservice call /turtle/move_to_relative_pose 1 0 1.57
  • Move to relative (x=0, y=-1):
rosservice call /turtle/move_to_relative_point -- 0 -1
  • Reset:
rosservice call /turtle/reset_pose

Call services from python functions

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

class TurtleClient(object):
    def move_to_point(self, x, y):
    def wait_until_stop(self):
    def is_at(self, x, y, theta=None,
    ...

if __name__ == "__main__":
    rospy.init_node("turtlebot_client")
    test_set_pose_IN_SIMULATION_ONLY()  # Not for real robot.
    test_get_and_reset_pose()
    test_move_to_poses()
    test_move_to_points()
    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.

ros_turtlebot_control's People

Contributors

felixchenfy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.