cartofacade

package
v0.3.46 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package cartofacade contains the api to call into CGO

Package cartofacade is used to mock the CGo API.

Package cartofacade contains the api to call into CGO

Package cartofacade is used to mock a cartofacade.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnableToAcquireLock = errors.New("VIAM_CARTO_UNABLE_TO_ACQUIRE_LOCK")

ErrUnableToAcquireLock is the error returned from AddLidarReading, AddIMUReading, and/or AddOdometerReading when lock can't be acquired.

Functions

This section is empty.

Types

type Carto

type Carto struct {
	SlamMode
	// contains filtered or unexported fields
}

Carto holds the c type viam_carto

func NewCarto

func NewCarto(cfg CartoConfig, acfg CartoAlgoConfig, vcl CartoLibInterface) (Carto, error)

NewCarto calls viam_carto_init and returns a pointer to a viam carto object. vcl is only an interface to facilitate testing. The only type vcl is expected to have is a CartoLib.

type CartoAlgoConfig

type CartoAlgoConfig struct {
	OptimizeOnStart      bool
	OptimizeEveryNNodes  int
	NumRangeData         int
	MissingDataRayLength float32
	MaxRange             float32
	MinRange             float32
	UseIMUData           bool
	MaxSubmapsToKeep     int
	FreshSubmapsCount    int
	MinCoveredArea       float64
	MinAddedSubmapsCount int
	OccupiedSpaceWeight  float64
	TranslationWeight    float64
	RotationWeight       float64

	HasInitialTrajectoryPose   bool
	InitialTrajectoryPoseX     float64
	InitialTrajectoryPoseY     float64
	InitialTrajectoryPoseTheta float64
}

CartoAlgoConfig contains config values from app

func GetTestAlgoConfig

func GetTestAlgoConfig(useImuData bool) CartoAlgoConfig

GetTestAlgoConfig gets a sample algo config for testing purposes.

type CartoConfig

type CartoConfig struct {
	Camera         string
	MovementSensor string
	LidarConfig    LidarConfig

	EnableMapping bool
	ExistingMap   string
}

CartoConfig contains config values from app

func GetBadTestConfig

func GetBadTestConfig() CartoConfig

GetBadTestConfig gets a sample config for testing purposes that will cause a failure.

func GetTestConfig

func GetTestConfig(cameraName, movementSensorName, filename string, enableMapping bool) CartoConfig

GetTestConfig gets a sample config for testing purposes.

type CartoFacade

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

CartoFacade exists to ensure that only one go routine is calling into the CGO api at a time to ensure the go runtime doesn't spawn multiple OS threads, which would harm performance.

func New

func New(cartoLib CartoLibInterface, cartoCfg CartoConfig, cartoAlgoCfg CartoAlgoConfig) CartoFacade

New instantiates the Cartofacade struct which limits calls into C.

func (*CartoFacade) AddIMUReading

func (cf *CartoFacade) AddIMUReading(
	ctx context.Context,
	timeout time.Duration,
	movementSensorName string,
	currentReading s.TimedIMUReadingResponse,
) error

AddIMUReading calls into the cartofacade C code.

func (*CartoFacade) AddLidarReading

func (cf *CartoFacade) AddLidarReading(
	ctx context.Context,
	timeout time.Duration,
	lidarName string,
	currentReading s.TimedLidarReadingResponse,
) error

AddLidarReading calls into the cartofacade C code.

func (*CartoFacade) AddOdometerReading

func (cf *CartoFacade) AddOdometerReading(
	ctx context.Context,
	timeout time.Duration,
	movementSensorName string,
	currentReading s.TimedOdometerReadingResponse,
) error

AddOdometerReading calls into the cartofacade C code.

func (*CartoFacade) Initialize

func (cf *CartoFacade) Initialize(ctx context.Context, timeout time.Duration, activeBackgroundWorkers *sync.WaitGroup) (SlamMode, error)

Initialize calls into the cartofacade C code.

func (*CartoFacade) InternalState

func (cf *CartoFacade) InternalState(ctx context.Context, timeout time.Duration) ([]byte, error)

InternalState calls into the cartofacade C code.

func (*CartoFacade) PointCloudMap

func (cf *CartoFacade) PointCloudMap(ctx context.Context, timeout time.Duration) ([]byte, error)

PointCloudMap calls into the cartofacade C code.

func (*CartoFacade) Position

func (cf *CartoFacade) Position(ctx context.Context, timeout time.Duration) (Position, error)

Position calls into the cartofacade C code.

func (*CartoFacade) RunFinalOptimization

func (cf *CartoFacade) RunFinalOptimization(ctx context.Context, timeout time.Duration) error

