hps3d

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2025 License: MIT Imports: 8 Imported by: 0

README

HPS3D Go Library

This library provides Go bindings for the HPS3D SDK, a high-performance solid-state LiDAR sensor SDK developed by Hypersen. The library enables Go developers to interact with the HPS3D SDK's functionality using idiomatic Go code.

Disclaimer: I am not affiliated with Hypersen. This project is an independent effort to provide Go bindings for the HPS3D SDK and redistribute its precompiled binaries under the terms of the MIT License.

Overview

The HPS3D SDK is designed for the HPS-3D160-U solid-state LiDAR sensor, which operates on the Time-of-Flight (ToF) principle. This project redistributes the precompiled binaries and header files from the official HPS3D SDK repository under the terms of the MIT License. The original source code for the SDK is closed-source, but the binary distribution allows developers to leverage its functionality in their applications.

Example Usage

Below is an example of how to use the HPS3D Go library to interact with the HPS3D SDK:

package main

import (
	"errors"
	"fmt"
	"os"
	"os/signal"
	"syscall"

	"codeberg.org/otaviogomes/hps3d"
)

func main() {
	pid := os.Getpid()
	fmt.Println("Starting server. PID:", pid)

	if err := run(); err != nil {
		fmt.Printf("Error: %v\n", err)
		os.Exit(1)
	}
}

func run() error {
	if sdkVersion := hps3d.GetSDKVersion(); sdkVersion != "" {
		fmt.Println("SDK Version:", sdkVersion)
	} else {
		return errors.New("failed to retrieve SDK version")
	}

	device, err := hps3d.NewDevice("usb:///dev/ttyACM0")
	if err != nil {
		return fmt.Errorf("error connecting to device: %w", err)
	}
	defer device.Close()

	if version, err := device.GetDeviceVersion(); err == nil {
		fmt.Println("Device Version:", version)
	} else {
		fmt.Printf("Failed to retrieve device version: %v\n", err)
	}

	if serial, err := device.GetSerialNumber(); err == nil {
		fmt.Println("Device Serial Number:", serial)
	} else {
		fmt.Printf("Failed to retrieve device serial number: %v\n", err)
	}

	device.SetDistanceOffset(-165)

	settings, err := device.ExportSettings()
	if err != nil {
		return fmt.Errorf("failed to export settings: %w", err)
	}

	fmt.Println(settings)

	events, err := hps3d.StartEventListener()
	if err != nil {
		return fmt.Errorf("failed to start event listener: %w", err)
	}
	defer hps3d.StopEventListener()

	if err := device.StartCapture(); err != nil {
		return fmt.Errorf("failed to start capture: %w", err)
	}
	defer device.StopCapture()

	quit := make(chan os.Signal, 1)
	signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)

	for {
		select {
		case event := <-events:
			handleEvent(event)

		case s := <-quit:
			fmt.Printf("Received signal: %v. Shutting down...\n", s)
			return nil
		}
	}
}

func handleEvent(event hps3d.EventData) error {
	fmt.Printf("Received event: Handle=%d, EventType=%d\n", event.Handle, event.EventType)

	switch event.EventType {
	case hps3d.EventFullDepth:
		fmt.Printf("Frame: %d\n", event.Data.FullDepthData.FrameCount)
		fmt.Printf("Average Distance: %d\n", event.Data.FullDepthData.DistanceAverage)

	case hps3d.EventSimpleDepth:
		fmt.Printf("Frame: %d\n", event.Data.SimpleDepthData.FrameCount)
		fmt.Printf("Average Distance: %d\n", event.Data.SimpleDepthData.DistanceAverage)

	case hps3d.EventDisconnect:
		fmt.Println("Device disconnected")
		return nil

	case hps3d.EventSysException:
		return fmt.Errorf("system exception occurred: handle=%d", event.Handle)

	case hps3d.EventFullROI:
		fmt.Println("Full ROI event received")

	case hps3d.EventNull:
		fmt.Println("Null event received")

	default:
		fmt.Println("Unknown event type")
	}

	return nil
}

Third-Party Libraries

This project includes precompiled binaries and header files from the HPS3D SDK. These files are distributed under the MIT License. Below are the details:

Source

The libraries and headers were obtained from the official repository:
https://github.com/hypersen/HPS3D_SDK

License

The HPS3D SDK is distributed under the MIT License. The full text of the license can be found in the lib/LICENSE file.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

The third-party libraries included in this project are distributed under their respective licenses. For more information, see the README in the lib/ directory.

Documentation

Index

Constants

View Source
const (
	SmoothFilterDisable = SmoothFilter(C.HPS3D_SMOOTH_FILTER_DISABLE)
	SmoothFilterAverage = SmoothFilter(C.HPS3D_SMOOTH_FILTER_AVERAGE)
	SmoothFilterGauss   = SmoothFilter(C.HPS3D_SMOOTH_FILTER_GAUSS)
)
View Source
const (
	EventNull         = EventType(C.HPS3D_NULL_EVEN)
	EventSimpleROI    = EventType(C.HPS3D_SIMPLE_ROI_EVEN)
	EventFullROI      = EventType(C.HPS3D_FULL_ROI_EVEN)
	EventFullDepth    = EventType(C.HPS3D_FULL_DEPTH_EVEN)
	EventSimpleDepth  = EventType(C.HPS3D_SIMPLE_DEPTH_EVEN)
	EventSysException = EventType(C.HPS3D_SYS_EXCEPTION_EVEN)
	EventDisconnect   = EventType(C.HPS3D_DISCONNECT_EVEN)
)
View Source
const MaxPixelNumber = int(C.HPS3D_MAX_PIXEL_NUMBER)

