Skip to content

Commit

Permalink
Merge pull request #40 from jdlangs/rm_0.6_deprecations
Browse files Browse the repository at this point in the history
Remove deprecations from julia v0.6, drop v0.5 support
  • Loading branch information
jdlangs authored Nov 6, 2017
2 parents ae77284 + 045e686 commit cabcf81
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 70 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: julia
julia:
- 0.5
- 0.6
- nightly
sudo: required
Expand Down
4 changes: 2 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
julia 0.5
julia 0.6
PyCall 1.11.0
Compat 0.17.0
Compat 0.34.0
6 changes: 3 additions & 3 deletions src/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function _callback_notify(handle::Ptr{Void})
ccall(:uv_async_send, Cint, (Ptr{Void},), handle)
end

const CB_NOTIFY_PTR = cfunction(_callback_notify, Cint, (Ptr{Void},))
const CB_NOTIFY_PTR = cfunction(_callback_notify, Cint, Tuple{Ptr{Void}})

function _callback_async_loop(rosobj, cond)
@debug("Spinning up callback loop...")
Expand All @@ -15,14 +15,14 @@ function _callback_async_loop(rosobj, cond)
@debug("Exiting callback loop")
end

function _run_callbacks{M}(sub::Subscriber{M})
function _run_callbacks(sub::Subscriber{M}) where M
while pycall(sub.queue["size"], PyAny) > 0
msg = pycall(sub.queue["get"], PyObject)
sub.callback(convert(M, msg), sub.callback_args...)
end
end

function _run_callbacks{T}(srv::Service{T})
function _run_callbacks(srv::Service{T}) where T
ReqType = _srv_reqtype(T)

req = pycall(srv.cb_interface["get_request"], PyObject)
Expand Down
35 changes: 16 additions & 19 deletions src/gentypes.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#Generate Julia composite types for ROS messages

using Compat
import Compat: String, Symbol
using PyCall

export @rosimport, rostypegen, rostypereset

#Type definitions
#Composite types for internal use. Keeps track of the imported types and helps
#keep code generation orderly.
@compat abstract type ROSModule end
type ROSPackage
abstract type ROSModule end
mutable struct ROSPackage
name::String
msg::ROSModule
srv::ROSModule
Expand All @@ -21,13 +19,13 @@ type ROSPackage
pkg
end
end
type ROSMsgModule <: ROSModule
struct ROSMsgModule <: ROSModule
pkg::ROSPackage
members::Vector{String}
deps::Set{String}
ROSMsgModule(pkg) = new(pkg, String[], Set{String}())
end
type ROSSrvModule <: ROSModule
struct ROSSrvModule <: ROSModule
pkg::ROSPackage
members::Vector{String}
deps::Set{String}
Expand Down Expand Up @@ -62,9 +60,9 @@ const _ros_builtin_types = Dict{String, Symbol}(
)

#Abstract supertypes of all generated types
@compat abstract type AbstractMsg end
@compat abstract type AbstractSrv end
@compat abstract type AbstractService end
abstract type AbstractMsg end
abstract type AbstractSrv end
abstract type AbstractService end

