Project

General

Profile

Revision d006cdc0

IDd006cdc0e37e8758d45853fc541e3c1eead610a6
Parent 2afe2054
Child 8e58dd0e

Added by Tahm over 10 years ago

Adding turtlesim reference code

View differences:

HowToPlayWithTurtles.txt
6 6
turtlesim. You will become familiar with ROS, and with a framework like 
7 7
buggysim's. 
8 8

  
9
1. Build TurtleSim
10
------------------
11
   Run:
12
    cd ~/buggyworkspace
13
    catkin_make
9 14

  
15
    # We have now build the binaries; we will now overlay these on our 
16
    #   workspace. 
17
    cd ~/buggyworkspace/devel    
18
    source setup.bash
10 19

  
11 20

  
21
2. Run TurtleSim
22
----------------
23

  
24
We will now run turtlesim. This is, once again, a paraphrasing of the 
25
turtlesim tutorial, that can be found at http://wiki.ros.org/ROS/Tutorials/UnderstandingTopics . 
26

  
27
  Run:
28
   # Make sure you ran /deve/setup.bash, so the right binaries are run. 
29
   # Start up the core service
30
   roscore
31

  
32
   # Start up the rostopic viewer. 
33
   # This will let you watch as the new nodes come online, and you can see
34
   #   what topics and services they offer. 
35
   rqt_graph
36
   #   (i recommend unhiding all topics, to get a better view)
37

  
38
   # In a new terminal
39
   # This command will start 
40
   rosrun turtlesim_ref turtlesim_node
41
   
42
   # Run some commands to investigate
43
   rosnode list
44
   rosnode info /rosout
45

  
46
   # Read from a running topic
47
   rostopic hz /turtle1/pose # see update freq.
48
   rostopic bw /turtle1/pose # see bandwidth
49
   rostopic echo /turtle1/pose
50
   
51
   
turtlesim_ref/CMakeLists.txt
1
cmake_minimum_required(VERSION 2.8.3)
2
project(turtlesim_ref)
3
#project(turtlesim)
4

  
5
find_package(catkin REQUIRED COMPONENTS message_generation roscpp roslib rosconsole std_msgs std_srvs rostime roscpp_serialization)
6

  
7
find_package(Qt4 4.6 REQUIRED COMPONENTS QtCore QtGui)
8
include(${QT_USE_FILE})
9
find_package(Boost REQUIRED COMPONENTS thread)
10

  
11
include_directories(include ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${QT_INCLUDE_DIRS})
12
link_directories(${catkin_LIBRARY_DIRS})
13

  
14
add_message_files(DIRECTORY msg FILES 
15
                  Color.msg Pose.msg Velocity.msg)
16
add_service_files(DIRECTORY srv FILES
17
                  Kill.srv
18
                  SetPen.srv
19
                  Spawn.srv
20
                  TeleportAbsolute.srv
21
                  TeleportRelative.srv)
