Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refac toImage #19

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ext/PyCaesarRobotOSExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ using StaticArrays

# dont load Caesar until after rostypegen
using Caesar
# import Caesar: unmarshal

import Base: convert

# FIXME DEPRECATE UPGRADE TBD
import Unmarshal: unmarshal
# import Caesar: unmarshal

import Caesar._PCL as _PCL

import Base: convert
import Caesar: toImage

# weakdeps type and memver prototype import for overwritten definition pattern
import PyCaesar: RosbagSubscriber, RosbagWriter
import PyCaesar: loop!, getROSPyMsgTimestamp, nanosecond2datetime
import PyCaesar: handleMsg!, handleMsg_OVRLPRECOMP!
import PyCaesar: toImage, toROSImage

##

Expand Down
48 changes: 48 additions & 0 deletions ext/services/ROSConversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,51 @@ function unmarshal(
end



function unmarshal(
msg::sensor_msgs.msg.Image
)
Dict{String,Any}(
"width" => Int(msg.width),
"height" => Int(msg.height),
"step" => Int(msg.step),
"data" => msg.data, # base64encode(
"encoding" => msg.encoding,
"is_bigendian" => msg.is_bigendian === 0x01,
"header" => unmarshal(msg.header),
"_type" => "ROS1/sensor_msgs/Image",
"description" => "Caesar.toImage(JSON.parse(jstr))"
)
end


toImage(msg::sensor_msgs.msg.Image) = unmarshal(msg) |> toImage


"""
$SIGNATURES

Convert `Caesar.Image::Dict` type to ROS message `sensor_msgs.msg.Image`.

See also: [`Caesar.unmarshal`](@ref), [`Caesar.toImage`](@ref), [`Caesar._PCL.toROSPointCloud2`](@ref)
"""
function toROSImage(msgd::Dict{String,Any})
header = std_msgs.msg.Header();
header.seq = msgd["header"]["seq"]
header.stamp = RobotOS.Time(msgd["header"]["stamp"]["secs"], msgd["header"]["stamp"]["nsecs"])
header.frame_id = msgd["header"]["frame_id"]

msg = sensor_msgs.msg.Image();

msg.header = header
msg.height = UInt32(msgd["height"])
msg.width = UInt32(msgd["width"])

msg.is_bigendian = UInt8(msgd["is_bigendian"])
msg.step = UInt32(msgd["step"])
msg.data = UInt8.(msgd["data"]) # base64decode( )
msg.encoding = msgd["encoding"]

msg
end
#
3 changes: 2 additions & 1 deletion ext/services/WeakdepsPrototypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ function handleMsg! end
function handleMsg_OVRLPRECOMP! end
function loop! end
function getROSPyMsgTimestamp end
function nanosecond2datetime end
function nanosecond2datetime end
function toROSImage end