"""
@rosimport
Expand Down Expand Up @@ -103,6 +101,7 @@ end

_get_quote_value(input::QuoteNode) = input.value
_get_quote_value(input::Expr) = (@assert input.head == :quote; input.args[1])

#Return the pkg and types strings for a single expression of form:
# pkg.[msg|srv].type or pkg.[msg|srv]:type
function _pkgtype_import(input::Expr)
Expand Down Expand Up @@ -316,8 +315,6 @@ function modulecode(mod::ROSModule)
#Common imports
push!(modcode,
quote
using Compat
import Compat: String, Symbol
using PyCall
import Base: convert, getindex
import RobotOS
Expand Down Expand Up @@ -417,7 +414,7 @@ function buildtype(mod::ROSSrvModule, typename::String)
reqsym = Symbol(string(typename,"Request"))
respsym = Symbol(string(typename,"Response"))
srvexprs = Expr[
:(immutable $defsym <: AbstractService end),
:(struct $defsym <: AbstractService end),
:(_typerepr(::Type{$defsym}) = $(_rostypestr(mod,typename))),
:(_srv_reqtype(::Type{$defsym}) = $reqsym),
:(_srv_resptype(::Type{$defsym}) = $respsym),
Expand Down Expand Up @@ -447,7 +444,7 @@ function typecode(rosname::String, super::Symbol, members::Vector)
#First the empty expressions
#(1) Type declaration
push!(exprs, :(
type $jlsym <: $super
mutable struct $jlsym <: $super
#Generated code here
end
))
Expand All @@ -473,7 +470,7 @@ function typecode(rosname::String, super::Symbol, members::Vector)
push!(exprs, :(
function convert(jlt::Type{$jlsym}, o::PyObject)
if convert(String, o["_type"]) != _typerepr(jlt)
throw(InexactError())
throw(InexactError(:convert, $jlsym, o))
end
jl = $jlsym()
#Generated code here
Expand Down Expand Up @@ -557,7 +554,7 @@ end

#Build a String => Iterable{String} object from the individual package
#dependencies.
function _collectdeps{S<:AbstractString}(pkgs::Dict{S, ROSPackage})
function _collectdeps(pkgs::Dict{S, ROSPackage}) where S <: AbstractString
deps = Dict{S, Set{S}}()
for pname in keys(pkgs)
if ! haskey(deps, pname)
Expand Down Expand Up @@ -654,18 +651,18 @@ _jl_safe_name(name::AbstractString, suffix) = _nameconflicts(name) ?
_nameconflicts(typename::String) = isdefined(Base, Symbol(typename))

#Get a default value for any builtin ROS type
_typedefault{T<:Real}(::Type{T}) = zero(T)
_typedefault(::Type{T}) where {T <: Real} = zero(T)
_typedefault(::Type{String}) = ""
_typedefault(::Type{Time}) = Time(0,0)
_typedefault(::Type{Duration}) = Duration(0,0)

#Default method to get the "pkg/type" string from a generated DataType.
#Extended by the generated modules.
_typerepr{T}(::Type{T}) = error("Not a ROS type")
_typerepr(::Type{T}) where {T} = error("Not a ROS type")

#Default method to get the request/response datatypes for a generated service
_srv_reqtype{T}( ::Type{T}) = error("Not a ROS Service type")
_srv_resptype{T}(::Type{T}) = error("Not a ROS Service type")
_srv_reqtype( ::Type{T}) where {T} = error("Not a ROS Service type")
_srv_resptype(::Type{T}) where {T} = error("Not a ROS Service type")

#Accessors for the package name
_name(p::ROSPackage) = p.name
Expand Down
18 changes: 8 additions & 10 deletions src/pubsub.jl
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
#API for publishing and subscribing to message topics
export Publisher, Subscriber, publish

using Compat

"""
Publisher{T}(topic; kwargs...)
Publisher(topic, T; kwargs...)
Create an object to publish messages of type `T` on a topic. Keyword arguments are directly passed
to rospy.
"""
type Publisher{MsgType<:AbstractMsg}
struct Publisher{MsgType<:AbstractMsg}
o::PyObject

@compat function (::Type{Publisher{MT}}){MT <: AbstractMsg}(topic::AbstractString; kwargs...)
function Publisher{MT}(topic::AbstractString; kwargs...) where MT <: AbstractMsg
@debug("Creating <$(string(MT))> publisher on topic: '$topic'")
rospycls = _get_rospy_class(MT)
return new{MT}(__rospy__[:Publisher](ascii(topic), rospycls; kwargs...))
end
end

Publisher{MT<:AbstractMsg}(topic::AbstractString, ::Type{MT}; kwargs...) =
Publisher(topic::AbstractString, ::Type{MT}; kwargs...) where {MT <: AbstractMsg} =
Publisher{MT}(ascii(topic); kwargs...)

"""
publish(p::Publisher{T}, msg::T)
Publish `msg` on `p`, a `Publisher` with matching message type.
"""
function publish{MT<:AbstractMsg}(p::Publisher{MT}, msg::MT)
function publish(p::Publisher{MT}, msg::MT) where MT <: AbstractMsg
pycall(p.o["publish"], PyAny, convert(PyObject, msg))
end

Expand All @@ -40,16 +38,16 @@ Create a subscription to a topic with message type `T` with a callback to use wh
received, which can be any callable type. Extra arguments provided to the callback when invoked
can be provided in the `cb_args` tuple. Keyword arguments are directly passed to rospy.
"""
type Subscriber{MsgType<:AbstractMsg}
mutable struct Subscriber{MsgType<:AbstractMsg}
callback
callback_args::Tuple
sub_obj::PyObject
queue::PyObject
async_loop::Task