RunFinalOptimization calls into the cartofacade C code.

func (*CartoFacade) Start

func (cf *CartoFacade) Start(ctx context.Context, timeout time.Duration) error

Start calls into the cartofacade C code.

func (*CartoFacade) Stop

func (cf *CartoFacade) Stop(ctx context.Context, timeout time.Duration) error

Stop calls into the cartofacade C code.

func (*CartoFacade) Terminate

func (cf *CartoFacade) Terminate(ctx context.Context, timeout time.Duration) error

Terminate calls into the cartofacade C code.

type CartoInterface

type CartoInterface interface {
	// contains filtered or unexported methods
}

CartoInterface describes the method signatures that Carto must implement

type CartoLib

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

CartoLib holds the c type viam_carto_lib

func NewLib

func NewLib(miniloglevel, verbose int) (CartoLib, error)

NewLib calls viam_carto_lib_init and returns a pointer to a viam carto lib object.

func (*CartoLib) Terminate

func (vcl *CartoLib) Terminate() error

Terminate calls viam_carto_lib_terminate to clean up memory for viam carto lib.

type CartoLibInterface

type CartoLibInterface interface {
	Terminate() error
}

CartoLibInterface describes the method signatures that CartoLib must implement

type CartoLibMock

type CartoLibMock struct {
	CartoLib
	TerminateFunc func() error
}

CartoLibMock represents a fake instance of cartofacade.

func (*CartoLibMock) Terminate

func (cf *CartoLibMock) Terminate() error

Terminate calls the injected TerminateFunc or the real version.

type CartoMock

type CartoMock struct {
	Carto
	StartFunc                func() error
	StopFunc                 func() error
	TerminateFunc            func() error
	AddLidarReadingFunc      func(string, s.TimedLidarReadingResponse) error
	AddIMUReadingFunc        func(string, s.TimedIMUReadingResponse) error
	AddOdometerReadingFunc   func(string, s.TimedOdometerReadingResponse) error
	PositionFunc             func() (Position, error)
	PointCloudMapFunc        func() ([]byte, error)
	InternalStateFunc        func() ([]byte, error)
	RunFinalOptimizationFunc func() error
}

CartoMock represents a fake instance of cartofacade.

type Interface

type Interface interface {
	Initialize(
		ctx context.Context,
		timeout time.Duration,
		activeBackgroundWorkers *sync.WaitGroup,
	) (SlamMode, error)
	Start(
		ctx context.Context,
		timeout time.Duration,
	) error
	Stop(
		ctx context.Context,
		timeout time.Duration,
	) error
	Terminate(
		ctx context.Context,
		timeout time.Duration,
	) error
	AddLidarReading(
		ctx context.Context,
		timeout time.Duration,
		lidarName string,
		currentReading s.TimedLidarReadingResponse,
	) error
	AddIMUReading(
		ctx context.Context,
		timeout time.Duration,
		movementSensorName string,
		currentReading s.TimedIMUReadingResponse,
	) error
	AddOdometerReading(
		ctx context.Context,
		timeout time.Duration,
		movementSensorName string,
		currentReading s.TimedOdometerReadingResponse,
	) error
	Position(
		ctx context.Context,
		timeout time.Duration,
	) (Position, error)
	InternalState(
		ctx context.Context,
		timeout time.Duration,
	) ([]byte, error)
	PointCloudMap(
		ctx context.Context,
		timeout time.Duration,
	) ([]byte, error)
	RunFinalOptimization(
		ctx context.Context,
		timeout time.Duration,
	) error
	// contains filtered or unexported methods
}

Interface defines the functionality of a CartoFacade instance. It should not be used outside of this package but needs to be public for testing purposes.

type LidarConfig

type LidarConfig int64

LidarConfig represents the lidar configuration

const (
	// TwoD LidarConfig denotes a 2d lidar
	TwoD LidarConfig = iota
	// ThreeD LidarConfig denotes a 3d lidar
	ThreeD
)

type Mock

