├── .gitignore
├── CMakeLists.txt
├── README.md
├── execute_me.sh
├── launch
├── move_circle.launch
└── move_square.launch
├── package.xml
├── src
├── move_circle_client.py
├── move_circle_server.py
├── move_square_client.py
└── move_square_server.py
└── srv
├── MoveCircle.srv
├── MoveCircle.srv~
└── MoveSquare.srv
/.gitignore:
--------------------------------------------------------------------------------
1 | .pyc
2 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 2.8.3)
2 | project(turtlesim_cleaner)
3 |
4 | ## Compile as C++11, supported in ROS Kinetic and newer
5 | # add_compile_options(-std=c++11)
6 |
7 | ## Find catkin macros and libraries
8 | ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
9 | ## is used, also find other catkin packages
10 | find_package(catkin REQUIRED COMPONENTS
11 | geometry_msgs
12 | rospy
13 | message_generation
14 |
15 | )
16 |
17 | ## System dependencies are found with CMake's conventions
18 | # find_package(Boost REQUIRED COMPONENTS system)
19 |
20 |
21 | ## Uncomment this if the package has a setup.py. This macro ensures
22 | ## modules and global scripts declared therein get installed
23 | ## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
24 | # catkin_python_setup()
25 |
26 | ################################################
27 | ## Declare ROS messages, services and actions ##
28 | ################################################
29 |
30 | ## To declare and build messages, services or actions from within this
31 | ## package, follow these steps:
32 | ## * Let MSG_DEP_SET be the set of packages whose message types you use in
33 | ## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
34 | ## * In the file package.xml:
35 | ## * add a build_depend tag for "message_generation"
36 | ## * add a build_depend and a run_depend tag for each package in MSG_DEP_SET
37 | ## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
38 | ## but can be declared for certainty nonetheless:
39 | ## * add a run_depend tag for "message_runtime"
40 | ## * In this file (CMakeLists.txt):
41 | ## * add "message_generation" and every package in MSG_DEP_SET to
42 | ## find_package(catkin REQUIRED COMPONENTS ...)
43 | ## * add "message_runtime" and every package in MSG_DEP_SET to
44 | ## catkin_package(CATKIN_DEPENDS ...)
45 | ## * uncomment the add_*_files sections below as needed
46 | ## and list every .msg/.srv/.action file to be processed
47 | ## * uncomment the generate_messages entry below
48 | ## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)
49 |
50 | ## Generate messages in the 'msg' folder
51 | # add_message_files(
52 | # FILES
53 | # Message1.msg
54 | # Message2.msg
55 | # )
56 |
57 | ## Generate services in the 'srv' folder
58 | add_service_files(
59 | FILES
60 | MoveCircle.srv
61 | MoveSquare.srv
62 | )
63 |
64 | ## Generate actions in the 'action' folder
65 | # add_action_files(
66 | # FILES
67 | # Action1.action
68 | # Action2.action
69 | # )
70 |
71 | ## Generate added messages and services with any dependencies listed here
72 | generate_messages(
73 | DEPENDENCIES
74 | geometry_msgs
75 | )
76 |
77 | ################################################
78 | ## Declare ROS dynamic reconfigure parameters ##
79 | ################################################
80 |
81 | ## To declare and build dynamic reconfigure parameters within this
82 | ## package, follow these steps:
83 | ## * In the file package.xml:
84 | ## * add a build_depend and a run_depend tag for "dynamic_reconfigure"
85 | ## * In this file (CMakeLists.txt):
86 | ## * add "dynamic_reconfigure" to
87 | ## find_package(catkin REQUIRED COMPONENTS ...)
88 | ## * uncomment the "generate_dynamic_reconfigure_options" section below
89 | ## and list every .cfg file to be processed
90 |
91 | ## Generate dynamic reconfigure parameters in the 'cfg' folder
92 | # generate_dynamic_reconfigure_options(
93 | # cfg/DynReconf1.cfg
94 | # cfg/DynReconf2.cfg
95 | # )
96 |
97 | ###################################
98 | ## catkin specific configuration ##
99 | ###################################
100 | ## The catkin_package macro generates cmake config files for your package
101 | ## Declare things to be passed to dependent projects
102 | ## INCLUDE_DIRS: uncomment this if you package contains header files
103 | ## LIBRARIES: libraries you create in this project that dependent projects also need
104 | ## CATKIN_DEPENDS: catkin_packages dependent projects also need
105 | ## DEPENDS: system dependencies of this project that dependent projects also need
106 | catkin_package(
107 | # INCLUDE_DIRS include
108 | # LIBRARIES turtlesim_cleaner
109 | # CATKIN_DEPENDS geometry_msgs rospy
110 | # DEPENDS system_lib
111 | )
112 |
113 | ###########
114 | ## Build ##
115 | ###########
116 |
117 | ## Specify additional locations of header files
118 | ## Your package locations should be listed before other locations
119 | include_directories(
120 | # include
121 | ${catkin_INCLUDE_DIRS}
122 | )
123 |
124 | ## Declare a C++ library
125 | # add_library(${PROJECT_NAME}
126 | # src/${PROJECT_NAME}/turtlesim_cleaner.cpp
127 | # )
128 |
129 | ## Add cmake target dependencies of the library
130 | ## as an example, code may need to be generated before libraries
131 | ## either from message generation or dynamic reconfigure
132 | # add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
133 |
134 | ## Declare a C++ executable
135 | ## With catkin_make all packages are built within a single CMake context
136 | ## The recommended prefix ensures that target names across packages don't collide
137 | # add_executable(${PROJECT_NAME}_node src/turtlesim_cleaner_node.cpp)
138 |
139 | ## Rename C++ executable without prefix
140 | ## The above recommended prefix causes long target names, the following renames the
141 | ## target back to the shorter version for ease of user use
142 | ## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
143 | # set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")
144 |
145 | ## Add cmake target dependencies of the executable
146 | ## same as for the library above
147 | # add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
148 |
149 | ## Specify libraries to link a library or executable target against
150 | # target_link_libraries(${PROJECT_NAME}_node
151 | # ${catkin_LIBRARIES}
152 | # )
153 |
154 | #############
155 | ## Install ##
156 | #############
157 |
158 | # all install targets should use catkin DESTINATION variables
159 | # See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html
160 |
161 | ## Mark executable scripts (Python etc.) for installation
162 | ## in contrast to setup.py, you can choose the destination
163 | # install(PROGRAMS
164 | # scripts/my_python_script
165 | # DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
166 | # )
167 |
168 | ## Mark executables and/or libraries for installation
169 | # install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_node
170 | # ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
171 | # LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
172 | # RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
173 | # )
174 |
175 | ## Mark cpp header files for installation
176 | # install(DIRECTORY include/${PROJECT_NAME}/
177 | # DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
178 | # FILES_MATCHING PATTERN "*.h"
179 | # PATTERN ".svn" EXCLUDE
180 | # )
181 |
182 | ## Mark other files for installation (e.g. launch and bag files, etc.)
183 | # install(FILES
184 | # # myfile1
185 | # # myfile2
186 | # DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
187 | # )
188 |
189 | #############
190 | ## Testing ##
191 | #############
192 |
193 | ## Add gtest based cpp test target and link libraries
194 | # catkin_add_gtest(${PROJECT_NAME}-test test/test_turtlesim_cleaner.cpp)
195 | # if(TARGET ${PROJECT_NAME}-test)
196 | # target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
197 | # endif()
198 |
199 | ## Add folders to be run by python nosetests
200 | # catkin_add_nosetests(test)
201 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Turtlesim_cleaner
2 |
3 | Hi, this package contains 4 nodes + 2 launch files + 1 shell script that runs the two launch files consecutively.
4 |
5 | # Circle :
6 |
7 | 1. move_circle_server : ROS Server that makes turtlesim move in a circle.
8 | 2. move_circle_client : ROS Client that requests the Server with arguments for speed and radius of Circle.
9 |
10 | # Square :
11 |
12 | 1. move_square_server : ROS Server that makes turtlesim draw squares.
13 | 2. move_square_client : ROS Client that request the server with arguments for side lenght and number of rotations.
14 |
15 | # Launch Files
16 |
17 | 1. move_circle.launch : Launches turtlesim + server + client
18 | 2. move_square.launch : Launches turtlesim + server + client
19 |
--------------------------------------------------------------------------------
/execute_me.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # My first script
3 |
4 | roslaunch turtlesim_cleaner move_circle.launch
5 | roslaunch turtlesim_cleaner move_square.launch
--------------------------------------------------------------------------------
/launch/move_circle.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/launch/move_square.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | turtlesim_cleaner
4 | 0.0.0
5 | The turtlesim_cleaner package
6 |
7 |
8 |
9 |
10 | sudharshan
11 |
12 |
13 |
14 |
15 |
16 | TODO
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | catkin
43 | geometry_msgs
44 | rospy
45 | geometry_msgs
46 | rospy
47 | message_generation
48 | message_runtime
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/src/move_circle_client.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import rospy
4 | from turtlesim_cleaner.srv import *
5 |
6 | def move_circle_client():
7 | rospy.wait_for_service('move_circle')
8 | try:
9 | radius = float(input("Enter Radius (0 - 2.5) : "))
10 | speed = float(input("Enter Speed : "))
11 | move_circle = rospy.ServiceProxy('move_circle', MoveCircle)
12 | move_circle(speed,radius)
13 | #return resp1.sum
14 | except rospy.ServiceException, e:
15 | print "Service call failed: %s"%e
16 |
17 | if __name__ == "__main__":
18 | print "What is your wish?"
19 | move_circle_client()
--------------------------------------------------------------------------------
/src/move_circle_server.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import rospy
4 | from turtlesim_cleaner.srv import *
5 | from geometry_msgs.msg import Twist
6 |
7 | PI = 3.1415926535897
8 |
9 | def handle_move_circle(req):
10 | pub = rospy.Publisher('/turtle1/cmd_vel',Twist, queue_size = 10)
11 | vel_msg = Twist()
12 | speed = req.s
13 | radius = req.r
14 |
15 | print "Your wish is my command"
16 | print "If you want to quit and watch me draw squares, Ctl-c me"
17 |
18 |
19 | vel_msg.linear.x = speed
20 | vel_msg.linear.y = 0
21 | vel_msg.linear.z = 0
22 | vel_msg.angular.x = 0
23 | vel_msg.angular.y = 0
24 | vel_msg.angular.z = speed/radius
25 |
26 | #Move Robot in circle
27 | while not rospy.is_shutdown():
28 | pub.publish(vel_msg)
29 |
30 | vel_msg.linear.x = 0
31 | vel_msg.linear.z = 0
32 | pub.publish(vel_msg)
33 |
34 | def move_circle_server():
35 | rospy.init_node('move_circle_server')
36 | s = rospy.Service( 'move_circle', MoveCircle, handle_move_circle )
37 | rospy.spin()
38 |
39 | if __name__ == "__main__":
40 | move_circle_server()
41 |
42 |
--------------------------------------------------------------------------------
/src/move_square_client.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import rospy
4 | from turtlesim_cleaner.srv import *
5 |
6 | def move_square_client():
7 | rospy.wait_for_service('move_square')
8 | try:
9 | side_length = input("Enter Side length (0-5) : ")
10 | rotations = input("Enter number of rotations : ")
11 | move_square = rospy.ServiceProxy('move_square', MoveSquare)
12 | move_square(side_length,rotations)
13 |
14 | except rospy.ServiceException, e:
15 | print "Service call failed: %s"%e
16 |
17 | if __name__ == "__main__":
18 | move_square_client()
--------------------------------------------------------------------------------
/src/move_square_server.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import rospy
4 | from turtlesim_cleaner.srv import *
5 | from geometry_msgs.msg import Twist
6 | PI = 3.1415926535897
7 | # Setting a default speed of 3 units/sec
8 | speed = 3
9 |
10 | # Callback will create a publisher that publishes to the turtlesim
11 | def handle_move_square(req):
12 | print "I shall do your bidding"
13 | pub = rospy.Publisher('/turtle1/cmd_vel',Twist, queue_size = 10)
14 | vel_msg = Twist()
15 | side_length = req.s
16 | rotations = req.r
17 |
18 | current_rotation = 0
19 | while current_rotation < rotations:
20 | move_in_line(side_length,vel_msg,pub)
21 | rotate(vel_msg,pub)
22 | current_rotation+=0.25
23 |
24 | def move_square_server():
25 | rospy.init_node('move_square_server',anonymous = True)
26 | s = rospy.Service( 'move_square', MoveSquare, handle_move_square )
27 | rospy.spin()
28 |
29 |
30 | def move_in_line(side_length,vel_msg,pub):
31 |
32 | vel_msg.linear.x = speed
33 | vel_msg.linear.y = 0
34 | vel_msg.linear.z = 0
35 | vel_msg.angular.x = 0
36 | vel_msg.angular.y = 0
37 | vel_msg.angular.z = 0
38 |
39 | t0 = rospy.Time.now().to_sec()
40 | distance_travelled = 0
41 |
42 | while distance_travelled < side_length:
43 | pub.publish(vel_msg)
44 | t1 = rospy.Time.now().to_sec()
45 | distance_travelled = speed*(t1-t0)
46 |
47 | vel_msg.linear.x = 0
48 | pub.publish(vel_msg)
49 |
50 | def rotate(vel_msg,pub):
51 | angular_speed = 2
52 | vel_msg.angular.z = angular_speed
53 | t0 = rospy.Time.now().to_sec()
54 | angle_travelled = 0
55 |
56 | while ( angle_travelled < PI/2.0 ):
57 | pub.publish(vel_msg)
58 | t1 = rospy.Time.now().to_sec()
59 | angle_travelled = angular_speed*(t1-t0)
60 |
61 | vel_msg.angular.z = 0
62 | pub.publish(vel_msg)
63 |
64 | if __name__ == '__main__':
65 | try:
66 | move_square_server()
67 | except rospy.ROSInterruptException:
68 | pass
69 |
--------------------------------------------------------------------------------
/srv/MoveCircle.srv:
--------------------------------------------------------------------------------
1 | float32 s
2 | float32 r
3 | ---
4 |
--------------------------------------------------------------------------------
/srv/MoveCircle.srv~:
--------------------------------------------------------------------------------
1 | float32
2 | float32
3 | ---
4 |
--------------------------------------------------------------------------------
/srv/MoveSquare.srv:
--------------------------------------------------------------------------------
1 | float32 s
2 | int32 r
3 | ---
4 |
--------------------------------------------------------------------------------