@compat function (::Type{Subscriber{MT}}){MT <: AbstractMsg}(
function Subscriber{MT}(
topic::AbstractString, cb, cb_args::Tuple=(); kwargs...
)
) where MT <: AbstractMsg
@debug("Creating <$(string(MT))> subscriber on topic: '$topic'")
rospycls = _get_rospy_class(MT)

Expand All @@ -66,6 +64,6 @@ type Subscriber{MsgType<:AbstractMsg}
end
end

function Subscriber{MT<:AbstractMsg}(topic, ::Type{MT}, cb, cb_args::Tuple=(); kwargs...)
function Subscriber(topic, ::Type{MT}, cb, cb_args::Tuple=(); kwargs...) where MT <: AbstractMsg
Subscriber{MT}(topic, cb, cb_args; kwargs...)
end
22 changes: 7 additions & 15 deletions src/services.jl
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
#API for calling/creating services. Syntax is practically identical to rospy.
export Service, ServiceProxy, wait_for_service

using Compat

"""
ServiceProxy{T}(name; kwargs...)
ServiceProxy(name, T; kwargs...)
Create a proxy object used to invoke a remote service. Use `srv_proxy(msg_request)` with the object
to invoke the service call. Keyword arguments are directly passed to rospy.
"""
type ServiceProxy{SrvType <: AbstractService}
struct ServiceProxy{SrvType <: AbstractService}
o::PyObject

@compat function (::Type{ServiceProxy{ST}}){ST <: AbstractService}(
name::AbstractString; kwargs...
)
function ServiceProxy{ST}(name::AbstractString; kwargs...) where ST <: AbstractService
@debug("Creating <$ST> service proxy for '$name'")
rospycls = _get_rospy_class(ST)
new{ST}(__rospy__[:ServiceProxy](ascii(name), rospycls; kwargs...))
end
end

function ServiceProxy{ST<:AbstractService}(name::AbstractString, srv::Type{ST}; kwargs...)
function ServiceProxy(name::AbstractString, srv::Type{ST}; kwargs...) where ST <: AbstractService
ServiceProxy{ST}(ascii(name); kwargs...)
end

