@@ -14,29 +14,48 @@ for i=1:Nmsgs
1414 refs[i] = Vector3 (rand (3 )... )
1515end
1616
17+ const ros_pub = Publisher (" vectors" , Vector3, queue_size = 10 )
18+ rossleep (Duration (3.0 ))
19+
20+ function publish_messages (pubobj, msgs, rate_hz)
21+ const r = Rate (rate_hz)
22+ for msg in msgs
23+ publish (pubobj, msg)
24+ rossleep (r)
25+ end
26+ rossleep (Duration (1.0 ))
27+ end
28+
1729function pose_cb (msg:: PoseStamped , msgs:: Vector{PoseStamped} )
1830 mtime = to_nsec (msg. header. stamp) - t0
19- println (" Message received, time: " ,mtime," nanoseconds" )
20- if msg. header. stamp. secs > 1.
31+ mtime > 0 && println (" Message received, time: " ,mtime," nanoseconds" )
32+ if msg. header. stamp. secs > 1.0
2133 push! (msgs, msg)
2234 println (" Got message #" ,msg. header. seq)
2335 end
2436end
25- pose_cb (PoseStamped (), msgs)
37+ pose_cb (PoseStamped (), msgs) # warm up run
38+
39+ if VERSION >= v " 0.5.0-dev+3692" # callbacks are broken
40+
41+ warn (" Not testing subscriber!" )
42+
43+ publish_messages (ros_pub, refs, 20.0 )
44+ rossleep (Duration (5.0 ))
45+ Nreceived = get_param (" /num_received_messages" )
46+ @test Nreceived == length (refs)
47+ set_param (" /num_received_messages" , 0 )
48+
49+ else # callbacks not broken
2650
27- const ros_pub = Publisher (" vectors" , Vector3, queue_size = 10 )
2851const ros_sub = Subscriber (" poses" , PoseStamped, pose_cb, (msgs,), queue_size = 10 )
2952
3053# First message doesn't go out for some reason
3154publish (ros_pub, Vector3 (1.1 ,2.2 ,3.3 ))
3255rossleep (Duration (1.0 ))
33-
34- const r = Rate (20.0 )
35- for i= 1 : Nmsgs
36- publish (ros_pub, refs[i])
37- rossleep (r)
38- end
56+ publish_messages (ros_pub, refs, 20.0 )
3957rossleep (Duration (1.0 ))
58+
4059println (" Received " ,length (msgs)," / " ,Nmsgs)
4160
4261@test length (msgs) == Nmsgs
@@ -45,3 +64,6 @@ for i=1:Nmsgs
4564 @test_approx_eq msgs[i]. pose. position. y refs[i]. y
4665 @test_approx_eq msgs[i]. pose. position. z refs[i]. z
4766end
67+ empty! (msgs)
68+
69+ end # version check
0 commit comments