22
generate_messages(DEPENDENCIES std_msgs std_srvs)
23

  
24
catkin_package(CATKIN_DEPENDS message_runtime std_msgs std_srvs)
25

  
26
# Set up the dependencies for turtlesim_node
27
set(turtlesim_node_SRCS
28
  src/turtlesim.cpp
29
  src/turtle.cpp
30
  src/turtle_frame.cpp
31
)
32
set(turtlesim_node_HDRS
33
  include/turtlesim/turtle_frame.h
34
)
35

  
36
# apparently this is just what you do with QT
37
qt4_wrap_cpp(turtlesim_node_MOCS ${turtlesim_node_HDRS})
38

  
39
# Build the turtlesim node?
40
add_executable(turtlesim_node ${turtlesim_node_SRCS} ${turtlesim_node_MOCS})
41
target_link_libraries(turtlesim_node ${QT_LIBRARIES} ${catkin_LIBRARIES} ${Boost_LIBRARIES})
42
add_dependencies(turtlesim_node turtlesim_gencpp)
43

  
44

  
45
# Build the teleop...thing. I thought it was a package, 
46
#  it obviously isn't
47
add_executable(turtle_teleop_key tutorials/teleop_turtle_key.cpp)
48
target_link_libraries(turtle_teleop_key ${catkin_LIBRARIES})
49
add_dependencies(turtle_teleop_key turtlesim_gencpp)
50

  
51

  
52
# Build draw_square. so many words
53
add_executable(draw_square tutorials/draw_square.cpp)
54
target_link_libraries(draw_square ${catkin_LIBRARIES} ${Boost_LIBRARIES})
55
add_dependencies(draw_square turtlesim_gencpp)
56

  
57
# but these words I know, it spawns a turtle that does follor the leader
58
add_executable(mimic tutorials/mimic.cpp)
59
target_link_libraries(mimic ${catkin_LIBRARIES})
60
add_dependencies(mimic turtlesim_gencpp)
61

  
62
install(TARGETS turtlesim_node turtle_teleop_key draw_square mimic
63
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
64

  
65
install(DIRECTORY images
66
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
67
  FILES_MATCHING PATTERN "*.png")
turtlesim_ref/HowToBuild.txt
1
How to build this thing
2
=======================
3

  
4

  
5
Run catkin_make at the top level. 
6
The binaries will be in devel; 
7
    - to use them, source the setup.bash file in devel.
8
       this will drag the things you just built into your packagepath
9

  
10
Change the source, recompile, continue!
11

  
12
Note that if you want any of your stuff built, you have to 
13
add it to the cmake file. 
turtlesim_ref/debian/changelog
1
ros-groovy-turtlesim (0.3.13-0precise) precise; urgency=high
2

  
3
  * Autogenerated, no changelog for this version found in CHANGELOG.rst.
4

  
5
 -- Dirk Thomas <dthomas@osrfoundation.org>  Thu, 05 Sep 2013 22:29:39 -0000
6

  
7

  
turtlesim_ref/debian/compat
1
7
turtlesim_ref/debian/control
1
Source: ros-groovy-turtlesim
2
Section: misc
3
Priority: extra
4
Maintainer: Dirk Thomas <dthomas@osrfoundation.org>
5
Build-Depends: debhelper (>= 7.0.50~), libqt4-dev, qt4-qmake, ros-groovy-catkin, ros-groovy-message-generation, ros-groovy-rosconsole, ros-groovy-roscpp, ros-groovy-roscpp-serialization, ros-groovy-roslib, ros-groovy-rostime, ros-groovy-std-msgs, ros-groovy-std-srvs
6
Homepage: http://www.ros.org/wiki/turtlesim
7
Standards-Version: 3.9.2
8

  
9
Package: ros-groovy-turtlesim
10
Architecture: any
11
Depends: ${shlibs:Depends}, ${misc:Depends}, libqt4-dbus, libqt4-network, libqt4-script, libqt4-test, libqt4-xml, libqtcore4, ros-groovy-message-runtime, ros-groovy-rosconsole, ros-groovy-roscpp, ros-groovy-roscpp-serialization, ros-groovy-roslib, ros-groovy-rostime, ros-groovy-std-msgs, ros-groovy-std-srvs
12
Description: turtlesim is a tool made for teaching ROS and ROS packages.
turtlesim_ref/debian/gbp.conf
1
[git-buildpackage]
2
upstream-branch=release/groovy/turtlesim/0.3.13-0
3
upstream-tree=branch
turtlesim_ref/debian/rules
1
#!/usr/bin/make -f
2
# -*- makefile -*-
3
# Sample debian/rules that uses debhelper.
4
# This file was originally written by Joey Hess and Craig Small.
5
# As a special exception, when this file is copied by dh-make into a
6
# dh-make output file, you may use that output file without restriction.
7
# This special exception was added by Craig Small in version 0.37 of dh-make.
8

  
9
# Uncomment this to turn on verbose mode.
10
export DH_VERBOSE=1
11
export DH_OPTIONS=-v --buildsystem=cmake
12
# TODO: remove the LDFLAGS override.  It's here to avoid esoteric problems
13
# of this sort:
14
#  https://code.ros.org/trac/ros/ticket/2977
15
#  https://code.ros.org/trac/ros/ticket/3842
16
export LDFLAGS=
17
export PKG_CONFIG_PATH=/opt/ros/groovy/lib/pkgconfig
18

  
19
%:
20
	dh  $@
21

  
22
override_dh_auto_configure:
23
	# In case we're installing to a non-standard location, look for a setup.sh
24
	# in the install tree that was dropped by catkin, and source it.  It will
25
	# set things like CMAKE_PREFIX_PATH, PKG_CONFIG_PATH, and PYTHONPATH.
26
	if [ -f "/opt/ros/groovy/setup.sh" ]; then . "/opt/ros/groovy/setup.sh"; fi && \
27
	dh_auto_configure -- \
28
		-DCATKIN_BUILD_BINARY_PACKAGE="1" \
29
		-DCMAKE_INSTALL_PREFIX="/opt/ros/groovy" \
30
		-DCMAKE_PREFIX_PATH="/opt/ros/groovy"
31

  
32
override_dh_auto_build:
33
	# In case we're installing to a non-standard location, look for a setup.sh
34
	# in the install tree that was dropped by catkin, and source it.  It will
35
	# set things like CMAKE_PREFIX_PATH, PKG_CONFIG_PATH, and PYTHONPATH.
36
	if [ -f "/opt/ros/groovy/setup.sh" ]; then . "/opt/ros/groovy/setup.sh"; fi && \
37
	dh_auto_build
38

  
39
override_dh_auto_test:
40
	# In case we're installing to a non-standard location, look for a setup.sh
41
	# in the install tree that was dropped by catkin, and source it.  It will
42
	# set things like CMAKE_PREFIX_PATH, PKG_CONFIG_PATH, and PYTHONPATH.
43
	echo -- Running tests. Even if one of them fails the build is not canceled.
44
	if [ -f "/opt/ros/groovy/setup.sh" ]; then . "/opt/ros/groovy/setup.sh"; fi && \
45
	dh_auto_test || true
46

  
47
override_dh_shlibdeps:
48
	# In case we're installing to a non-standard location, look for a setup.sh
49
	# in the install tree that was dropped by catkin, and source it.  It will
50
	# set things like CMAKE_PREFIX_PATH, PKG_CONFIG_PATH, and PYTHONPATH.
51
	if [ -f "/opt/ros/groovy/setup.sh" ]; then . "/opt/ros/groovy/setup.sh"; fi && \
52
	dh_shlibdeps -l$(CURDIR)/debian/ros-groovy-turtlesim//opt/ros/groovy/lib/
turtlesim_ref/debian/source/format
1
3.0 (quilt)
turtlesim_ref/images/hydro.svg
1
<?xml version="1.0" encoding="utf-8"?>
2
<!-- Generator: Adobe Illustrator 16.0.4, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
3
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="45px"
5
	 height="45px" viewBox="0 0 45 45" enable-background="new 0 0 45 45" xml:space="preserve">
6
<g id="head1">
7
	<path fill="none" stroke="#A2C880" stroke-width="0.4" stroke-miterlimit="10" d="M17.829,14.402"/>
8
	<line fill="#A2C880" x1="14.885" y1="16.83" x2="15.303" y2="16.522"/>
9
	<path fill="#A2C880" d="M19.095,14.533"/>
10
	<line fill="#A2C880" x1="29.754" y1="16.83" x2="29.336" y2="16.522"/>
11
	<path fill="#A2C880" d="M25.544,14.533"/>
12
	<g>
13
		<g>
14
			<path fill="none" stroke="#C7E0AC" stroke-width="0.2366" stroke-miterlimit="10" d="M23.826,6.305"/>
15
		</g>
16
	</g>
17
	<path fill="none" stroke="#A2C880" stroke-width="0.4" stroke-miterlimit="10" d="M22.5,0.625"/>
18
	<path fill="#A2C880" stroke="#375219" stroke-width="1.5" stroke-miterlimit="10" d="M20.071,14.002
19
		c1.048-3.341-0.434-5.89-0.434-5.89c0.166,0.099-1.743-1.642-1.315-3.514C18.77,2.635,22.3,1.315,22.3,1.315
20
		s2.999,0.788,3.959,2.89s-1.107,3.981-1.271,3.912c0,0-1.466,3.42-0.276,5.53"/>
21
	<path fill="#231F20" d="M21.014,3.291c0,0-1.151,0.479-1.072,1.072c0.081,0.596,0.873,0.397,1.072,0.277
22
		c0.198-0.119,0.794-0.555,0.636-0.993c-0.161-0.435-0.161-0.435-0.161-0.435"/>
23
	<path fill="#231F20" d="M23.619,3.291c0,0,1.15,0.479,1.072,1.072c-0.078,0.596-0.873,0.397-1.072,0.277
24
		c-0.199-0.119-0.795-0.555-0.637-0.993c0.162-0.435,0.162-0.435,0.162-0.435"/>
25
	<g>
26
		<g>
27
			<path fill="none" stroke="#C7E0AC" stroke-width="0.2366" stroke-miterlimit="10" d="M22.04,4.491"/>
28
		</g>
29
	</g>
30
	<g>
31
		<g>
32
			<path fill="none" stroke="#C7E0AC" stroke-width="0.2366" stroke-miterlimit="10" d="M22.631,4.176"/>
33
		</g>
34
	</g>
35
	<g>
36
		<g>
37
			<path fill="none" stroke="#C7E0AC" stroke-width="0.2366" stroke-miterlimit="10" d="M25.036,4.491"/>
38
		</g>
39
	</g>
40
	<g>
41
		<g>
42
			<path fill="none" stroke="#C7E0AC" stroke-width="0.2366" stroke-miterlimit="10" d="M25.47,5.359"/>
43
		</g>
44
	</g>
45
	<path fill="none" stroke="#A2C880" stroke-width="0.4" stroke-miterlimit="10" d="M34.05,4.562"/>
46
	<path fill="#A2C880" stroke="#375219" stroke-width="1.5" stroke-miterlimit="10" d="M25.271,14.436
47
		c2.6-2.347,2.616-5.295,2.616-5.295c0.093,0.169-0.667-2.299,0.652-3.694c1.382-1.464,5.095-0.809,5.095-0.809
48
		s2.183,2.201,1.943,4.5s-2.976,2.868-3.082,2.725c0,0-3,2.202-3.046,4.624"/>
49
	<g>
50
		<g>
51
			<path fill="none" stroke="#C7E0AC" stroke-width="0.2366" stroke-miterlimit="10" d="M31.689,7.659"/>
52
		</g>
53
	</g>
54
	<g>
55
		<g>
56
			<path fill="none" stroke="#C7E0AC" stroke-width="0.2366" stroke-miterlimit="10" d="M32.359,7.688"/>
57
		</g>
58
	</g>
59
	<g>
60
		<g>
61
			<path fill="none" stroke="#C7E0AC" stroke-width="0.2366" stroke-miterlimit="10" d="M34.271,9.181"/>
62
		</g>
63
	</g>
64
	<g>
65
		<g>
66
			<path fill="none" stroke="#C7E0AC" stroke-width="0.2366" stroke-miterlimit="10" d="M34.205,10.148"/>
67
		</g>
68
	</g>
69
	<path fill="none" stroke="#A2C880" stroke-width="0.4" stroke-miterlimit="10" d="M10.817,4.562"/>
70
	<path fill="#A2C880" stroke="#375219" stroke-width="1.5" stroke-miterlimit="10" d="M19.597,14.436
71
		c-2.6-2.347-2.616-5.295-2.616-5.295c-0.093,0.169,0.667-2.299-0.652-3.694c-1.382-1.464-5.095-0.809-5.095-0.809
72
		s-2.183,2.201-1.943,4.5s2.976,2.868,3.082,2.725c0,0,3,2.202,3.046,4.624"/>
73
	<path fill="#231F20" d="M13.375,5.737c0,0,1.234-0.174,1.467,0.379c0.233,0.554-0.551,0.786-0.781,0.783
74
		c-0.232-0.002-0.967-0.075-1.054-0.533C12.925,5.91,12.925,5.91,12.925,5.91"/>
75
	<path fill="#231F20" d="M10.937,7.108c0,0-0.75,0.996-0.38,1.467c0.368,0.474,0.954-0.101,1.063-0.305
76
		c0.109-0.203,0.402-0.882,0.044-1.179c-0.36-0.293-0.36-0.293-0.36-0.293"/>
77
	<path fill="#231F20" d="M31.464,5.737c0,0-1.234-0.174-1.467,0.379c-0.233,0.554,0.551,0.786,0.781,0.783
78
		c0.232-0.002,0.967-0.075,1.054-0.533c0.082-0.456,0.082-0.456,0.082-0.456"/>
79
	<path fill="#231F20" d="M33.902,7.108c0,0,0.75,0.996,0.38,1.467c-0.368,0.474-0.954-0.101-1.063-0.305
80
		c-0.109-0.203-0.402-0.882-0.044-1.179c0.36-0.293,0.36-0.293,0.36-0.293"/>
81
	<g>
82
		<g>
83
			<path fill="none" stroke="#C7E0AC" stroke-width="0.2366" stroke-miterlimit="10" d="M13.178,7.659"/>
84
		</g>
85
	</g>
86
	<g>
87
		<g>
88
			<path fill="none" stroke="#C7E0AC" stroke-width="0.2366" stroke-miterlimit="10" d="M12.508,7.688"/>
89
		</g>
90
	</g>
91
	<g>
92
		<g>
93
			<path fill="none" stroke="#C7E0AC" stroke-width="0.2366" stroke-miterlimit="10" d="M10.596,9.181"/>
94
		</g>
95
	</g>
96
	<g>
97
		<g>
98
			<path fill="none" stroke="#C7E0AC" stroke-width="0.2366" stroke-miterlimit="10" d="M10.662,10.148"/>
99
		</g>
100
	</g>
101
</g>
102
<g id="head2" display="none">
103
	<path display="inline" fill="#A2C880" d="M19.542,13.598c0.175,0.104-1.841-1.735-1.39-3.713c0.473-2.075,4.205-3.47,4.205-3.47
104
		s3.168,0.833,4.184,3.054c1.016,2.221-1.17,4.208-1.344,4.134"/>
105
	<path display="inline" fill="#231F20" d="M19.781,8.012c0,0-0.81,0.336-0.754,0.755s0.614,0.279,0.754,0.195
106
		s0.56-0.391,0.448-0.699c-0.113-0.308-0.113-0.308-0.113-0.308"/>
107
	<path display="inline" fill="#231F20" d="M24.956,8.012c0,0,0.811,0.336,0.756,0.755c-0.057,0.419-0.617,0.279-0.756,0.195
108
		c-0.141-0.084-0.561-0.391-0.449-0.699c0.113-0.308,0.113-0.308,0.113-0.308"/>
109
	<path display="inline" fill="#A2C880" d="M18.388,14.193c-0.043,0.127,0.19-1.66-0.879-2.465c-1.123-0.846-3.6,0.038-3.6,0.038
110
		s-1.243,1.77-0.811,3.323s2.381,1.625,2.438,1.514"/>
111
	<path display="inline" fill="#231F20" d="M15.185,11.696c0,0,0.552-0.175,0.701,0.061c0.15,0.235-0.189,0.403-0.298,0.42
112
		c-0.106,0.017-0.448,0.042-0.522-0.162c-0.074-0.203-0.074-0.203-0.074-0.203"/>
113
	<path display="inline" fill="#231F20" d="M13.381,13.309c0,0-0.269,0.515-0.062,0.702c0.206,0.188,0.43-0.12,0.465-0.223
114
		c0.035-0.102,0.115-0.436-0.071-0.543c-0.189-0.107-0.189-0.107-0.189-0.107"/>
115
	<path display="inline" fill="#A2C880" d="M26.507,14.193c0.043,0.127-0.19-1.66,0.879-2.465c1.123-0.846,3.6,0.038,3.6,0.038
116
		s1.243,1.77,0.811,3.323s-2.381,1.625-2.438,1.514"/>
117
	<path display="inline" fill="#231F20" d="M29.702,11.686c0,0-0.558-0.154-0.698,0.087c-0.142,0.241,0.205,0.396,0.313,0.408
118
		c0.106,0.013,0.45,0.025,0.517-0.182c0.066-0.206,0.066-0.206,0.066-0.206"/>
119
	<path display="inline" fill="#231F20" d="M31.514,13.309c0,0,0.269,0.515,0.062,0.702c-0.206,0.188-0.43-0.12-0.465-0.223
120
		c-0.035-0.102-0.115-0.436,0.071-0.543c0.189-0.107,0.189-0.107,0.189-0.107"/>
121
	<g display="inline">
122
		<g>
123
			<path fill="none" stroke="#C7E0AC" stroke-miterlimit="10" d="M22.625,10.5"/>
124
		</g>
125
	</g>
126
	<g display="inline">
127
		<g>
128
			<path fill="none" stroke="#C7E0AC" stroke-miterlimit="10" d="M21.375,10.583"/>
129
		</g>
130
	</g>
131
</g>
132
<g id="Layer_1">
133
	<path fill="#A2C880" stroke="#375219" stroke-width="1.5" stroke-miterlimit="10" d="M13.501,32.946c0,0-1.134,1.152-1.606,2.804
134
		c-0.327,1.144-0.157,2.62,0.192,3.734c0,0,1.07,0.341,1.415-0.638c0,0,0.763-0.213,0.703-0.808c0,0,0.833,0.17,0.918-0.681
135
		c0.084-0.851,0.374-0.895,0.374-0.895"/>
136
	<path fill="#A2C880" stroke="#375219" stroke-width="1.5" stroke-miterlimit="10" d="M31.215,32.612c0,0,1.135,1.211,1.607,2.945
137
		c0.326,1.202,0.156,2.753-0.192,3.924c0,0-1.069,0.358-1.415-0.67c0,0-0.762-0.224-0.703-0.849c0,0-0.832,0.179-0.918-0.715
138
		c-0.084-0.894-0.374-0.94-0.374-0.94"/>
139
	<path fill="#A2C880" stroke="#375219" stroke-width="1.5" stroke-miterlimit="10" d="M15.262,16.801c0,0-3.549-0.879-5.784,0.031
140
		c0,0-2.184,1.795-3.488,4.573c-1.304,2.778-1.672,5.624-1.686,5.799c0,0-0.181,1.326,0.218,1.991c0,0,0.271,0.771,0.811,0.788
141
		c0,0,0.81,0.329,1.667-1.57c0,0,0.798-0.896,1.115-0.977c0,0,0.759-0.683,1.233-1.528c0,0,0.393-0.864,1.281-1.127
142
		c0,0,0.692-0.291,1.192-1.336c0,0,1.905-0.482,2.011-0.815c0,0,0.083-2.085,0.522-2.77"/>
143
	<path fill="#A2C880" stroke="#375219" stroke-width="1.5" stroke-miterlimit="10" d="M29.764,16.801c0,0,3.549-0.879,5.783,0.031
144
		c0,0,2.184,1.795,3.488,4.573c1.305,2.778,1.672,5.624,1.686,5.799c0,0,0.181,1.326-0.218,1.991c0,0-0.271,0.771-0.811,0.788
145
		c0,0-0.81,0.329-1.667-1.57c0,0-0.799-0.896-1.115-0.977c0,0-0.76-0.683-1.233-1.528c0,0-0.394-0.864-1.281-1.127
146
		c0,0-0.692-0.291-1.192-1.336c0,0-1.904-0.482-2.011-0.815c0,0-0.083-2.085-0.522-2.77"/>
147
	<path fill="#A2C880" stroke="#375219" stroke-width="1.5" stroke-miterlimit="10" d="M20.612,39.122l-0.675-0.185
148
		c0,0,0.912,3,2.3,2.938s2.251-2.787,2.251-2.787"/>
149
	<g>
150
		<path fill="#231F20" d="M11.529,27.122c1.292,8.792,5.583,11.667,9.083,12.5c0,0,2.071,0.563,3.775,0
151
			c3.416-1.13,7.791-3.708,9.084-12.5"/>
152
		<path fill="#231F20" d="M11.529,27.122c-1.292-8.792,6.708-12.958,6.708-12.958c-0.643,0.374,3.453-2.621,8.525,0
153
			c0,0,8,4.166,6.709,12.958"/>
154
	</g>
155
	<g>
156
		<polygon fill="#0C5A85" points="19.688,27.9 17.537,23.66 19.75,19.188 25.5,19 26.938,23.544 24.881,27.9 		"/>
157
	</g>
158
	<path fill="#0C5A85" d="M25.607,18.083l1.629-2.458c0,0-2.021-1.792-4.7-1.625h-0.299c-2.68-0.167-4.701,1.625-4.701,1.625
159
		l1.63,2.458C19.167,18.083,20.84,17.417,25.607,18.083z"/>
160
	<path fill="#0C5A85" d="M32.583,24.292c0.375-3.792-4.5-8.083-4.5-8.083l-2,2.542l1.979,4.312"/>
161
	<path fill="#0C5A85" d="M12.104,24.292c-0.375-3.792,4.5-8.083,4.5-8.083l2,2.542l-1.979,4.312"/>
162
	<path fill="#0C5A85" d="M19.875,29.25h5.069c0,0,0.747,4.892-2.821,4.938C18.556,34.233,19.875,29.25,19.875,29.25z"/>
163
	<path fill="#0C5A85" d="M27.875,24.459l-1.792,3.692c0,0,0.271,1.474,0,2.474s4.75,0.793,5,0.709s1.75-4.334,1.167-5.959"/>
164
	<path fill="#0C5A85" d="M16.312,25l1.098,0.884l0.69,1.27l0.733,1.347c0,0-0.524,1.43-0.271,2.366s-4.691,0.087-4.925,0.009
165
		c-0.234-0.079-1.997-3.919-1.451-5.441"/>
166
	<path fill="#0C5A85" d="M25.573,32.625c0,0,0.734-0.842,5.359-0.259c0,0-2.942,5.717-7.225,6.384c0,0-0.875-2.042-0.458-3.042"/>
167
	<path fill="#0C5A85" d="M18.997,32.625c0,0-0.734-0.842-5.359-0.259c0,0,2.942,5.717,7.225,6.384c0,0,0.875-2.042,0.458-3.042"/>
168
	<path fill="#06334B" d="M16.802,23.372"/>
169
	<g opacity="0.7">
170
		<g>
171
			<path fill="none" stroke="#C7E0AC" stroke-width="0.4" stroke-miterlimit="10" d="M40.125,27.875"/>
172
		</g>
173
	</g>
174
	<g opacity="0.9">
175
		<g>
176
			<path fill="none" stroke="#C7E0AC" stroke-width="0.4" stroke-miterlimit="10" d="M22,41"/>
177
		</g>
178
	</g>
179
	<g>
180
		<g>
181
			<path fill="none" stroke="#C7E0AC" stroke-width="0.4" stroke-miterlimit="10" d="M13,37.062"/>
182
		</g>
183
	</g>
184
	<g>
185
	</g>
186
	<g>
187
	</g>
188
	<g>
189
	</g>
190
	<g>
191
	</g>
192
	<g>
193
	</g>
194
</g>
195
</svg>
turtlesim_ref/include/turtlesim/turtle.h
1
/*
2
 * Copyright (c) 2009, Willow Garage, Inc.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 *     * Redistributions of source code must retain the above copyright
9
 *       notice, this list of conditions and the following disclaimer.
10
 *     * Redistributions in binary form must reproduce the above copyright
11
 *       notice, this list of conditions and the following disclaimer in the
12
 *       documentation and/or other materials provided with the distribution.
13
 *     * Neither the name of the Willow Garage, Inc. nor the names of its
14
 *       contributors may be used to endorse or promote products derived from
15
 *       this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
 * POSSIBILITY OF SUCH DAMAGE.
28
 */
29

  
30
#ifndef TURTLESIM_TURTLE_H
31
#define TURTLESIM_TURTLE_H
32

  
33
// This prevents a MOC error with versions of boost >= 1.48
34
#ifndef Q_MOC_RUN  // See: https://bugreports.qt-project.org/browse/QTBUG-22829
35
# include <ros/ros.h>
36
# include <boost/shared_ptr.hpp>
37

  
38
# include <turtlesim/Pose.h>
39
#include <turtlesim/Velocity.h>
40
# include <turtlesim/SetPen.h>
41
# include <turtlesim/TeleportRelative.h>
42
# include <turtlesim/TeleportAbsolute.h>
43
# include <turtlesim/Color.h>
44
#endif
45

  
46
#include <QImage>
47
#include <QPainter>
48
#include <QPen>
49
#include <QPointF>
50

  
51
#define PI 3.14159265
52

  
53
namespace turtlesim
54
{
55

  
56
class Turtle
57
{
58
public:
59
  Turtle(const ros::NodeHandle& nh, const QImage& turtle_image, const QPointF& pos, float orient);
60

  
61
  bool update(double dt, QPainter& path_painter, const QImage& path_image, qreal canvas_width, qreal canvas_height);
62
  void paint(QPainter &painter);
63
private:
64
  void velocityCallback(const VelocityConstPtr& vel);
65
  bool setPenCallback(turtlesim::SetPen::Request&, turtlesim::SetPen::Response&);
66
  bool teleportRelativeCallback(turtlesim::TeleportRelative::Request&, turtlesim::TeleportRelative::Response&);
67
  bool teleportAbsoluteCallback(turtlesim::TeleportAbsolute::Request&, turtlesim::TeleportAbsolute::Response&);
68

  
69
  void rotateImage();
70

  
71
  ros::NodeHandle nh_;
72

  
73
  QImage turtle_image_;
74
  QImage turtle_rotated_image_;
75

  
76
  QPointF pos_;
77
  qreal orient_;
78

  
79
  qreal lin_vel_;
80
  qreal ang_vel_;
81
  bool pen_on_;
82
  QPen pen_;
83

  
84
  ros::Subscriber velocity_sub_;
85
  ros::Publisher pose_pub_;
86
  ros::Publisher color_pub_;
87
  ros::ServiceServer set_pen_srv_;
88
  ros::ServiceServer teleport_relative_srv_;
89
  ros::ServiceServer teleport_absolute_srv_;
90

  
91
  ros::WallTime last_command_time_;
92

  
93
  float meter_;
94

  
95
  struct TeleportRequest
96
  {
97
    TeleportRequest(float x, float y, qreal _theta, qreal _linear, bool _relative)
98
    : pos(x, y)
99
    , theta(_theta)
100
    , linear(_linear)
101
    , relative(_relative)
102
    {}
103

  
104
    QPointF pos;
105
    qreal theta;
106
    qreal linear;
107
    bool relative;
108
  };
109
  typedef std::vector<TeleportRequest> V_TeleportRequest;
110
  V_TeleportRequest teleport_requests_;
111
};
112
typedef boost::shared_ptr<Turtle> TurtlePtr;
113

  
114
}
115

  
116
#endif
turtlesim_ref/include/turtlesim/turtle_frame.h
1
/*
2
 * Copyright (c) 2009, Willow Garage, Inc.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 *     * Redistributions of source code must retain the above copyright
9
 *       notice, this list of conditions and the following disclaimer.
10
 *     * Redistributions in binary form must reproduce the above copyright
11
 *       notice, this list of conditions and the following disclaimer in the
12
 *       documentation and/or other materials provided with the distribution.
13
 *     * Neither the name of the Willow Garage, Inc. nor the names of its
14
 *       contributors may be used to endorse or promote products derived from
15
 *       this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
 * POSSIBILITY OF SUCH DAMAGE.
28
 */
29

  
30
#include <QFrame>
31
#include <QImage>
32
#include <QPainter>
33
#include <QPaintEvent>
34
#include <QTimer>
35
#include <QVector>
36

  
37
// This prevents a MOC error with versions of boost >= 1.48
38
#ifndef Q_MOC_RUN  // See: https://bugreports.qt-project.org/browse/QTBUG-22829
39
# include <ros/ros.h>
40

  
41
# include <std_srvs/Empty.h>
42
# include <turtlesim/Spawn.h>
43
# include <turtlesim/Kill.h>
44
# include <map>
45

  
46
# include "turtle.h"
47
#endif
48

  
49
namespace turtlesim
50
{
51

  
52
class TurtleFrame : public QFrame
53
{
54
  Q_OBJECT
55
public:
56
  TurtleFrame(QWidget* parent = 0, Qt::WindowFlags f = 0);
57
  ~TurtleFrame();
58

  
59
  std::string spawnTurtle(const std::string& name, float x, float y, float angle);
60

  
61
protected:
62
  void paintEvent(QPaintEvent* event);
63

  
64
private slots:
65
  void onUpdate();
66

  
67
private:
68
  void updateTurtles();
69
  void clear();
70
  bool hasTurtle(const std::string& name);
71

  
72
  bool clearCallback(std_srvs::Empty::Request&, std_srvs::Empty::Response&);
73
  bool resetCallback(std_srvs::Empty::Request&, std_srvs::Empty::Response&);
74
  bool spawnCallback(turtlesim::Spawn::Request&, turtlesim::Spawn::Response&);
75
  bool killCallback(turtlesim::Kill::Request&, turtlesim::Kill::Response&);
76

  
77
  ros::NodeHandle nh_;
78
  QTimer* update_timer_;
79
  QImage path_image_;
80
  QPainter path_painter_;
81

  
82
  uint64_t frame_count_;
83

  
84
  ros::WallTime last_turtle_update_;
85

  
86
  ros::ServiceServer clear_srv_;
87
  ros::ServiceServer reset_srv_;
88
  ros::ServiceServer spawn_srv_;
89
  ros::ServiceServer kill_srv_;
90

  
91
  typedef std::map<std::string, TurtlePtr> M_Turtle;
92
  M_Turtle turtles_;
93
  uint32_t id_counter_;
94

  
95
  QVector<QImage> turtle_images_;
96

  
97
  float meter_;
98
  float width_in_meters_;
99
  float height_in_meters_;
100
};
101

  
102
}
turtlesim_ref/launch/multisim.launch
1
<launch>
2
	<group ns="turtlesim1">
3
	       <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
4
	</group>
5
	<group ns="turtlesim2">
6
	       <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
7
	</group>
8
</launch>
turtlesim_ref/msg/Color.msg
1
uint8 r
2
uint8 g
3
uint8 b
turtlesim_ref/msg/Pose.msg
1
float32 x
2
float32 y
3
float32 theta
4

  
5
float32 linear_velocity
6
float32 angular_velocity
turtlesim_ref/msg/Velocity.msg
1
float32 linear
2
float32 angular
turtlesim_ref/package.xml
1
<?xml version="1.0"?>
2
<package>
3
  <name>turtlesim_ref</name>
4
  <version>0.1.1</version>
5
  <description>
6
    buggysim is derived from turtlesim, and is used for slightly-realistic
7
        buggy simulation for Robobuggy. 
8
  </description>
9
  <maintainer email="msebek@andrew.cmu.edu">Matthew Sebek</maintainer>
10
  <license>BSD</license>
11

  
12
  <!-- Lol just gonna leave these here for now... -->
13
  <url type="website">http://www.ros.org/wiki/turtlesim</url>
14
  <url type="bugtracker">https://github.com/ros/ros_tutorials/issues</url>
15
  <url type="repository">https://github.com/ros/ros_tutorials</url>
16
  <author>Josh Faust</author>
17

  
18
  <buildtool_depend>catkin</buildtool_depend>
19

  
20
  <build_depend>message_generation</build_depend>
21
  <build_depend>libqt4-dev</build_depend>
22
  <build_depend>qt4-qmake</build_depend>
23
  <build_depend>rosconsole</build_depend>
24
  <build_depend>roscpp</build_depend>
25
  <build_depend>roscpp_serialization</build_depend>
26
  <build_depend>roslib</build_depend>
27
  <build_depend>rostime</build_depend>
28
  <build_depend>std_msgs</build_depend>
29
  <build_depend>std_srvs</build_depend>
30

  
31
  <run_depend>libqt4</run_depend>
32
  <run_depend>message_runtime</run_depend>
33
  <run_depend>rosconsole</run_depend>
34
  <run_depend>roscpp</run_depend>
35
  <run_depend>roscpp_serialization</run_depend>
36
  <run_depend>roslib</run_depend>
37
  <run_depend>rostime</run_depend>
38
  <run_depend>std_msgs</run_depend>
39
  <run_depend>std_srvs</run_depend>
40
</package>
turtlesim_ref/src/turtle.cpp
1
/*
2
 * Copyright (c) 2009, Willow Garage, Inc.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 *     * Redistributions of source code must retain the above copyright
9
 *       notice, this list of conditions and the following disclaimer.
10
 *     * Redistributions in binary form must reproduce the above copyright
11
 *       notice, this list of conditions and the following disclaimer in the
12
 *       documentation and/or other materials provided with the distribution.
13
 *     * Neither the name of the Willow Garage, Inc. nor the names of its
14
 *       contributors may be used to endorse or promote products derived from
15
 *       this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
 * POSSIBILITY OF SUCH DAMAGE.
28
 */
29

  
30
#include "turtlesim/turtle.h"
31

  
32
#include <QColor>
33
#include <QRgb>
34

  
35
#define DEFAULT_PEN_R 0xb3
36
#define DEFAULT_PEN_G 0xb8
37
#define DEFAULT_PEN_B 0xff
38

  
39
namespace turtlesim
40
{
41

  
42
Turtle::Turtle(const ros::NodeHandle& nh, const QImage& turtle_image, const QPointF& pos, float orient)
43
: nh_(nh)
44
, turtle_image_(turtle_image)
45
, pos_(pos)
46
, orient_(orient)
47
, lin_vel_(0.0)
48
, ang_vel_(0.0)
49
, pen_on_(true)
50
, pen_(QColor(DEFAULT_PEN_R, DEFAULT_PEN_G, DEFAULT_PEN_B))
51
{
52
  pen_.setWidth(3);
53

  
54
  velocity_sub_ = nh_.subscribe("command_velocity", 1, &Turtle::velocityCallback, this);
55
  pose_pub_ = nh_.advertise<Pose>("pose", 1);
56
  color_pub_ = nh_.advertise<Color>("color_sensor", 1);
57

  
58
  set_pen_srv_ = nh_.advertiseService("set_pen", &Turtle::setPenCallback, this);
59
  teleport_relative_srv_ = nh_.advertiseService("teleport_relative", &Turtle::teleportRelativeCallback, this);
60
  teleport_absolute_srv_ = nh_.advertiseService("teleport_absolute", &Turtle::teleportAbsoluteCallback, this);
61

  
62
  meter_ = turtle_image_.height();
63
  rotateImage();
64
}
65

  
66

  
67
void Turtle::velocityCallback(const VelocityConstPtr& vel)
68
{
69
  last_command_time_ = ros::WallTime::now();
70
  lin_vel_ = vel->linear;
71
  ang_vel_ = vel->angular;
72
}
73

  
74
bool Turtle::setPenCallback(turtlesim::SetPen::Request& req, turtlesim::SetPen::Response&)
75
{
76
  pen_on_ = !req.off;
77
  if (req.off)
78
  {
79
    return true;
80
  }
81

  
82
  QPen pen(QColor(req.r, req.g, req.b));
83
  if (req.width != 0)
84
  {
85
    pen.setWidth(req.width);
86
  }
87

  
88
  pen_ = pen;
89
  return true;
90
}
91

  
92
bool Turtle::teleportRelativeCallback(turtlesim::TeleportRelative::Request& req, turtlesim::TeleportRelative::Response&)
93
{
94
  teleport_requests_.push_back(TeleportRequest(0, 0, req.angular, req.linear, true));
95
  return true;
96
}
97

  
98
bool Turtle::teleportAbsoluteCallback(turtlesim::TeleportAbsolute::Request& req, turtlesim::TeleportAbsolute::Response&)
99
{
100
  teleport_requests_.push_back(TeleportRequest(req.x, req.y, req.theta, 0, false));
101
  return true;
102
}
103

  
104
void Turtle::rotateImage()
105
{
106
  QTransform transform;
107
  transform.rotate(-orient_ * 180.0 / PI + 90.0);
108
  turtle_rotated_image_ = turtle_image_.transformed(transform);
109
}
110

  
111
bool Turtle::update(double dt, QPainter& path_painter, const QImage& path_image, qreal canvas_width, qreal canvas_height)
112
{
113
  bool modified = false;
114
  qreal old_orient = orient_;
115

  
116
  // first process any teleportation requests, in order
117
  V_TeleportRequest::iterator it = teleport_requests_.begin();
118
  V_TeleportRequest::iterator end = teleport_requests_.end();
119
  for (; it != end; ++it)
120
  {
121
    const TeleportRequest& req = *it;
122

  
123
    QPointF old_pos = pos_;
124
    if (req.relative)
125
    {
126
      orient_ += req.theta;
127
      pos_.rx() += std::sin(orient_ + PI/2.0) * req.linear;
128
      pos_.ry() += std::cos(orient_ + PI/2.0) * req.linear;
129
    }
130
    else
131
    {
132
      pos_.setX(req.pos.x());
133
      pos_.setY(std::max(0.0, static_cast<double>(canvas_height - req.pos.y())));
134
      orient_ = req.theta;
135
    }
136

  
137
    path_painter.setPen(pen_);
138
    path_painter.drawLine(pos_ * meter_, old_pos * meter_);
139
    modified = true;
140
  }
141

  
142
  teleport_requests_.clear();
143

  
144
  // Stop moving the turtle if there hasn't been a command sent recently.
145
  if (ros::WallTime::now() - last_command_time_ > ros::WallDuration(1.0))
146
  {
147
    lin_vel_ = 0.0;
148
    ang_vel_ = 0.0;
149
  }
150

  
151
  QPointF old_pos = pos_;
152

  
153
  orient_ = std::fmod(orient_ + ang_vel_ * dt, 2*PI);
154
  pos_.rx() += std::sin(orient_ + PI/2.0) * lin_vel_ * dt;
155
  pos_.ry() += std::cos(orient_ + PI/2.0) * lin_vel_ * dt;
156

  
157
  // Clamp to screen size
158
  if (pos_.x() < 0 || pos_.x() > canvas_width ||
159
      pos_.y() < 0 || pos_.y() > canvas_height)
160
  {
161
    ROS_WARN("Oh no! I hit the wall! (Clamping from [x=%f, y=%f])", pos_.x(), pos_.y());
162
  }
163

  
164
  pos_.setX(std::min(std::max(static_cast<double>(pos_.x()), 0.0), static_cast<double>(canvas_width)));
165
  pos_.setY(std::min(std::max(static_cast<double>(pos_.y()), 0.0), static_cast<double>(canvas_height)));
166

  
167
  // Publish pose of the turtle
168
  Pose p;
169
  p.x = pos_.x();
170
  p.y = canvas_height - pos_.y();
171
  p.theta = orient_;
172
  p.linear_velocity = lin_vel_;
173
  p.angular_velocity = ang_vel_;
174
  pose_pub_.publish(p);
175

  
176
  // Figure out (and publish) the color underneath the turtle
177
  {
178
    Color color;
179
    QRgb pixel = path_image.pixel((pos_ * meter_).toPoint());
180
    color.r = qRed(pixel);
181
    color.g = qGreen(pixel);
182
    color.b = qBlue(pixel);
183
    color_pub_.publish(color);
184
  }
185

  
186
  ROS_DEBUG("[%s]: pos_x: %f pos_y: %f theta: %f", nh_.getNamespace().c_str(), pos_.x(), pos_.y(), orient_);
187

  
188
  if (orient_ != old_orient)
189
  {
190
    rotateImage();
191
    modified = true;
192
  }
193
  if (pos_ != old_pos)
194
  {
195
    if (pen_on_)
196
    {
197
      path_painter.setPen(pen_);
198
      path_painter.drawLine(pos_ * meter_, old_pos * meter_);
199
    }
200
    modified = true;
201
  }
202

  
203
  return modified;
204
}
205

  
206
  // Do the actual painting operations.
207
void Turtle::paint(QPainter& painter)
208
{
209
  QPointF p = pos_ * meter_;
210
  p.rx() -= 0.5 * turtle_rotated_image_.width();
211
  p.ry() -= 0.5 * turtle_rotated_image_.height();
212
  painter.drawImage(p, turtle_rotated_image_);
213
}
214

  
215
}
turtlesim_ref/src/turtle_frame.cpp
1
/*
2
 * Copyright (c) 2009, Willow Garage, Inc.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 *     * Redistributions of source code must retain the above copyright
9
 *       notice, this list of conditions and the following disclaimer.
10
 *     * Redistributions in binary form must reproduce the above copyright
11
 *       notice, this list of conditions and the following disclaimer in the
12
 *       documentation and/or other materials provided with the distribution.
13
 *     * Neither the name of the Willow Garage, Inc. nor the names of its
14
 *       contributors may be used to endorse or promote products derived from
15
 *       this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
 * POSSIBILITY OF SUCH DAMAGE.
28
 */
29

  
30
#include "turtlesim/turtle_frame.h"
31

  
32
#include <QPointF>
33

  
34
#include <ros/package.h>
35
#include <cstdlib>
36
#include <ctime>
37

  
38
#define DEFAULT_BG_R 0x45
39
#define DEFAULT_BG_G 0x56
40
#define DEFAULT_BG_B 0xff
41

  
42
namespace turtlesim
43
{
44

  
45
TurtleFrame::TurtleFrame(QWidget* parent, Qt::WindowFlags f)
46
: QFrame(parent, f)
47
, path_image_(500, 500, QImage::Format_ARGB32)
48
, path_painter_(&path_image_)
49
, frame_count_(0)
50
, id_counter_(0)
51
{
52
  setFixedSize(500, 500);
53
  setWindowTitle("TurtleSim");
54

  
55
  srand(time(NULL));
56

  
57
  update_timer_ = new QTimer(this);
58
  update_timer_->setInterval(16);
59
  update_timer_->start();
60

  
61
  connect(update_timer_, SIGNAL(timeout()), this, SLOT(onUpdate()));
62

  
63
  nh_.setParam("background_r", DEFAULT_BG_R);
64
  nh_.setParam("background_g", DEFAULT_BG_G);
65
  nh_.setParam("background_b", DEFAULT_BG_B);
66

  
67
  QVector<QString> turtles;
68
  turtles.append("box-turtle.png");
69
  turtles.append("robot-turtle.png");
70
  turtles.append("sea-turtle.png");
71
  turtles.append("diamondback.png");
72
  turtles.append("electric.png");
73
  turtles.append("fuerte.png");
74
  turtles.append("groovy.png");
75
  turtles.append("hydro.svg");
76

  
77
  QString images_path = (ros::package::getPath("turtlesim") + "/images/").c_str();
78
  for (size_t i = 0; i < turtles.size(); ++i)
79
  {
80
    QImage img;
81
    img.load(images_path + turtles[i]);
82
    turtle_images_.append(img);
83
  }
84

  
85
  meter_ = turtle_images_[0].height();
86

  
87
  clear();
88

  
89
  clear_srv_ = nh_.advertiseService("clear", &TurtleFrame::clearCallback, this);
90
  reset_srv_ = nh_.advertiseService("reset", &TurtleFrame::resetCallback, this);
91
  spawn_srv_ = nh_.advertiseService("spawn", &TurtleFrame::spawnCallback, this);
92
  kill_srv_ = nh_.advertiseService("kill", &TurtleFrame::killCallback, this);
93

  
94
  ROS_INFO("Starting turtlesim with node name %s", ros::this_node::getName().c_str()) ;
95

  
96
  width_in_meters_ = (width() - 1) / meter_;
97
  height_in_meters_ = (height() - 1) / meter_;
98
  spawnTurtle("", width_in_meters_ / 2.0, height_in_meters_ / 2.0, 0);
99
}
100

  
101
TurtleFrame::~TurtleFrame()
102
{
103
  delete update_timer_;
104
}
105

  
106
bool TurtleFrame::spawnCallback(turtlesim::Spawn::Request& req, turtlesim::Spawn::Response& res)
107
{
108
  std::string name = spawnTurtle(req.name, req.x, req.y, req.theta);
109
  if (name.empty())
110
  {
111
    ROS_ERROR("A turtled named [%s] already exists", req.name.c_str());
112
    return false;
113
  }
114

  
115
  res.name = name;
116

  
117
  return true;
118
}
119

  
120
bool TurtleFrame::killCallback(turtlesim::Kill::Request& req, turtlesim::Kill::Response&)
121
{
122
  M_Turtle::iterator it = turtles_.find(req.name);
123
  if (it == turtles_.end())
124
  {
125
    ROS_ERROR("Tried to kill turtle [%s], which does not exist", req.name.c_str());
126
    return false;
127
  }
128

  
129
  turtles_.erase(it);
130
  update();
131

  
132
  return true;
133
}
134

  
135
bool TurtleFrame::hasTurtle(const std::string& name)
136
{
137
  return turtles_.find(name) != turtles_.end();
138
}
139

  
140
std::string TurtleFrame::spawnTurtle(const std::string& name, float x, float y, float angle)
141
{
142
  std::string real_name = name;
143
  if (real_name.empty())
144
  {
145
    do
146
    {
147
      std::stringstream ss;
148
      ss << "turtle" << ++id_counter_;
149
      real_name = ss.str();
150
    } while (hasTurtle(real_name));
151
  }
152
  else
153
  {
154
    if (hasTurtle(real_name))
155
    {
156
      return "";
157
    }
158
  }
159

  
160
  TurtlePtr t(new Turtle(ros::NodeHandle(real_name), turtle_images_[rand() % turtle_images_.size()], QPointF(x, y), angle));
161
  turtles_[real_name] = t;
162
  update();
163

  
164
  ROS_INFO("Spawning turtle [%s] at x=[%f], y=[%f], theta=[%f]", real_name.c_str(), x, y, angle);
165

  
166
  return real_name;
167
}
168

  
169
void TurtleFrame::clear()
170
{
171
  int r = DEFAULT_BG_R;
172
  int g = DEFAULT_BG_G;
173
  int b = DEFAULT_BG_B;
174

  
175
  nh_.param("background_r", r, r);
176
  nh_.param("background_g", g, g);
177
  nh_.param("background_b", b, b);
178

  
179
  path_image_.fill(qRgb(r, g, b));
180
  update();
181
}
182

  
183
void TurtleFrame::onUpdate()
184
{
185
  ros::spinOnce();
186

  
187
  updateTurtles();
188

  
189
  if (!ros::ok())
190
  {
191
    close();
192
  }
193
}
194

  
195
void TurtleFrame::paintEvent(QPaintEvent* event)
196
{
197
  QPainter painter(this);
198

  
199
  painter.drawImage(QPoint(0, 0), path_image_);
200

  
201
  M_Turtle::iterator it = turtles_.begin();
202
  M_Turtle::iterator end = turtles_.end();
203
  for (; it != end; ++it)
204
  {
205
    it->second->paint(painter);
206
  }
207
}
208

  
209
void TurtleFrame::updateTurtles()
210
{
211
  if (last_turtle_update_.isZero())
212
  {
213
    last_turtle_update_ = ros::WallTime::now();
214
    return;
215
  }
216

  
217
  bool modified = false;
218
  M_Turtle::iterator it = turtles_.begin();
219
  M_Turtle::iterator end = turtles_.end();
220
  for (; it != end; ++it)
221
  {
222
    modified |= it->second->update(0.001 * update_timer_->interval(), path_painter_, path_image_, width_in_meters_, height_in_meters_);
223
  }
224
  if (modified)
225
  {
226
    update();
227
  }
228

  
229
  ++frame_count_;
230
}
231

  
232

  
233
bool TurtleFrame::clearCallback(std_srvs::Empty::Request&, std_srvs::Empty::Response&)
234
{
235
  ROS_INFO("Clearing turtlesim.");
236
  clear();
237
  return true;
238
}
239

  
240
bool TurtleFrame::resetCallback(std_srvs::Empty::Request&, std_srvs::Empty::Response&)
241
{
242
  ROS_INFO("Resetting turtlesim.");
243
  turtles_.clear();
244
  id_counter_ = 0;
245
  spawnTurtle("", width_in_meters_ / 2.0, height_in_meters_ / 2.0, 0);
246
  clear();
247
  return true;
248
}
249

  
250
}
turtlesim_ref/src/turtlesim.cpp
1
/*
2
 * Copyright (c) 2009, Willow Garage, Inc.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 *     * Redistributions of source code must retain the above copyright
9
 *       notice, this list of conditions and the following disclaimer.
10
 *     * Redistributions in binary form must reproduce the above copyright
11
 *       notice, this list of conditions and the following disclaimer in the
12
 *       documentation and/or other materials provided with the distribution.
13
 *     * Neither the name of the Willow Garage, Inc. nor the names of its
14
 *       contributors may be used to endorse or promote products derived from
15
 *       this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
 * POSSIBILITY OF SUCH DAMAGE.
28
 */
29

  
30
#include <QApplication>
31

  
32
#include <ros/ros.h>
33

  
34
#include "turtlesim/turtle_frame.h"
35

  
36
class TurtleApp : public QApplication
37
{
38
public:
39
  ros::NodeHandlePtr nh_;
40

  
41
  TurtleApp(int& argc, char** argv)
42
    : QApplication(argc, argv)
43
  {
44
    ros::init(argc, argv, "turtlesim", ros::init_options::NoSigintHandler);
45
    nh_.reset(new ros::NodeHandle);
46
  }
47

  
48
  int exec()
49
  {
50
    turtlesim::TurtleFrame frame;
51
    frame.show();
52

  
53
    return QApplication::exec();
54
  }
55
};
56

  
57
int main(int argc, char** argv)
58
{
59
  TurtleApp app(argc, argv);
60
  return app.exec();
61
}
62

  
turtlesim_ref/srv/Kill.srv
1
string name
2
---
turtlesim_ref/srv/SetPen.srv
1
uint8 r
2
uint8 g
3
uint8 b
4
uint8 width
5
uint8 off
6
---
turtlesim_ref/srv/Spawn.srv
1
float32 x
2
float32 y
3
float32 theta
4
string name # Optional.  A unique name will be created and returned if this is empty
5
---
6
string name
turtlesim_ref/srv/TeleportAbsolute.srv
1
float32 x
2
float32 y
3
float32 theta
4
---
turtlesim_ref/srv/TeleportRelative.srv
1
float32 linear
2
float32 angular
3
---
turtlesim_ref/tutorials/draw_square.cpp
1
#include <boost/bind.hpp>
2
#include <ros/ros.h>
3
#include <turtlesim/Pose.h>
4
#include <turtlesim/Velocity.h>
5
#include <std_srvs/Empty.h>
6

  
7
turtlesim::PoseConstPtr g_pose;
8
turtlesim::Pose g_goal;
9

  
10
enum State
11
{
12
  FORWARD,
13
  STOP_FORWARD,
14
  TURN,
15
  STOP_TURN,
16
};
17

  
18
State g_state = FORWARD;
19
State g_last_state = FORWARD;
20
bool g_first_goal_set = false;
21

  
22
#define PI 3.141592
23

  
24
void poseCallback(const turtlesim::PoseConstPtr& pose)
25
{
26
  g_pose = pose;
27
}
28

  
29
bool hasReachedGoal()
30
{
31
  return fabsf(g_pose->x - g_goal.x) < 0.1 && fabsf(g_pose->y - g_goal.y) < 0.1 && fabsf(g_pose->theta - g_goal.theta) < 0.01;
32
}
33

  
34
bool hasStopped()
35
{
36
  return g_pose->angular_velocity < 0.0001 && g_pose->linear_velocity < 0.0001;
37
}
38

  
39
void printGoal()
40
{
41
  ROS_INFO("New goal [%f %f, %f]", g_goal.x, g_goal.y, g_goal.theta);
42
}
43

  
44
void commandTurtle(ros::Publisher vel_pub, float linear, float angular)
45
{
46
  turtlesim::Velocity vel;
47
  vel.linear = linear;
48
  vel.angular = angular;
49
  vel_pub.publish(vel);
50
}
51

  
52
void stopForward(ros::Publisher vel_pub)
53
{
54
  if (hasStopped())
55
  {
56
    ROS_INFO("Reached goal");
57
    g_state = TURN;
58
    g_goal.x = g_pose->x;
59
    g_goal.y = g_pose->y;
60
    g_goal.theta = fmod(g_pose->theta + PI/2.0, 2*PI);
61
    printGoal();
62
  }
63
  else
64
  {
65
    commandTurtle(vel_pub, 0, 0);
66
  }
67
}
68

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff