-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get structured point cloud data from decoded data packet.
- Loading branch information
1 parent
9bc3509
commit f922b62
Showing
5 changed files
with
571 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package vlp16 | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"time" | ||
) | ||
|
||
type SphericalPointCloud struct { | ||
SphericalPoints []SphericalPoint | ||
Timestamp time.Duration | ||
} | ||
|
||
type SphericalPoint struct { | ||
Distance float64 | ||
Azimuth float64 | ||
Elevation float64 | ||
Reflectivity Reflectivity | ||
LastReflection bool | ||
} | ||
|
||
func (cloud *SphericalPointCloud) UnmarshalPacket(packet *Packet) error { | ||
for i := 0; i < len(packet.Blocks); i++ { | ||
if err := cloud.parseBlock(i, packet); err != nil { | ||
return errors.Wrap(err, "Error parsing Block") | ||
} | ||
// Duration is in nanoseconds and Velodyne timestamp in microseconds | ||
cloud.Timestamp = time.Duration(packet.Timestamp) * time.Microsecond | ||
} | ||
return nil | ||
} | ||
|
||
func (cloud *SphericalPointCloud) parseBlock(blockIndex int, packet *Packet) error { | ||
azimuth := packet.Blocks[blockIndex].Azimuth | ||
for j := 0; j < len(packet.Blocks[0].Channels); j++ { | ||
if j == 16 { | ||
azimuth = interpolateAzimuth(blockIndex, packet) | ||
} | ||
distance := packet.Blocks[blockIndex].Channels[j].Distance | ||
if distance == 0 { // skip when distance = 0, invalid return from LiDAR. | ||
continue | ||
} | ||
lastReturn := false | ||
switch packet.ReturnMode { | ||
case ReturnModeDualReturn: | ||
// Even number blocks (0,2,4,...) contain last return | ||
if blockIndex%2 == 0 { | ||
lastReturn = true | ||
} | ||
case ReturnModeLastReturn: | ||
lastReturn = true | ||
} | ||
|
||
point := SphericalPoint{} | ||
point.Distance = float64(distance) * distanceFactor | ||
point.Azimuth = deg2Rad(float64(azimuth) * azimuthFactor) | ||
point.Elevation = verticalAngle(j) | ||
point.Reflectivity = packet.Blocks[blockIndex].Channels[j].Reflectivity | ||
point.LastReflection = lastReturn | ||
|
||
cloud.SphericalPoints = append(cloud.SphericalPoints, point) | ||
} | ||
return nil | ||
} |
Oops, something went wrong.