Skip to content

Commit 7ddd2af

Browse files
committed
ROS service type generation and API
Squashed merge commit from the 'srv' branch
1 parent d0c5169 commit 7ddd2af

17 files changed

+779
-302
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ language: julia
22
julia:
33
- release
44
- nightly
5+
56
before_install:
67
- sudo apt-add-repository -y "deb http://packages.ros.org/ros/ubuntu precise main"
78
- wget https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -O - | sudo apt-key add -
@@ -14,7 +15,7 @@ before_script:
1415
- source /opt/ros/hydro/setup.sh
1516
- roscore &
1617
- sleep 5
17-
- python test/republish.py &
18+
- python test/echonode.py &
1819
- sleep 5
1920
after_script:
2021
- killall roscore

README.md

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
### Description
88

99
This package enables interfacing Julia code with a ROS ([Robot Operating
10-
System](http://wiki.ros.org)) system. It works by generating native Julia types for
11-
ROS messages, the same as in C++ or Python, and then wrapping rospy through the
12-
PyCall package to get communication through topics and parameters.
10+
System](http://wiki.ros.org)) system. It works by generating native Julia types
11+
for ROS types, the same as in C++ or Python, and then wrapping rospy through
12+
the PyCall package to get communication through topics, services, and
13+
parameters.
1314

1415
### Installation
1516

@@ -28,18 +29,18 @@ directly to version 1.0.
2829

2930
## Usage: Type Generation
3031

31-
ROS message types are brought into your program with the `@rosimport` macro
32-
which specifies a package and one or more types. The three valid forms can be
33-
seen here:
32+
ROS types are brought into your program with the `@rosimport` macro which
33+
specifies a package and one or more types. The three valid syntax forms can be
34+
seen in these examples:
3435

3536
@rosimport std_msgs.msg.Header
36-
@rosimport geometry_msgs.msg: PoseStamped
37-
@rosimport sensor_msgs.msg: Imu, Image
37+
@rosimport nav_msgs.srv: GetPlan
38+
@rosimport geometry_msgs.msg: PoseStamped, Vector3
3839

39-
`@rosimport` will bring in the python modules for the requested type and all
40+
`@rosimport` will import the python modules for the requested type and all
4041
its dependencies but the native Julia types are not created yet since any
4142
inter-module dependencies have to be resolved first. After the final
42-
`@rosimport` call, initiate the message generation with:
43+
`@rosimport` call, initiate the type generation with:
4344

4445
rostypegen()
4546

@@ -125,6 +126,20 @@ example:
125126
sub2 = Subscriber{Imu}("topic", cb2, queue_size = 10)
126127
spin()
127128

129+
### Using services
130+
131+
ROS services are fully supported, including automatic request and response type
132+
generation. For the `@rosimport` call, use the plain service type name. After
133+
`rostypegen()`, the generated `.srv` submodule will contain 3 types: the plain
134+
type, a request type, and a response type. For example `GetPlan`,
135+
`GetPlanRequest`, and `GetPlanResponse`. To provide the service to other nodes,
136+
you would create a `Service{GetPlan}` object. To call it, a
137+
`ServiceProxy{GetPlan}` object. The syntax exactly matches rospy to construct
138+
and use these objects. The only exception is in Julia v0.3, where the `call`
139+
method is not overloaded for objects. In that case, you must call the
140+
`ServiceProxy` via `call(myproxy, myreq)` instead of the rospy method of
141+
`myproxy(myreq)` which works in later versions of Julia.
142+
128143
### Parameter Server
129144

130145
`get_param`, `set_param`, `has_param`, and `delete_param` are all implemented
@@ -165,19 +180,29 @@ republishes them as Points.
165180
rostypegen()
166181
using geometry_msgs.msg
167182

168-
callback(msg::Pose2D, pub_obj::Publisher{Point}) = begin
183+
function callback(msg::Pose2D, pub_obj::Publisher{Point})
169184
pt_msg = Point(msg.x, msg.y, 0.0)
170185
publish(pub_obj, pt_msg)
171186
end
172-
pub = Publisher{Point}("pts", queue_size=10)
173-
sub = Subscriber{Pose2D}("pose", callback, (pub,), queue_size=10)
174-
175-
init_node("rosjl_example")
176-
loop_rate = Rate(5.0)
177-
while ! is_shutdown()
178-
npt = Point(rand(), rand(), 0.0)
179-
publish(pub, npt)
180-
sleep(loop_rate)
187+
188+
function loop(pub_obj)
189+
loop_rate = Rate(5.0)
190+
while ! is_shutdown()
191+
npt = Point(rand(), rand(), 0.0)
192+
publish(pub_obj, npt)
193+
sleep(loop_rate)
194+
end
195+
end
196+
197+
function main()
198+
init_node("rosjl_example")
199+
pub = Publisher{Point}("pts", queue_size=10)
200+
sub = Subscriber{Pose2D}("pose", callback, (pub,), queue_size=10)
201+
loop(pub)
202+
end
203+
204+
if ! isinteractive()
205+
main()
181206
end
182207

183208
## Versions

deps/build.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#Temp hack because PyCall's current release doesn't work at all on v0.4
2+
Pkg.checkout("PyCall")

src/RobotOS.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
module RobotOS
22

3-
#Interior code can use this macro for debugging output
4-
macro debug(expr, other...)
5-
:(if _debug_output println($expr,$(other...)) end)
6-
end
7-
_debug_output = false
8-
debug(d::Bool) = global _debug_output = d
9-
103
using PyCall
114
const __rospy__ = try
125
pywrap(pyimport("rospy"))
@@ -20,9 +13,11 @@ end
2013
py_sys = pyimport("sys")
2114
py_sys["argv"] = ARGS
2215

16+
include("debug.jl")
2317
include("time.jl")
2418
include("gentypes.jl")
2519
include("rospy.jl")
2620
include("pubsub.jl")
21+
include("services.jl")
2722

2823
end

src/debug.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#Debugging helper utils
2+
_debug_output = false
3+
_debug_indent = 0
4+
debug(d::Bool) = global _debug_output = d
5+
macro debug(expr, other...)
6+
:(if _debug_output
7+
print(repeat("\t", _debug_indent))
8+
println($expr,$(other...))
9+
end)
10+
end
11+
macro debug_addindent()
12+
:(global _debug_indent += 1)
13+
end
14+
macro debug_subindent()
15+
:(global _debug_indent -= 1)
16+
end
17+

0 commit comments

Comments
 (0)