3
3
using Compat
4
4
import Compat: String, Symbol
5
5
6
- export @rosimport , rostypegen, rostypereset, gentypes, cleartypes
6
+ export @rosimport , rostypegen, rostypereset
7
7
8
8
# Type definitions
9
9
# Composite types for internal use. Keeps track of the imported types and helps
@@ -55,7 +55,7 @@ const _ros_builtin_types = Dict{String, Symbol}(
55
55
" string" => :String ,
56
56
" time" => :Time ,
57
57
" duration" => :Duration ,
58
- # Deprecated but supported
58
+ # Deprecated by ROS but supported here
59
59
" char" => :UInt8 ,
60
60
" byte" => :Int8 ,
61
61
)
@@ -65,11 +65,23 @@ const _ros_builtin_types = Dict{String, Symbol}(
65
65
@compat abstract type AbstractSrv end
66
66
@compat abstract type AbstractService end
67
67
68
- # Rearranges the expression into a RobotOS._rosimport call. Input comes in as a
69
- # single package qualified expression, or as a tuple expression where the first
70
- # element is the same as the single expression case. Most of the code is just
71
- # error checking that the input takes that form.
68
+ """
69
+ @rosimport
70
+
71
+ Import ROS message or service types into Julia. Call `rostypegen()` after all `@rosimport` calls.
72
+ Package or type dependencies are also imported automatically as needed.
73
+
74
+ Example usages:
75
+ ```julia
76
+ @rosimport geometry_msgs.msg.PoseStamped
77
+ @rosimport sensor_msgs.msg: Image, Imu
78
+ @rosimport nav_msgs.srv.GetPlan
79
+ ```
80
+ """
72
81
macro rosimport (input)
82
+ # Rearranges the expression into a RobotOS._rosimport call. Input comes in as a single package
83
+ # qualified expression, or as a tuple expression where the first element is the same as the
84
+ # single expression case. Most of the code is just error checking that the input takes that form.
73
85
@assert input. head in [:tuple , :(.), :(:)] " Improper @rosimport input"
74
86
if input. head == :tuple
75
87
@assert isa (input. args[1 ], Expr) " Improper @rosimport input"
@@ -124,8 +136,13 @@ function _rosimport(package::String, ismsg::Bool, names::String...)
124
136
end
125
137
end
126
138
127
- # Do the Julia type generation. This function is needed because we want to
128
- # create the modules in one go, rather than anytime @rosimport gets called
139
+ """
140
+ rostypegen()
141
+
142
+ Initiate the Julia type generation process after importing some ROS types. Creates modules in `Main`
143
+ with the same behavior as imported ROS modules in python. Should only be called once, after all
144
+ `@rosimport` statements are done.
145
+ """
129
146
function rostypegen ()
130
147
global _rospy_imports
131
148
pkgdeps = _collectdeps (_rospy_imports)
@@ -135,9 +152,12 @@ function rostypegen()
135
152
end
136
153
end
137
154
138
- # Reset type generation process to start over with @rosimport. Does not remove
139
- # already generated modules! They will be replaced when rostypegen is called
140
- # again.
155
+ """
156
+ rostypereset()
157
+
158
+ Clear out the previous `@rosimport`s, returning the type generation to its original state. Cannot do
159
+ anything about already generated modules in `Main`.
160
+ """
141
161
function rostypereset ()
142
162
global _rospy_imports
143
163
global _rospy_objects
0 commit comments