Variables

View Source
var (
	ErrOk              = errors.New("OK")
	ErrError           = errors.New("Error")
	ErrBusy            = errors.New("Busy")
	ErrConnectFailed   = errors.New("Connection Failed")
	ErrCreateThreadErr = errors.New("Thread Creation Error")
	ErrWriteErr        = errors.New("Write Error")
	ErrReadErr         = errors.New("Read Error")
	ErrPacketHeadErr   = errors.New("Packet Header Error")
	ErrPacketErr       = errors.New("Packet Error")
	ErrBuffEmpty       = errors.New("Buffer Empty")
	ErrVersionMismatch = errors.New("Version Mismatch")
)

Functions

func GetSDKVersion

func GetSDKVersion() string

func StartEventListener

func StartEventListener() (<-chan EventData, error)

func StopEventListener

func StopEventListener()

Types

type Device

type Device struct {
	// contains filtered or unexported fields
}

func NewDevice

func NewDevice(url string) (*Device, error)

NewDevice inicializa um dispositivo baseado na URL fornecida

func (*Device) Close

func (d *Device) Close() error

func (*Device) ExportSettings

func (d *Device) ExportSettings() (DeviceSettings, error)

func (*Device) GetDeviceVersion

func (d *Device) GetDeviceVersion() (string, error)

func (*Device) GetSerialNumber

func (d *Device) GetSerialNumber() (string, error)

func (*Device) IsConnect

func (d *Device) IsConnect() bool

func (*Device) IsStart

func (d *Device) IsStart() bool

func (*Device) SaveSettings

func (d *Device) SaveSettings() error

func (*Device) SetDeviceUserID

func (d *Device) SetDeviceUserID(userID uint8) error

func (*Device) SetDistanceFilterConf

func (d *Device) SetDistanceFilterConf(enable bool, K float32) error

func (*Device) SetDistanceOffset

func (d *Device) SetDistanceOffset(offset int16) error

func (*Device) SetEdgeFilterEnable

func (d *Device) SetEdgeFilterEnable(enable bool) error

func (*Device) SetMultiCameraCode

func (d *Device) SetMultiCameraCode(cameraCode uint8) error

func (*Device) SetOpticalPathCalibration

func (d *Device) SetOpticalPathCalibration(enable bool) error

func (*Device) SetROIGroupID

func (d *Device) SetROIGroupID(groupID uint8) error

func (*Device) SetSmoothFilterConf

func (d *Device) SetSmoothFilterConf(filterType SmoothFilter, args int) error

func (*Device) SingleCapture

func (d *Device) SingleCapture() (*EventData, error)

func (*Device) StartCapture

func (d *Device) StartCapture() error

func (*Device) StopCapture

func (d *Device) StopCapture() error

type DeviceSettings

type DeviceSettings struct {
	UserID             int
	MaxResolutionX     int
	MaxResolutionY     int
	MaxROIGroups       int
	MaxROINumber       int
	MaxThresholds      int
	MaxMultiCameraCode int
	DistFilterEnable   bool
	DistFilterK        float32
	SmoothFilterType   int
	SmoothFilterArgs   int
	CurGroupID         int
	CurMultiCameraCode int
	DistOffset         int
	OpticalPathCalib   bool
	EdgeFilterEnable   bool
}

func (DeviceSettings) String

func (s DeviceSettings) String() string

String returns a formatted string representation of DeviceSettings.

type EventData

type EventData struct {
	Handle    int
	EventType EventType
	Data      *MeasureData
}

type EventType

type EventType int

type EventType C.HPS3D_EventType_t

func (EventType) String added in v0.0.5

func (e EventType) String() string

type FullDepthData

type FullDepthData struct {
	DistanceAverage uint16
	DistanceMin     uint16
	SaturationCount uint16
	FrameCount      uint32
	Distance        []uint16
	PointCloudData  PointCloudData
}

FullDepthData representa os dados de profundidade completa

type MeasureData

type MeasureData struct {
	SimpleDepthData SimpleDepthData
	FullDepthData   FullDepthData
}

MeasureData representa os dados medidos convertidos para Go

type Point

type Point struct {
	X float32
	Y float32
	Z float32
}

Point representa um ponto 3D

type PointCloudData

type PointCloudData struct {
	Width     uint16
	Height    uint16
	Points    uint32
	PointData []Point
}

PointCloudData representa os dados de nuvem de pontos

type SimpleDepthData

type SimpleDepthData struct {
	DistanceAverage uint16
	DistanceMin     uint16
	SaturationCount uint16
	FrameCount      uint32
}

SimpleDepthData representa os dados de profundidade simples

type SmoothFilter

type SmoothFilter C.HPS3D_SmoothFilterType_t

type Status

type Status int

type Status C.HPS3D_StatusTypeDef

func (Status) String

func (s Status) String() string

String retorna uma representação legível do status.

func (Status) ToError

func (s Status) ToError() error

ToError converte um Status em um erro Go.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL