Skip to content

Commit f65330c

Browse files
committed
PointCloud converter good enough for 2D Radar
1 parent 6c28418 commit f65330c

File tree

5 files changed

+96
-25
lines changed

5 files changed

+96
-25
lines changed

examples/marine/asv/philos/IngestROSbag.jl

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ using DistributedFactorGraphs.DocStringExtensions
6161
using Dates
6262
using JSON2
6363
using BSON
64+
using Serialization
6465
using FixedPointNumbers
6566
using StaticArrays
6667

@@ -161,6 +162,7 @@ function handleRadarPointcloud!(msg::sensor_msgs.msg.PointCloud2, fg::AbstractDF
161162
# pc = Caesar._PCL.PointCloud(; height=md.height, width=md.width)
162163

163164
queueScans[i] = (pc2,pc_)
165+
# queueScans[i] = pc_
164166
end
165167

166168
# add a new variable to the graph
@@ -170,7 +172,7 @@ function handleRadarPointcloud!(msg::sensor_msgs.msg.PointCloud2, fg::AbstractDF
170172
systemstate.var_index += 1
171173

172174
io = IOBuffer()
173-
BSON.@save io queueScans
175+
serialize(io, queueScans)
174176

175177
# @show datablob = pc # queueScans
176178
# and add a data blob of all the scans
@@ -179,7 +181,7 @@ function handleRadarPointcloud!(msg::sensor_msgs.msg.PointCloud2, fg::AbstractDF
179181
take!(io), # get base64 binary
180182
# Vector{UInt8}(JSON2.write(datablob)),
181183
mimeType="/application/octet-stream/bson;dataformat=Vector{Caesar._PCL.PCLPointCloud2}",
182-
description="BSON.@load PipeBuffer(readBytes) queueScans")
184+
description="queueScans = Serialize.deserialize(PipeBuffer(readBytes))")
183185
#
184186
end
185187

@@ -354,7 +356,39 @@ addBlobStore!(fg, ds)
354356

355357
de,db = getData(fg, :x0, :RADARPC)
356358

357-
BSON.@load PipeBuffer(db) queueScans
359+
queueScans = deserialize(PipeBuffer(db)) # BSON.@load
358360

359-
queueScans[1]
361+
pc2,pc = queueScans[1]
360362

363+
##
364+
365+
using Gadfly
366+
Gadfly.set_default_plot_size(40cm,20cm)
367+
368+
##
369+
370+
371+
PL = []
372+
373+
for lb in [:x0;:x1;:x2;:x3;:x4;:x5]
374+
de,db = getData(fg, lb, :RADARPC)
375+
queueScans = deserialize(PipeBuffer(db))
376+
for (pc2,pc) in queueScans
377+
X = (c->c.x).(pc.points)
378+
Y = (c->c.y).(pc.points)
379+
push!(PL, Gadfly.layer(x=X,y=Y, Geom.point))
380+
end
381+
end
382+
383+
Gadfly.plot(PL...)
384+
385+
##
386+
387+
388+
389+
390+
391+
392+
393+
394+
##

src/3rdParty/_PCL/entities/PCLTypes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ See
109109
- https://pointclouds.org/documentation/point__types_8hpp_source.html
110110
"""
111111
Base.@kwdef struct PointXYZ{C <: Colorant, T <: Number} <: PointT
112-
color::C = RGB(1,1,1)
112+
color::C = RGBA(1,1,1,1)
113113
data::SVector{4,T} = SVector(0,0,0,1f0)
114114
end
115115

src/3rdParty/_PCL/services/ROSConversions.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Base.convert(::Type{UInt64}, rost::RobotOS.Time) = UInt64(rost.secs)*1000000 + t
1414
# Really odd constructor, strong assumption that user FIRST ran @rostypegen in Main BEFORE loading Caesar
1515
# https://docs.ros.org/en/hydro/api/pcl_conversions/html/pcl__conversions_8h_source.html#l00208
1616
function PCLPointCloud2(msg::Main.sensor_msgs.msg.PointCloud2)
17-
@warn("work in progress on PCLPointCloud2(msg::Main.sensor_msgs.msg.PointCloud2)")
1817
header = Header(;stamp = msg.header.stamp,
1918
seq = msg.header.seq,
2019
frame_id= msg.header.frame_id )

test/pcl/testPointCloud2.jl

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,81 @@ using BSON
1313
using Test
1414
using Pkg
1515

16-
import Caesar._PCL: FieldMapper, createMapping, PointCloud, PointField, PCLPointCloud2, Header, asType, _PCL_POINTFIELD_FORMAT, FieldMapping, MsgFieldMap, FieldMatches
16+
# import Caesar._PCL: FieldMapper, createMapping, PointCloud, PointField, PCLPointCloud2, Header, asType, _PCL_POINTFIELD_FORMAT, FieldMapping, MsgFieldMap, FieldMatches
1717

1818

1919
##
2020
@testset "test Caesar._PCL.PCLPointCloud2 to Caesar._PCL.PointCloud converter." begin
2121
##
2222

23-
testdatafile = joinpath( dirname(dirname(Pkg.pathof(Caesar))), "test", "testdata", "_PCLPointCloud2.bson")
24-
23+
# testdatafile = joinpath( dirname(dirname(Pkg.pathof(Caesar))), "test", "testdata", "_PCLPointCloud2.bson")
2524
# load presaved test data to test the coverter
26-
BSON.@load testdatafile PointCloudRef PointCloudTest
25+
# BSON.@load testdatafile PointCloudRef PointCloudTest
26+
27+
## build PCLPointCloud2 to be converted
28+
29+
datafile = joinpath( dirname(dirname(Pkg.pathof(Caesar))), "test", "testdata", "_PCLPointCloud2_15776.dat")
30+
fid = open(datafile,"r")
31+
data = read(fid)
32+
close(fid)
33+
34+
##
35+
36+
pc2 = Caesar._PCL.PCLPointCloud2(;
37+
header = Caesar._PCL.Header(;
38+
seq = 92147,
39+
stamp = 0x0005b24647c4af10,
40+
frame_id = "velodyne"
41+
),
42+
height = 1,
43+
width = 493,
44+
fields = [
45+
Caesar._PCL.PointField("x", 0x00000000, Caesar._PCL._PCL_FLOAT32, 0x00000001),
46+
Caesar._PCL.PointField("y", 0x00000004, Caesar._PCL._PCL_FLOAT32, 0x00000001),
47+
Caesar._PCL.PointField("z", 0x00000008, Caesar._PCL._PCL_FLOAT32, 0x00000001),
48+
Caesar._PCL.PointField("intensity", 0x00000010, Caesar._PCL._PCL_FLOAT32, 0x00000001)
49+
],
50+
point_step = 32,
51+
row_step = 15776,
52+
is_dense = 1,
53+
data
54+
)
55+
2756

28-
show(PointCloudTest[1])
57+
##
58+
59+
show(pc2)
2960

3061
# test major unpacking / type conversion needed by ROS.sensor_msgs.pointcloud2
31-
pc = Caesar._PCL.PointCloud(PointCloudTest[1])
62+
pc = Caesar._PCL.PointCloud(pc2)
63+
64+
show(pc)
3265

3366
@test pc.height == 1
3467
@test pc.width == 493
3568
@test pc.is_dense
3669

37-
@test_broken length(pc.points) == 493
70+
@test length(pc.points) == 493
71+
72+
##
73+
74+
# truncated copy of reference data on good to 1e-3
75+
@test isapprox( [-0,0,0], pc.points[1].data[1:3], atol=5e-3)
76+
@test isapprox( [-1.56486,1.09851,0], pc.points[2].data[1:3], atol=5e-3)
77+
@test isapprox( [-793.383,556.945,0], pc.points[3].data[1:3], atol=5e-3)
78+
@test isapprox( [-0,0,0], pc.points[4].data[1:3], atol=5e-3)
79+
@test isapprox( [-1.56148,1.10331,0], pc.points[5].data[1:3], atol=5e-3)
80+
@test isapprox( [-788.548,557.169,0], pc.points[6].data[1:3], atol=5e-3)
81+
@test isapprox( [-790.109,558.273,0], pc.points[7].data[1:3], atol=5e-3)
82+
@test isapprox( [-791.671,559.376,0], pc.points[8].data[1:3], atol=5e-3)
83+
@test isapprox( [-793.232,560.479,0], pc.points[9].data[1:3], atol=5e-3)
84+
@test isapprox( [-794.794,561.583,0], pc.points[10].data[1:3], atol=5e-3)
3885

39-
for (i,pt) in enumerate(pc.points)
40-
@test isapprox( PointCloudRef[1][1,:], pt.data; atol=1e-6)
41-
end
4286

43-
# 231 fromPCLPointCloud2 (msg, cloud, field_map);
44-
# (gdb) print field_map
45-
# $7 = std::vector of length 1, capacity 4 = {{serialized_offset = 0,
46-
# struct_offset = 0, size = 12}}
87+
# for (i,pt) in enumerate(pc.points)
88+
# @test isapprox( PointCloudRef[1][i,1:3], pt.data[1:3]; atol=1e-6)
89+
# end
4790

48-
# (gdb) print cloud.points[0]
49-
# $43 = {<pcl::_PointXYZ> = {{data = {-0, 0, 0, 1}, {x = -0, y = 0,
50-
# z = 0}}}, <No data fields>}
51-
# (gdb) print sizeof(cloud.points[0])
52-
# $44 = 16
5391

5492
##
5593
end

test/testdata/_PCLPointCloud2.bson

-395 KB
Binary file not shown.

0 commit comments

Comments
 (0)