@compat function (srv::ServiceProxy{ST}){ST <: AbstractService}(
req::AbstractSrv
)
function (srv::ServiceProxy{ST})(req::AbstractSrv) where ST <: AbstractService
if ! isa(req, _srv_reqtype(ST))
throw(ArgumentError(
string("Incorrect service request type: ", typeof(req),
Expand All @@ -46,15 +40,13 @@ end
Create a service object that can receive requests and provide responses. The callback can be of
any callable type. Keyword arguments are directly passed to rospy.
"""
type Service{SrvType <: AbstractService}
mutable struct Service{SrvType <: AbstractService}
handler
srv_obj::PyObject
cb_interface::PyObject
async_loop::Task

@compat function (::Type{Service{ST}}){ST <: AbstractService}(
name::AbstractString, handler; kwargs...
)
function Service{ST}(name::AbstractString, handler; kwargs...) where ST <: AbstractService
@debug("Providing <$ST> service at '$name'")
rospycls = _get_rospy_class(ST)

Expand All @@ -81,7 +73,7 @@ type Service{SrvType <: AbstractService}
end
end

function Service{ST<:AbstractService}(name::AbstractString, srv::Type{ST}, handler; kwargs...)
function Service(name::AbstractString, srv::Type{ST}, handler; kwargs...) where ST <: AbstractService
Service{ST}(ascii(name), handler; kwargs...)
end

Expand Down
20 changes: 9 additions & 11 deletions src/time.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#All time related types and functions

using Compat

import Base: convert, isless, sleep, +, -, *, ==
export Time, Duration, Rate, to_sec, to_nsec, get_rostime, rossleep

#Time type definitions
@compat abstract type TVal end
abstract type AbstractTime end

"""
Time(secs, nsecs), Time(), Time(t::Real)
Expand All @@ -17,7 +15,7 @@ Basic arithmetic can be performed on combinations of `Time` and `Duration` objec
For example, if `t::Time` and `d::Duration`, `t+d` will be a `Time`, `d+d` a `Duration`, `t-d` a
`Time`, `d-d` a `Duration`, and `t-t` a `Duration`.
"""
immutable Time <: TVal
struct Time <: AbstractTime
secs::Int32
nsecs::Int32
function Time(s::Real,n::Real)
Expand All @@ -37,7 +35,7 @@ Basic arithmetic can be performed on combinations of `Time` and `Duration` objec
For example, if `t::Time` and `d::Duration`, `t+d` will be a `Time`, `d+d` a `Duration`, `t-d` a
`Time`, `d-d` a `Duration`, and `t-t` a `Duration`.
"""
immutable Duration <: TVal
struct Duration <: AbstractTime
secs::Int32
nsecs::Int32
function Duration(s::Real,n::Real)
Expand Down Expand Up @@ -84,19 +82,19 @@ convert(::Type{PyObject}, t::Duration) = __rospy__[:Duration](t.secs,t.nsecs)
Return the value of a ROS time object in absolute seconds (with nanosecond precision)
"""
to_sec{T<:TVal}(t::T) = t.secs + 1e-9*t.nsecs
to_sec(t::T) where {T <: AbstractTime} = t.secs + 1e-9*t.nsecs

"""
to_nsec(t)
Return the value of a ROS time object in nanoseconds as an integer.
"""
to_nsec{T<:TVal}(t::T) = 1_000_000_000*t.secs + t.nsecs
convert{T<:TVal}(::Type{Float64}, t::T) = to_sec(t)
to_nsec(t::T) where {T <: AbstractTime} = 1_000_000_000*t.secs + t.nsecs
convert(::Type{Float64}, t::T) where {T <: AbstractTime} = to_sec(t)

#Comparisons
=={T<:TVal}(t1::T, t2::T) = (t1.secs == t2.secs) && (t1.nsecs == t2.nsecs)
isless{T<:TVal}(t1::T, t2::T) = to_nsec(t1) < to_nsec(t2)
==(t1::T, t2::T) where {T <: AbstractTime} = (t1.secs == t2.secs) && (t1.nsecs == t2.nsecs)
isless(t1::T, t2::T) where {T <: AbstractTime} = to_nsec(t1) < to_nsec(t2)

"""
Rate(hz::Real), Rate(d::Duration)
Expand All @@ -105,7 +103,7 @@ Used to allow a loop to run at a fixed rate. Construct with a frequency or `Dura
`rossleep` or `sleep`. The rate object will record execution time of other work in the loop and
modify the sleep time to compensate, keeping the loop rate as consistent as possible.
"""
type Rate
mutable struct Rate
duration::Duration
last_time::Time
end
Expand Down
2 changes: 1 addition & 1 deletion test/pubsub.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ros_pub = Publisher("vectors", Vector3, queue_size = 10)
rossleep(Duration(3.0))

function publish_messages(pubobj, msgs, rate_hz)
const r = Rate(rate_hz)
r = Rate(rate_hz)
for msg in msgs
publish(pubobj, msg)
rossleep(r)
Expand Down
6 changes: 2 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Base.Test
using Compat.Test
using PyCall
using RobotOS
using Compat
RobotOS.debug(true)

#Generally, later tests rely on things defined in previous tests, so the order
#is important
#Generally, later tests rely on things defined in previous tests, so the order is important
include("rospy.jl")
include("time.jl")
include("typegeneration.jl")
Expand Down
Loading

0 comments on commit cabcf81

Please sign in to comment.