type Mock struct {
	CartoFacade

	InitializeFunc func(
		ctx context.Context,
		timeout time.Duration, activeBackgroundWorkers *sync.WaitGroup,
	) (SlamMode, error)
	StartFunc func(
		ctx context.Context,
		timeout time.Duration,
	) error
	StopFunc func(
		ctx context.Context,
		timeout time.Duration,
	) error
	TerminateFunc func(
		ctx context.Context,
		timeout time.Duration,
	) error
	AddLidarReadingFunc func(
		ctx context.Context,
		timeout time.Duration,
		lidarName string,
		currentReading s.TimedLidarReadingResponse,
	) error
	AddIMUReadingFunc func(
		ctx context.Context,
		timeout time.Duration,
		movementSensorName string,
		currentReading s.TimedIMUReadingResponse,
	) error
	AddOdometerReadingFunc func(
		ctx context.Context,
		timeout time.Duration,
		movementSensorName string,
		currentReading s.TimedOdometerReadingResponse,
	) error
	PositionFunc func(
		ctx context.Context,
		timeout time.Duration,
	) (Position, error)
	InternalStateFunc func(
		ctx context.Context,
		timeout time.Duration,
	) ([]byte, error)
	PointCloudMapFunc func(
		ctx context.Context,
		timeout time.Duration,
	) ([]byte, error)
	RunFinalOptimizationFunc func(
		ctx context.Context,
		timeout time.Duration,
	) error
	// contains filtered or unexported fields
}

Mock represents a fake instance of cartofacade.

func (*Mock) AddIMUReading

func (cf *Mock) AddIMUReading(
	ctx context.Context,
	timeout time.Duration,
	movementSensorName string,
	currentReading s.TimedIMUReadingResponse,
) error

AddIMUReading calls the injected AddIMUReadingFunc or the real version.

func (*Mock) AddLidarReading

func (cf *Mock) AddLidarReading(
	ctx context.Context,
	timeout time.Duration,
	lidarName string,
	currentReading s.TimedLidarReadingResponse,
) error

AddLidarReading calls the injected AddLidarReadingFunc or the real version.

func (*Mock) AddOdometerReading

func (cf *Mock) AddOdometerReading(
	ctx context.Context,
	timeout time.Duration,
	movementSensorName string,
	currentReading s.TimedOdometerReadingResponse,
) error

AddOdometerReading calls the injected AddOdometerReadingFunc or the real version.

func (*Mock) Initialize

func (cf *Mock) Initialize(
	ctx context.Context,
	timeout time.Duration,
	activeBackgroundWorkers *sync.WaitGroup,
) (SlamMode, error)

Initialize calls the injected InitializeFunc or the real version.

func (*Mock) InternalState

func (cf *Mock) InternalState(
	ctx context.Context,
	timeout time.Duration,
) ([]byte, error)

InternalState calls the injected InternalStateFunc or the real version.

func (*Mock) PointCloudMap

func (cf *Mock) PointCloudMap(
	ctx context.Context,
	timeout time.Duration,
) ([]byte, error)

PointCloudMap calls the injected PointCloudMapFunc or the real version.

func (*Mock) Position

func (cf *Mock) Position(
	ctx context.Context,
	timeout time.Duration,
) (Position, error)

Position calls the injected PositionFunc or the real version.

func (*Mock) RunFinalOptimization

func (cf *Mock) RunFinalOptimization(
	ctx context.Context,
	timeout time.Duration,
) error

RunFinalOptimization calls the injected RunFinalOptimizationFunc or the real version.

func (*Mock) Start

func (cf *Mock) Start(
	ctx context.Context,
	timeout time.Duration,
) error

Start calls the injected StartFunc or the real version.

func (*Mock) Stop

func (cf *Mock) Stop(
	ctx context.Context,
	timeout time.Duration,
) error

Stop calls the Stop StopFunc or the real version.

func (*Mock) Terminate

func (cf *Mock) Terminate(
	ctx context.Context,
	timeout time.Duration,
) error

Terminate calls the injected TerminateFunc or the real version.

type Position

type Position struct {
	X float64
	Y float64
	Z float64

	Real float64
	Imag float64
	Jmag float64
	Kmag float64
}

Position holds values returned from c to be processed later

type Request

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

Request defines all of the necessary pieces to call into the CGo API.

type RequestInterface

type RequestInterface interface {
	// contains filtered or unexported methods
}

RequestInterface defines the functionality of a Request. It should not be used outside of this package but needs to be public for testing purposes.

type RequestMock

type RequestMock struct {
	Request
	// contains filtered or unexported fields
}

RequestMock represents a fake instance of a request.

type RequestParamType

type RequestParamType int64

RequestParamType defines the type being provided as input to the work.

type RequestType

type RequestType int64

RequestType defines the carto C API call that is being made.

type Response

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

Response defines the result of one piece of work that can be put on the result channel.

type SlamMode

type SlamMode int64

SlamMode represents the lidar configuration

const (
	// UnknownMode denotes an unknown slam mode
	UnknownMode SlamMode = iota
	// MappingMode denotes the slam algo is in mapping mode
	MappingMode
	// LocalizingMode denotes the slam algo is in localizing only mode
	LocalizingMode
	// UpdatingMode denotes the slam algo is in updating mode
	UpdatingMode
)

Jump to

Keyboard shortcuts

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