33using Compat
44import Compat: String, Symbol
55
6- export @rosimport , rostypegen, rostypereset, gentypes, cleartypes
6+ export @rosimport , rostypegen, rostypereset
77
88# Type definitions
99# Composite types for internal use. Keeps track of the imported types and helps
@@ -55,7 +55,7 @@ const _ros_builtin_types = Dict{String, Symbol}(
5555 " string" => :String ,
5656 " time" => :Time ,
5757 " duration" => :Duration ,
58- # Deprecated but supported
58+ # Deprecated by ROS but supported here
5959 " char" => :UInt8 ,
6060 " byte" => :Int8 ,
6161 )
@@ -65,11 +65,23 @@ const _ros_builtin_types = Dict{String, Symbol}(
6565@compat abstract type AbstractSrv end
6666@compat abstract type AbstractService end
6767
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+ """
7281macro 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.
7385 @assert input. head in [:tuple , :(.), :(:)] " Improper @rosimport input"
7486 if input. head == :tuple
7587 @assert isa (input. args[1 ], Expr) " Improper @rosimport input"
@@ -124,8 +136,13 @@ function _rosimport(package::String, ismsg::Bool, names::String...)
124136 end
125137end
126138
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+ """
129146function rostypegen ()
130147 global _rospy_imports
131148 pkgdeps = _collectdeps (_rospy_imports)
@@ -135,9 +152,12 @@ function rostypegen()
135152 end
136153end
137154
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+ """
141161function rostypereset ()
142162 global _rospy_imports
143163 global _rospy_objects
0 commit comments